@@ -76,16 +76,47 @@ type Version struct {
7676}
7777
7878// Formfactor enumerates the physical set of forms a key can take. USB-A vs.
79- // USB-C and Keychain vs. Nano.
79+ // USB-C and Keychain vs. Nano (and FIPS variants for these) .
8080type Formfactor int
8181
82- // Formfactors recognized by this package.
82+ // The mapping between known Formfactor values and their descriptions.
83+ var formFactorStrings = map [Formfactor ]string {
84+ FormfactorUSBAKeychain : "USB-A Keychain" ,
85+ FormfactorUSBANano : "USB-A Nano" ,
86+ FormfactorUSBCKeychain : "USB-C Keychain" ,
87+ FormfactorUSBCNano : "USB-C Nano" ,
88+ FormfactorUSBCLightningKeychain : "USB-C/Lightning Keychain" ,
89+
90+ FormfactorUSBAKeychainFIPS : "USB-A Keychain FIPS" ,
91+ FormfactorUSBANanoFIPS : "USB-A Nano FIPS" ,
92+ FormfactorUSBCKeychainFIPS : "USB-C Keychain FIPS" ,
93+ FormfactorUSBCNanoFIPS : "USB-C Nano FIPS" ,
94+ FormfactorUSBCLightningKeychainFIPS : "USB-C/Lightning Keychain FIPS" ,
95+ }
96+
97+ // String returns the human-readable description for the given form-factor
98+ // value, or a fallback value for any other, unknown form-factor.
99+ func (f Formfactor ) String () string {
100+ if s , ok := formFactorStrings [f ]; ok {
101+ return s
102+ }
103+ return fmt .Sprintf ("unknown(0x%02x)" , int (f ))
104+ }
105+
106+ // Formfactors recognized by this package. See the reference for more information:
107+ // https://developers.yubico.com/yubikey-manager/Config_Reference.html#_form_factor
83108const (
84- FormfactorUSBAKeychain = iota + 1
85- FormfactorUSBANano
86- FormfactorUSBCKeychain
87- FormfactorUSBCNano
88- FormfactorUSBCLightningKeychain
109+ FormfactorUSBAKeychain = 0x1
110+ FormfactorUSBANano = 0x2
111+ FormfactorUSBCKeychain = 0x3
112+ FormfactorUSBCNano = 0x4
113+ FormfactorUSBCLightningKeychain = 0x5
114+
115+ FormfactorUSBAKeychainFIPS = 0x81
116+ FormfactorUSBANanoFIPS = 0x82
117+ FormfactorUSBCKeychainFIPS = 0x83
118+ FormfactorUSBCNanoFIPS = 0x84
119+ FormfactorUSBCLightningKeychainFIPS = 0x85
89120)
90121
91122// Prefix in the x509 Subject Common Name for YubiKey attestations
@@ -163,20 +194,7 @@ func (a *Attestation) addExt(e pkix.Extension) error {
163194 if len (e .Value ) != 1 {
164195 return fmt .Errorf ("expected 1 byte from formfactor, got: %d" , len (e .Value ))
165196 }
166- switch e .Value [0 ] {
167- case 0x01 :
168- a .Formfactor = FormfactorUSBAKeychain
169- case 0x02 :
170- a .Formfactor = FormfactorUSBANano
171- case 0x03 :
172- a .Formfactor = FormfactorUSBCKeychain
173- case 0x04 :
174- a .Formfactor = FormfactorUSBCNano
175- case 0x05 :
176- a .Formfactor = FormfactorUSBCLightningKeychain
177- default :
178- return fmt .Errorf ("unrecognized formfactor: 0x%x" , e .Value [0 ])
179- }
197+ a .Formfactor = Formfactor (e .Value [0 ])
180198 }
181199 return nil
182200}
0 commit comments