-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathauthenticator.go
38 lines (32 loc) · 991 Bytes
/
authenticator.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
package virtualwebauthn
type AuthenticatorOptions struct {
UserHandle []byte
UserNotPresent bool
UserNotVerified bool
BackupEligible bool
BackupState bool
}
type Authenticator struct {
Options AuthenticatorOptions `json:"options"`
Aaguid [16]byte `json:"aaguid"`
Credentials []Credential `json:"credentials,omitempty"`
}
func NewAuthenticator() Authenticator {
return NewAuthenticatorWithOptions(AuthenticatorOptions{})
}
func NewAuthenticatorWithOptions(options AuthenticatorOptions) Authenticator {
auth := Authenticator{Options: options}
copy(auth.Aaguid[:], randomBytes(len(auth.Aaguid)))
return auth
}
func (a *Authenticator) AddCredential(cred Credential) {
a.Credentials = append(a.Credentials, cred)
}
func (a *Authenticator) FindAllowedCredential(options AssertionOptions) *Credential {
for i := range a.Credentials {
if a.Credentials[i].IsAllowedForAssertion(options) {
return &a.Credentials[i]
}
}
return nil
}