Completed
Push — master ( f338a0...491cb3 )
by Giancarlos
02:24
created

SignedXml::setPrivateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Giansalex
5
 * Date: 15/07/2017
6
 * Time: 22:39
7
 */
8
9
namespace Greenter\Security;
10
11
use FR3D\XmlDSig\Adapter\XmlseclibsAdapter;
12
13
/**
14
 * Class SignedXml
15
 * @package Greenter\Security
16
 */
17
class SignedXml
18
{
19
    /**
20
     * @var XmlseclibsAdapter
21
     */
22
    private $adapter;
23
24
    /**
25
     * SignedXml constructor.
26
     */
27 4
    public function __construct()
28
    {
29 4
        $this->adapter = new XmlseclibsAdapter();
30 4
        $this->adapter->addTransform(XmlseclibsAdapter::ENVELOPED);
31 4
    }
32
33
    /**
34
     * Firma el contenido del xml y retorna el contenido firmado.
35
     *
36
     * @param string $content
37
     * @return string
38
     */
39 4
    public function sign($content)
40
    {
41 4
        $doc = new \DOMDocument();
42 4
        $doc->loadXML($content);
43
44 4
        $this->adapter->sign($doc);
45 4
        return $doc->saveXML();
46
    }
47
48
    /**
49
     * Verifica la firma del xml.
50
     *
51
     * @param string $content
52
     * @return bool
53
     */
54 2
    public function verify($content)
55
    {
56 2
        $doc = new \DOMDocument();
57 2
        $doc->loadXML($content);
58
59 2
        return $this->adapter->verify($doc);
60
    }
61
62
    /**
63
     * @param string $key
64
     */
65 4
    public function setPrivateKey($key)
66
    {
67 4
        $this->adapter->setPrivateKey($key);
68 4
    }
69
70
    /**
71
     * @param string $key
72
     */
73 2
    public function setPublicKey($key)
74
    {
75 2
        $this->adapter->setPublicKey($key);
76
    }
77
}