| 1 | <?php |
||
| 17 | class SignedXml |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var SunatXmlSecAdapter |
||
| 21 | */ |
||
| 22 | private $adapter; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * SignedXml constructor. |
||
| 26 | */ |
||
| 27 | 2 | public function __construct() |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Firma el contenido del xml y retorna el contenido firmado. |
||
| 34 | * |
||
| 35 | * @param string $content |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | 2 | public function sign($content) |
|
| 39 | { |
||
| 40 | 2 | $doc = $this->getDocXml($content); |
|
| 41 | |||
| 42 | 2 | $this->adapter->sign($doc); |
|
| 43 | 2 | return $doc->saveXML(); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Verifica la firma del xml. |
||
| 48 | * |
||
| 49 | * @param string $content |
||
| 50 | * @return bool |
||
| 51 | */ |
||
| 52 | public function verify($content) |
||
| 53 | { |
||
| 54 | $doc = $this->getDocXml($content); |
||
| 55 | $this->adapter->getPublicKey($doc); |
||
| 56 | |||
| 57 | return $this->adapter->verify($doc); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param string $cert |
||
| 62 | */ |
||
| 63 | 2 | public function setCertificate($cert) |
|
| 64 | { |
||
| 65 | 2 | $this->adapter->setPrivateKey($cert); |
|
| 66 | 2 | $this->adapter->setPublicKey($cert); |
|
| 67 | 2 | } |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $content |
||
| 71 | * @return \DOMDocument |
||
| 72 | */ |
||
| 73 | 2 | private function getDocXml($content) |
|
| 80 | } |