Passed
Push — release-4-alpha ( 409cb2...426a19 )
by Tim
02:00
created

SignedElement::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2;
6
7
use RobRichards\XMLSecLibs\XMLSecurityKey;
8
9
/**
10
 * Interface to a SAML 2 element which may be signed.
11
 *
12
 * @package SimpleSAMLphp
13
 */
14
abstract class SignedElement
15
{
16
    /**
17
     * The private key we should use to sign the message.
18
     *
19
     * The private key can be null, in which case the message is sent unsigned.
20
     *
21
     * @var XMLSecurityKey|null
22
     */
23
    protected $signatureKey;
24
25
    /**
26
     * List of certificates that should be included in the message.
27
     *
28
     * @var array
29
     */
30
    protected $certificates;
31
32
33
    /**
34
     * Validate this element against a public key.
35
     *
36
     * If no signature is present, false is returned. If a signature is present,
37
     * but cannot be verified, an exception will be thrown.
38
     *
39
     * @param  XMLSecurityKey $key The key we should check against.
40
     * @return bool True if successful, false if we don't have a signature that can be verified.
41
     */
42
    abstract public function validate(XMLSecurityKey $key) : bool;
43
44
45
    /**
46
     * Set the certificates that should be included in the element.
47
     * The certificates should be strings with the PEM encoded data.
48
     *
49
     * @param array $certificates An array of certificates.
50
     * @return void
51
     */
52
    abstract public function setCertificates(array $certificates);
53
54
55
    /**
56
     * Retrieve the certificates that are included in the element (if any).
57
     *
58
     * @return array An array of certificates.
59
     */
60
    abstract public function getCertificates() : array;
61
62
63
    /**
64
     * Retrieve the private key we should use to sign the element.
65
     *
66
     * @return XMLSecurityKey|null The key, or NULL if no key is specified.
67
     */
68
    abstract public function getSignatureKey();
69
70
71
    /**
72
     * Set the private key we should use to sign the element.
73
     * If the key is null, the message will be sent unsigned.
74
     *
75
     * @param XMLSecurityKey|null $signatureKey
76
     * @return void
77
     */
78
    abstract public function setSignatureKey(XMLSecurityKey $signatureKey = null);
79
}
80