@@ -64,7 +64,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
6464 #[ allow( deprecated) ]
6565 let key_ref = ctx
6666 . dangerous_get_symmetric_key ( key_to_seal)
67- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KeyMissingError ) ?;
67+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KeyMissing ) ?;
6868 Self :: seal_ref ( key_ref, password)
6969 }
7070
@@ -97,7 +97,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
9797 // The envelope key is directly derived from the KDF and used as the key to encrypt the key
9898 // that should be sealed.
9999 let envelope_key = derive_key ( kdf_settings, password)
100- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KdfError ) ?;
100+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Kdf ) ?;
101101
102102 let ( content_format, key_to_seal_bytes) = match key_to_seal. to_encoded_raw ( ) {
103103 EncodedSymmetricKey :: BitwardenLegacyKey ( key_bytes) => {
@@ -145,7 +145,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
145145 let key = self . unseal_ref ( password) ?;
146146 #[ allow( deprecated) ]
147147 ctx. set_symmetric_key ( target_keyslot, key)
148- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KeyStoreError ) ?;
148+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KeyStore ) ?;
149149 Ok ( target_keyslot)
150150 }
151151
@@ -161,34 +161,32 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
161161 . first ( )
162162 . filter ( |_| self . cose_encrypt . recipients . len ( ) == 1 )
163163 . ok_or_else ( || {
164- PasswordProtectedKeyEnvelopeError :: ParsingError (
164+ PasswordProtectedKeyEnvelopeError :: Parsing (
165165 "Invalid number of recipients" . to_string ( ) ,
166166 )
167167 } ) ?;
168168
169169 if recipient. protected . header . alg != Some ( coset:: Algorithm :: PrivateUse ( ALG_ARGON2ID13 ) ) {
170- return Err ( PasswordProtectedKeyEnvelopeError :: ParsingError (
170+ return Err ( PasswordProtectedKeyEnvelopeError :: Parsing (
171171 "Unknown or unsupported KDF algorithm" . to_string ( ) ,
172172 ) ) ;
173173 }
174174
175175 let kdf_settings: Argon2RawSettings =
176176 ( & recipient. unprotected ) . try_into ( ) . map_err ( |_| {
177- PasswordProtectedKeyEnvelopeError :: ParsingError (
177+ PasswordProtectedKeyEnvelopeError :: Parsing (
178178 "Invalid or missing KDF parameters" . to_string ( ) ,
179179 )
180180 } ) ?;
181181 let envelope_key = derive_key ( & kdf_settings, password)
182- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KdfError ) ?;
182+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Kdf ) ?;
183183 let nonce: [ u8 ; crate :: xchacha20:: NONCE_SIZE ] = self
184184 . cose_encrypt
185185 . unprotected
186186 . iv
187187 . clone ( )
188188 . try_into ( )
189- . map_err ( |_| {
190- PasswordProtectedKeyEnvelopeError :: ParsingError ( "Invalid IV" . to_string ( ) )
191- } ) ?;
189+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Parsing ( "Invalid IV" . to_string ( ) ) ) ?;
192190
193191 let key_bytes = self
194192 . cose_encrypt
@@ -201,9 +199,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
201199
202200 SymmetricCryptoKey :: try_from (
203201 match ContentFormat :: try_from ( & self . cose_encrypt . protected . header ) . map_err ( |_| {
204- PasswordProtectedKeyEnvelopeError :: ParsingError (
205- "Invalid content format" . to_string ( ) ,
206- )
202+ PasswordProtectedKeyEnvelopeError :: Parsing ( "Invalid content format" . to_string ( ) )
207203 } ) ? {
208204 ContentFormat :: BitwardenLegacyKey => EncodedSymmetricKey :: BitwardenLegacyKey (
209205 BitwardenLegacyKeyBytes :: from ( key_bytes) ,
@@ -212,15 +208,13 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
212208 EncodedSymmetricKey :: CoseKey ( CoseKeyBytes :: from ( key_bytes) )
213209 }
214210 _ => {
215- return Err ( PasswordProtectedKeyEnvelopeError :: ParsingError (
211+ return Err ( PasswordProtectedKeyEnvelopeError :: Parsing (
216212 "Unknown or unsupported content format" . to_string ( ) ,
217213 ) ) ;
218214 }
219215 } ,
220216 )
221- . map_err ( |_| {
222- PasswordProtectedKeyEnvelopeError :: ParsingError ( "Failed to decode key" . to_string ( ) )
223- } )
217+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Parsing ( "Failed to decode key" . to_string ( ) ) )
224218 }
225219
226220 /// Re-seals the key with new KDF parameters (updated settings, salt), and a new password
@@ -268,12 +262,12 @@ impl<Ids: KeyIds> FromStr for PasswordProtectedKeyEnvelope<Ids> {
268262
269263 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
270264 let data = B64 :: try_from ( s) . map_err ( |_| {
271- PasswordProtectedKeyEnvelopeError :: ParsingError (
265+ PasswordProtectedKeyEnvelopeError :: Parsing (
272266 "Invalid PasswordProtectedKeyEnvelope Base64 encoding" . to_string ( ) ,
273267 )
274268 } ) ?;
275269 Self :: try_from ( & data. into_bytes ( ) ) . map_err ( |_| {
276- PasswordProtectedKeyEnvelopeError :: ParsingError (
270+ PasswordProtectedKeyEnvelopeError :: Parsing (
277271 "Failed to parse PasswordProtectedKeyEnvelope" . to_string ( ) ,
278272 )
279273 } )
@@ -373,7 +367,7 @@ impl TryInto<Params> for &Argon2RawSettings {
373367 self . parallelism ,
374368 Some ( ENVELOPE_ARGON2_OUTPUT_KEY_SIZE ) ,
375369 )
376- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KdfError )
370+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Kdf )
377371 }
378372}
379373
@@ -388,9 +382,7 @@ impl TryInto<Argon2RawSettings> for &Header {
388382 salt : extract_bytes ( self , ARGON2_SALT , "salt" ) ?
389383 . try_into ( )
390384 . map_err ( |_| {
391- PasswordProtectedKeyEnvelopeError :: ParsingError (
392- "Invalid Argon2 salt" . to_string ( ) ,
393- )
385+ PasswordProtectedKeyEnvelopeError :: Parsing ( "Invalid Argon2 salt" . to_string ( ) )
394386 } ) ?,
395387 } )
396388 }
@@ -415,7 +407,7 @@ fn derive_key(
415407 argon2_settings. try_into ( ) ?,
416408 )
417409 . hash_password_into ( password. as_bytes ( ) , & argon2_settings. salt , & mut hash)
418- . map_err ( |_| PasswordProtectedKeyEnvelopeError :: KdfError ) ?;
410+ . map_err ( |_| PasswordProtectedKeyEnvelopeError :: Kdf ) ?;
419411
420412 Ok ( hash)
421413}
@@ -428,29 +420,29 @@ pub enum PasswordProtectedKeyEnvelopeError {
428420 WrongPassword ,
429421 /// The envelope could not be parsed correctly, or the KDF parameters are invalid
430422 #[ error( "Parsing error {0}" ) ]
431- ParsingError ( String ) ,
423+ Parsing ( String ) ,
432424 /// The KDF failed to derive a key, possibly due to invalid parameters or memory allocation
433425 /// issues
434426 #[ error( "Kdf error" ) ]
435- KdfError ,
427+ Kdf ,
436428 /// There is no key for the provided key id in the key store
437429 #[ error( "Key missing error" ) ]
438- KeyMissingError ,
430+ KeyMissing ,
439431 /// The key store could not be written to, for example due to being read-only
440432 #[ error( "Could not write to key store" ) ]
441- KeyStoreError ,
433+ KeyStore ,
442434}
443435
444436impl From < CoseExtractError > for PasswordProtectedKeyEnvelopeError {
445437 fn from ( err : CoseExtractError ) -> Self {
446438 let CoseExtractError :: MissingValue ( label) = err;
447- PasswordProtectedKeyEnvelopeError :: ParsingError ( format ! ( "Missing value for {}" , label) )
439+ PasswordProtectedKeyEnvelopeError :: Parsing ( format ! ( "Missing value for {}" , label) )
448440 }
449441}
450442
451443impl From < TryFromIntError > for PasswordProtectedKeyEnvelopeError {
452444 fn from ( err : TryFromIntError ) -> Self {
453- PasswordProtectedKeyEnvelopeError :: ParsingError ( format ! ( "Invalid integer: {}" , err) )
445+ PasswordProtectedKeyEnvelopeError :: Parsing ( format ! ( "Invalid integer: {}" , err) )
454446 }
455447}
456448
0 commit comments