@@ -40,7 +40,6 @@ pub struct Device {
4040pub enum Operation {
4141 Create ,
4242 Get ,
43- SetDevicePin ,
4443}
4544
4645#[ derive( Clone , Debug , PartialEq , Serialize , Deserialize , Type ) ]
@@ -121,33 +120,6 @@ pub struct RequestingParty {
121120 pub origin : String ,
122121}
123122
124- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
125- pub enum ViewUpdateFailure {
126- GeneralFailure ( String ) ,
127- /// Request required UV, but it was not set on the device yet
128- PinNotSet ( String ) ,
129- /// User tried to set PIN, but it was too short
130- PinPolicyViolation ( String ) ,
131- }
132-
133- impl ViewUpdateFailure {
134- pub fn into_string ( self ) -> String {
135- match self {
136- ViewUpdateFailure :: GeneralFailure ( msg)
137- | ViewUpdateFailure :: PinNotSet ( msg)
138- | ViewUpdateFailure :: PinPolicyViolation ( msg) => msg,
139- }
140- }
141- }
142-
143- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
144- pub enum ViewUpdateSuccess {
145- /// Success that requires the window to close
146- CloseWindow ,
147- /// Success that requires the window to stay open
148- KeepWindowOpen ( String ) ,
149- }
150-
151123#[ derive( Debug , Clone , Serialize , Deserialize ) ]
152124pub enum ViewUpdate {
153125 SetTitle ( ( String , String ) ) ,
@@ -160,17 +132,48 @@ pub enum ViewUpdate {
160132 UsbNeedsPin { attempts_left : Option < u32 > } ,
161133 UsbNeedsUserVerification { attempts_left : Option < u32 > } ,
162134 UsbNeedsUserPresence ,
135+ UsbPinNotSet { error : Option < PinNotSetError > } ,
163136
164137 NfcNeedsPin { attempts_left : Option < u32 > } ,
165138 NfcNeedsUserVerification { attempts_left : Option < u32 > } ,
139+ NfcPinNotSet { error : Option < PinNotSetError > } ,
166140
167141 HybridNeedsQrCode ( String ) ,
168142 HybridConnecting ,
169143 HybridConnected ,
170144
171- Completed ( ViewUpdateSuccess ) ,
145+ Completed ,
172146 Cancelled ,
173- Failed ( ViewUpdateFailure ) ,
147+ Failed ( String ) ,
148+ }
149+
150+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
151+ pub enum PinNotSetError {
152+ /// PIN too short
153+ PinTooShort ,
154+ /// PIN too long
155+ PinTooLong ,
156+ /// PIN violates PinPolicy
157+ PinPolicyViolation ,
158+ }
159+
160+ impl PinNotSetError {
161+ pub fn to_string ( & self ) -> String {
162+ match self {
163+ PinNotSetError :: PinTooShort => String :: from ( "Pin too short" ) ,
164+ PinNotSetError :: PinTooLong => String :: from ( "Pin too long" ) ,
165+ PinNotSetError :: PinPolicyViolation => String :: from ( "Pin policy violation" ) ,
166+ }
167+ }
168+
169+ pub fn from_string ( error : & str ) -> Option < PinNotSetError > {
170+ match error {
171+ "Pin too short" => Some ( PinNotSetError :: PinTooShort ) ,
172+ "Pin too long" => Some ( PinNotSetError :: PinTooLong ) ,
173+ "Pin policy violation" => Some ( PinNotSetError :: PinPolicyViolation ) ,
174+ _ => None ,
175+ }
176+ }
174177}
175178
176179#[ derive( Clone , Debug , Default ) ]
@@ -220,6 +223,11 @@ pub enum UsbState {
220223 attempts_left : Option < u32 > ,
221224 } ,
222225
226+ /// The device needs the PIN to be entered.
227+ PinNotSet {
228+ error : Option < PinNotSetError > ,
229+ } ,
230+
223231 /// The device needs on-device user verification.
224232 NeedsUserVerification {
225233 attempts_left : Option < u32 > ,
@@ -259,6 +267,9 @@ pub enum NfcState {
259267 /// The device needs the PIN to be entered.
260268 NeedsPin { attempts_left : Option < u32 > } ,
261269
270+ /// The device needs the PIN to be entered.
271+ PinNotSet { error : Option < PinNotSetError > } ,
272+
262273 /// The device needs on-device user verification.
263274 NeedsUserVerification { attempts_left : Option < u32 > } ,
264275
@@ -299,10 +310,6 @@ pub enum Error {
299310 /// Note that this is different than exhausting the PIN count that fully
300311 /// locks out the device.
301312 PinAttemptsExhausted ,
302- /// The RP requires user verification, but the device has no PIN/Biometrics set.
303- PinNotSet ,
304- /// The device declined the entered PIN, as it violates the PIN policy (e.g. PIN too short)
305- PinPolicyViolation ,
306313 // TODO: We may want to hide the details on this variant from the public API.
307314 /// Something went wrong with the credential service itself, not the authenticator.
308315 Internal ( String ) ,
@@ -314,8 +321,6 @@ impl Display for Error {
314321 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
315322 match self {
316323 Self :: AuthenticatorError => f. write_str ( "AuthenticatorError" ) ,
317- Self :: PinNotSet => f. write_str ( "PinNotSet" ) ,
318- Self :: PinPolicyViolation => f. write_str ( "PinPolicyViolation" ) ,
319324 Self :: NoCredentials => f. write_str ( "NoCredentials" ) ,
320325 Self :: CredentialExcluded => f. write_str ( "CredentialExcluded" ) ,
321326 Self :: PinAttemptsExhausted => f. write_str ( "PinAttemptsExhausted" ) ,
0 commit comments