-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasskeyTrait.php
More file actions
170 lines (135 loc) · 3.7 KB
/
Copy pathPasskeyTrait.php
File metadata and controls
170 lines (135 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
declare(strict_types=1);
namespace ADT\FancyAdmin\Model\Entities;
use ADT\DoctrineLoggable\Attributes\LoggableProperty;
use ADT\FancyAdmin\Model\Entities\Traits\CreatedAt;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
trait PasskeyTrait
{
use CreatedAt;
#[ORM\ManyToOne(targetEntity: 'Identity', inversedBy: 'passkeys')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
protected Identity $identity;
#[ORM\Column(length: 64, nullable: false)]
#[LoggableProperty]
protected string $name;
/** Raw binary credential ID (VARBINARY(255)); DBAL binary type může vracet stream, getter normalizuje. */
#[ORM\Column(type: 'binary', length: 255, unique: true, nullable: false)]
protected mixed $credentialId;
/** Veřejný klíč v PEM formátu (výstup lbuchs/webauthn processCreate) */
#[ORM\Column(type: 'text', nullable: false)]
protected string $publicKey;
#[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true, 'default' => 0])]
protected int $signCount = 0;
/** Raw binary AAGUID autentikátoru (BINARY(16)) */
#[ORM\Column(type: 'binary', length: 16, nullable: true, options: ['fixed' => true])]
protected mixed $aaguid = null;
#[ORM\Column(type: 'json', nullable: true)]
protected ?array $transports = null;
#[ORM\Column(nullable: true)]
protected ?bool $backupEligible = null;
#[ORM\Column(nullable: true)]
protected ?bool $backupState = null;
#[ORM\Column(nullable: true)]
protected ?DateTimeImmutable $lastUsedAt = null;
public function getIdentity(): Identity
{
return $this->identity;
}
public function setIdentity(Identity $identity): static
{
$this->identity = $identity;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCredentialId(): string
{
return self::binaryColumnToString($this->credentialId);
}
public function setCredentialId(string $credentialId): static
{
$this->credentialId = $credentialId;
return $this;
}
public function getPublicKey(): string
{
return $this->publicKey;
}
public function setPublicKey(string $publicKey): static
{
$this->publicKey = $publicKey;
return $this;
}
public function getSignCount(): int
{
return $this->signCount;
}
public function setSignCount(int $signCount): static
{
$this->signCount = $signCount;
return $this;
}
public function getAaguid(): ?string
{
return $this->aaguid === null ? null : self::binaryColumnToString($this->aaguid);
}
public function setAaguid(?string $aaguid): static
{
$this->aaguid = $aaguid;
return $this;
}
public function getTransports(): ?array
{
return $this->transports;
}
public function setTransports(?array $transports): static
{
$this->transports = $transports;
return $this;
}
public function getBackupEligible(): ?bool
{
return $this->backupEligible;
}
public function setBackupEligible(?bool $backupEligible): static
{
$this->backupEligible = $backupEligible;
return $this;
}
public function getBackupState(): ?bool
{
return $this->backupState;
}
public function setBackupState(?bool $backupState): static
{
$this->backupState = $backupState;
return $this;
}
public function getLastUsedAt(): ?DateTimeImmutable
{
return $this->lastUsedAt;
}
public function setLastUsedAt(?DateTimeImmutable $lastUsedAt): static
{
$this->lastUsedAt = $lastUsedAt;
return $this;
}
/** DBAL typ binary hydratuje podle verze DBAL buď string, nebo stream */
private static function binaryColumnToString(mixed $value): string
{
if (is_resource($value)) {
rewind($value);
return (string) stream_get_contents($value);
}
return (string) $value;
}
}