Skip to content

Commit 48c7bde

Browse files
committed
Start with value abstracts
1 parent 5686f0e commit 48c7bde

39 files changed

Lines changed: 789 additions & 28 deletions

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"simplesamlphp/simplesamlphp-test-framework": "^1",
4242
"squizlabs/php_codesniffer": "^3"
4343
},
44+
"conflict": {
45+
"rector/rector": "2.3.0"
46+
},
4447
"config": {
4548
"sort-packages": true,
4649
"cache-dir": "build/composer",

src/Factories/ClaimFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace SimpleSAML\OpenID\Factories;
66

7-
use SimpleSAML\OpenID\Claims\GenericClaim;
8-
use SimpleSAML\OpenID\Claims\JwksClaim;
97
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
108
use SimpleSAML\OpenID\Exceptions\JwksException;
119
use SimpleSAML\OpenID\Federation\Factories\FederationClaimFactory;
1210
use SimpleSAML\OpenID\Helpers;
11+
use SimpleSAML\OpenID\ValueAbstracts\GenericClaim;
12+
use SimpleSAML\OpenID\ValueAbstracts\JwksClaim;
1313
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Factories\VcDataModelClaimFactory;
1414

1515
class ClaimFactory

src/Federation/Claims/TrustMarkOwnersClaimValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace SimpleSAML\OpenID\Federation\Claims;
66

77
use JsonSerializable;
8-
use SimpleSAML\OpenID\Claims\JwksClaim;
98
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
9+
use SimpleSAML\OpenID\ValueAbstracts\JwksClaim;
1010

1111
class TrustMarkOwnersClaimValue implements JsonSerializable
1212
{

src/Federation/EntityStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace SimpleSAML\OpenID\Federation;
66

7-
use SimpleSAML\OpenID\Claims\JwksClaim;
87
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
98
use SimpleSAML\OpenID\Codebooks\EntityTypesEnum;
109
use SimpleSAML\OpenID\Codebooks\JwtTypesEnum;
@@ -13,6 +12,7 @@
1312
use SimpleSAML\OpenID\Federation\Claims\TrustMarkOwnersClaimBag;
1413
use SimpleSAML\OpenID\Federation\Claims\TrustMarksClaimBag;
1514
use SimpleSAML\OpenID\Jws\ParsedJws;
15+
use SimpleSAML\OpenID\ValueAbstracts\JwksClaim;
1616

1717
class EntityStatement extends ParsedJws
1818
{

src/ValueAbstracts/ClaimBag.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
6+
7+
class ClaimBag
8+
{
9+
/**
10+
* @param array<non-empty-string,mixed> $claims
11+
*/
12+
public function __construct(
13+
protected array $claims = [],
14+
) {
15+
}
16+
17+
18+
/**
19+
* @return array<non-empty-string,mixed>
20+
*/
21+
public function getAll(): array
22+
{
23+
return $this->claims;
24+
}
25+
26+
27+
/**
28+
* @param non-empty-string $name
29+
*/
30+
public function get(string $name): mixed
31+
{
32+
return $this->claims[$name] ?? null;
33+
}
34+
35+
36+
/**
37+
* @param non-empty-string $name
38+
*/
39+
public function has(string $name): bool
40+
{
41+
return isset($this->claims[$name]);
42+
}
43+
44+
45+
/**
46+
* @param non-empty-string $name
47+
*/
48+
public function set(string $name, mixed $value): void
49+
{
50+
$this->claims[$name] = $value;
51+
}
52+
53+
54+
/**
55+
* @param array<non-empty-string,mixed> $claims
56+
*/
57+
public function merge(array $claims): void
58+
{
59+
$this->claims = array_merge($this->claims, $claims);
60+
}
61+
62+
63+
/**
64+
* @param non-empty-string $name
65+
*/
66+
public function remove(string $name): void
67+
{
68+
unset($this->claims[$name]);
69+
}
70+
71+
72+
/**
73+
* @param non-empty-string $name
74+
*/
75+
public function getAsString(string $name): ?string
76+
{
77+
$ret = $this->get($name);
78+
79+
if (is_string($ret)) {
80+
return $ret;
81+
}
82+
83+
return null;
84+
}
85+
86+
87+
/**
88+
* @param non-empty-string $name
89+
* @return mixed[]|null
90+
*/
91+
public function getAsArray(string $name): ?array
92+
{
93+
$ret = $this->get($name);
94+
95+
if (is_array($ret)) {
96+
return $ret;
97+
}
98+
99+
return null;
100+
}
101+
102+
103+
/**
104+
* @param non-empty-string $name
105+
*/
106+
public function getAsInt(string $name): ?int
107+
{
108+
$ret = $this->get($name);
109+
110+
if (is_int($ret)) {
111+
return $ret;
112+
}
113+
114+
return null;
115+
}
116+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\OpenID\Claims;
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
66

77
interface ClaimInterface extends \JsonSerializable
88
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\OpenID\Claims;
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
66

77
class GenericClaim implements ClaimInterface
88
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\OpenID\Claims;
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
66

77
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
88

src/ValueAbstracts/KeyPair.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
6+
7+
use SimpleSAML\OpenID\Jwk\JwkDecorator;
8+
9+
class KeyPair
10+
{
11+
public function __construct(
12+
protected JwkDecorator $privateKey,
13+
protected JwkDecorator $publicKey,
14+
protected readonly string $keyId,
15+
protected readonly ?string $privateKeyPassword = null,
16+
) {
17+
}
18+
19+
20+
public function getPrivateKey(): JwkDecorator
21+
{
22+
return $this->privateKey;
23+
}
24+
25+
26+
public function getPublicKey(): JwkDecorator
27+
{
28+
return $this->publicKey;
29+
}
30+
31+
32+
public function getKeyId(): string
33+
{
34+
return $this->keyId;
35+
}
36+
37+
38+
public function getPrivateKeyPassword(): ?string
39+
{
40+
return $this->privateKeyPassword;
41+
}
42+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\ValueAbstracts;
6+
7+
interface KeyPairConfigInterface
8+
{
9+
/**
10+
* @return non-empty-string
11+
*/
12+
public function getPrivateKeyString(): string;
13+
14+
15+
/**
16+
* @return non-empty-string
17+
*/
18+
public function getPublicKeyString(): string;
19+
20+
21+
/**
22+
* @return non-empty-string|null
23+
*/
24+
public function getPrivateKeyPassword(): ?string;
25+
26+
27+
/**
28+
* @return non-empty-string|null
29+
*/
30+
public function getKeyId(): ?string;
31+
}

0 commit comments

Comments
 (0)