-
Notifications
You must be signed in to change notification settings - Fork 2
/
verify_options.go
39 lines (34 loc) · 1.18 KB
/
verify_options.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
package webauthn
type verifyConfig struct {
allowedFormats map[AttestationFormat]struct{}
allowedTypes map[AttestationType]struct{}
}
// A VerifyOption customizes how verification is performed.
type VerifyOption func(*verifyConfig)
// WithVerifyAllowedFormats sets the allowedFormats in the verify config.
func WithVerifyAllowedFormats(allowedFormats ...AttestationFormat) VerifyOption {
return func(cfg *verifyConfig) {
cfg.allowedFormats = map[AttestationFormat]struct{}{}
for _, allowedFormat := range allowedFormats {
cfg.allowedFormats[allowedFormat] = struct{}{}
}
}
}
// WithVerifyAllowedTypes sets the allowedTypes in the verify config.
func WithVerifyAllowedTypes(allowedTypes ...AttestationType) VerifyOption {
return func(cfg *verifyConfig) {
cfg.allowedTypes = map[AttestationType]struct{}{}
for _, allowedType := range allowedTypes {
cfg.allowedTypes[allowedType] = struct{}{}
}
}
}
func getVerifyConfig(options ...VerifyOption) (*verifyConfig, error) {
cfg := new(verifyConfig)
WithVerifyAllowedFormats(AllAttestationFormats...)(cfg)
WithVerifyAllowedTypes(AllAttestationTypes...)(cfg)
for _, option := range options {
option(cfg)
}
return cfg, nil
}