File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 44
55namespace SimpleSAML \OpenID \ValueAbstracts ;
66
7+ use SimpleSAML \OpenID \Algorithms \SignatureAlgorithmEnum ;
8+ use SimpleSAML \OpenID \Exceptions \OpenIdException ;
9+
710class SignatureKeyPairBag
811{
912 /**
@@ -46,4 +49,47 @@ public function hasKeyId(string $keyId): bool
4649 {
4750 return isset ($ this ->signatureKeyPairs [$ keyId ]);
4851 }
52+
53+
54+ public function getFirst (): ?SignatureKeyPair
55+ {
56+ return $ this ->signatureKeyPairs [array_key_first ($ this ->signatureKeyPairs )] ?? null ;
57+ }
58+
59+
60+ /**
61+ * @throws \SimpleSAML\OpenID\Exceptions\OpenIdException
62+ */
63+ public function getFirstOrFail (): SignatureKeyPair
64+ {
65+ return $ this ->getFirst () ?? throw new OpenIdException (
66+ 'Signature key pair is not set. ' ,
67+ );
68+ }
69+
70+
71+ public function getFirstByAlgorithm (SignatureAlgorithmEnum $ signatureAlgorithm ): ?SignatureKeyPair
72+ {
73+ foreach ($ this ->signatureKeyPairs as $ signatureKeyPair ) {
74+ if ($ signatureKeyPair ->getSignatureAlgorithm () === $ signatureAlgorithm ) {
75+ return $ signatureKeyPair ;
76+ }
77+ }
78+
79+ return null ;
80+ }
81+
82+
83+ /**
84+ * @throws \SimpleSAML\OpenID\Exceptions\OpenIdException
85+ */
86+ public function getFirstByAlgorithmOrFail (SignatureAlgorithmEnum $ signatureAlgorithm ): SignatureKeyPair
87+ {
88+ return $ this ->getFirstByAlgorithm ($ signatureAlgorithm ) ?? throw new OpenIdException (
89+ sprintf (
90+ 'Signature key pair for algorithm %s is not set. ' ,
91+ $ signatureAlgorithm ->value ,
92+ ),
93+ );
94+ }
4995}
You can’t perform that action at this time.
0 commit comments