-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcredential.go
44 lines (37 loc) · 1.02 KB
/
credential.go
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
package virtualwebauthn
import "encoding/base64"
type Credential struct {
ID []byte `json:"id"`
Key *Key `json:"key"`
Counter uint32 `json:"counter,omitempty"`
}
func NewCredential(keyType KeyType) Credential {
return newCredential(keyType.newKey())
}
func NewCredentialWithImportedKey(keyType KeyType, keyData []byte) Credential {
return newCredential(keyType.importKey(keyData))
}
func newCredential(key *Key) Credential {
cred := Credential{}
cred.ID = randomBytes(32)
cred.Key = key
return cred
}
func (c *Credential) IsExcludedForAttestation(options AttestationOptions) bool {
encodedID := base64.RawURLEncoding.EncodeToString(c.ID)
for _, excludedID := range options.ExcludeCredentials {
if excludedID == encodedID {
return true
}
}
return false
}
func (c *Credential) IsAllowedForAssertion(options AssertionOptions) bool {
encodedID := base64.RawURLEncoding.EncodeToString(c.ID)
for _, allowedID := range options.AllowCredentials {
if allowedID == encodedID {
return true
}
}
return false
}