-
Notifications
You must be signed in to change notification settings - Fork 2
/
option.go
111 lines (102 loc) · 3.75 KB
/
option.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
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
package warp
//Option is a function that can be passed as a parameter to StartRegistration
//or StartAuthentication functions which adjusts the final options object.
//Options must typecheck for a pointer to PublicKeyCredentialCreationOptions or
//PublicKeyCredentialRequestOptions
type Option func(interface{}) error
//Timeout returns an option that adds a custom timeout to the credential
//creation options or credential request options object
func Timeout(timeout uint) Option {
return func(in interface{}) error {
switch opt := in.(type) {
case *PublicKeyCredentialCreationOptions:
opt.Timeout = timeout
case *PublicKeyCredentialRequestOptions:
opt.Timeout = timeout
default:
return ErrOption.Wrap(NewError("Timeout must receive creation or request object"))
}
return nil
}
}
//Extensions returns an option that adds one or more extensions to the
//creation options object or request options object
func Extensions(exts ...Extension) Option {
return func(in interface{}) error {
switch opt := in.(type) {
case *PublicKeyCredentialCreationOptions:
opt.Extensions = BuildExtensions(exts...)
case *PublicKeyCredentialRequestOptions:
opt.Extensions = BuildExtensions(exts...)
default:
return ErrOption.Wrap(NewError("Extensions must receive creation or request option"))
}
return nil
}
}
//ExcludeCredentials returns an option that adds a list of credentials to
//exclude to the creation options object
func ExcludeCredentials(creds []PublicKeyCredentialDescriptor) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialCreationOptions); ok {
opt.ExcludeCredentials = creds
return nil
}
return ErrOption.Wrap(NewError("ExcludeCredentials must receive creation object"))
}
}
//AuthenticatorSelection returns an option that adds authenticator selection
//criteria to the creation options object
func AuthenticatorSelection(criteria AuthenticatorSelectionCriteria) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialCreationOptions); ok {
opt.AuthenticatorSelection = &criteria
return nil
}
return ErrOption.Wrap(NewError("AuthenticatorSelection must receive creation object"))
}
}
//Attestation returns an option that adds an attestation conveyance
//preference to the creation options object
func Attestation(pref AttestationConveyancePreference) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialCreationOptions); ok {
opt.Attestation = pref
return nil
}
return ErrOption.Wrap(NewError("Attestation must receive creation object"))
}
}
//RelyingPartyID returns an option that specifies the Relying Party ID in the
//credential request object
func RelyingPartyID(rpID string) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialRequestOptions); ok {
opt.RPID = rpID
return nil
}
return ErrOption.Wrap(NewError("RelyingPartyID must receive request object"))
}
}
//AllowCredentials returns an option that adds a list of allowed credentials to
//the credential request object
func AllowCredentials(creds []PublicKeyCredentialDescriptor) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialRequestOptions); ok {
opt.AllowCredentials = creds
return nil
}
return ErrOption.Wrap(NewError("AllowCredentials must receive request object"))
}
}
//UserVerification returns an option that adds the relying party argument for
//user verification to the credential request object
func UserVerification(req UserVerificationRequirement) Option {
return func(in interface{}) error {
if opt, ok := in.(*PublicKeyCredentialRequestOptions); ok {
opt.UserVerification = req
return nil
}
return ErrOption.Wrap(NewError("UserVerification must receive request object"))
}
}