55namespace SimpleSAML \OpenID \VerifiableCredentials \VcDataModel2 \Factories ;
66
77use SimpleSAML \OpenID \Codebooks \AtContextsEnum ;
8+ use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
9+ use SimpleSAML \OpenID \Exceptions \VcDataModelException ;
810use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcAtContextClaimValue ;
911use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Factories \VcDataModelClaimFactory ;
12+ use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel2 \Claims \VcCredentialStatusClaimBag ;
13+ use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel2 \Claims \VcRefreshServiceClaimBag ;
14+ use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel2 \Claims \VcRefreshServiceClaimValue ;
1015
1116class VcDataModel2ClaimFactory extends VcDataModelClaimFactory
1217{
@@ -24,4 +29,82 @@ public function buildVcAtContextClaimValue(
2429 AtContextsEnum::W3OrgNsCredentialsV2,
2530 );
2631 }
32+
33+
34+ /**
35+ * @param mixed[] $data
36+ * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
37+ * @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
38+ */
39+ public function buildVcCredentialStatusClaimBag (array $ data ): VcCredentialStatusClaimBag
40+ {
41+ // If this is a single credential status claim, wrap it in a
42+ // CredentialStatusClaimBag.
43+ if ($ this ->helpers ->arr ()->isAssociative ($ data )) {
44+ return new VcCredentialStatusClaimBag (
45+ $ this ->buildVcCredentialStatusClaimValue ($ data ),
46+ );
47+ }
48+
49+ // We have multiple credential status claims. Wrap them in a
50+ // CredentialStatusClaimBag.
51+ $ data = $ this ->helpers ->type ()->enforceNonEmptyArrayOfNonEmptyArrays ($ data );
52+
53+ $ vcCredentialStatusClaims = [];
54+ foreach ($ data as $ credentialStatusClaimValueData ) {
55+ $ vcCredentialStatusClaims [] = $ this ->buildVcCredentialStatusClaimValue ($ credentialStatusClaimValueData );
56+ }
57+
58+ $ firstCredentialStatusClaim = array_shift ($ vcCredentialStatusClaims );
59+
60+ return new VcCredentialStatusClaimBag (
61+ $ firstCredentialStatusClaim ,
62+ ...$ vcCredentialStatusClaims ,
63+ );
64+ }
65+
66+
67+ /**
68+ * @param non-empty-array<mixed> $data
69+ * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
70+ * @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
71+ */
72+ public function buildVcRefreshServiceClaimValue2 (array $ data ): VcRefreshServiceClaimValue
73+ {
74+ $ type = $ data [ClaimsEnum::Type->value ] ?? throw new VcDataModelException (
75+ 'No Type claim value available. ' ,
76+ );
77+ $ typeClaimValue = $ this ->buildTypeClaimValue ($ type );
78+
79+ return new VcRefreshServiceClaimValue ($ typeClaimValue , $ data );
80+ }
81+
82+
83+ /**
84+ * @param mixed[] $data
85+ * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
86+ * @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
87+ */
88+ public function buildVcRefreshServiceClaimBag2 (array $ data ): VcRefreshServiceClaimBag
89+ {
90+ if ($ this ->helpers ->arr ()->isAssociative ($ data )) {
91+ $ data = [$ data ];
92+ }
93+
94+ $ data = $ this ->helpers ->type ()->enforceNonEmptyArrayOfNonEmptyArrays ($ data );
95+
96+ $ vcRefreshServiceClaimValueData = array_shift ($ data );
97+
98+ $ vcRefreshServiceClaimValue = $ this ->buildVcRefreshServiceClaimValue2 ($ vcRefreshServiceClaimValueData );
99+
100+ $ vcRefreshServiceClaimValues = array_map (
101+ $ this ->buildVcRefreshServiceClaimValue2 (...),
102+ $ data ,
103+ );
104+
105+ return new VcRefreshServiceClaimBag (
106+ $ vcRefreshServiceClaimValue ,
107+ ...$ vcRefreshServiceClaimValues ,
108+ );
109+ }
27110}
0 commit comments