@@ -27,7 +27,7 @@ impl<Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output>
2727 }
2828}
2929
30- impl < Ids : KeyIds , Key : KeyId , T : CompositeEncryptable < Ids , Key , Output > , Output >
30+ impl < Ids : KeyIds , Key : KeyId , T : CompositeEncryptable < Ids , Key , Output > , Output >
3131 CompositeEncryptable < Ids , Key , Vec < Output > > for Vec < T >
3232{
3333 fn encrypt_composite (
@@ -41,14 +41,10 @@ impl <Ids: KeyIds, Key: KeyId, T: CompositeEncryptable<Ids, Key, Output>, Output
4141 }
4242}
4343
44- /// An encryption operation that takes the input value - a primitive such as `String` and encrypts it into the output value.
45- /// The implementation decides the content format.
44+ /// An encryption operation that takes the input value - a primitive such as `String` and encrypts
45+ /// it into the output value. The implementation decides the content format.
4646pub trait TypedEncryptable < Ids : KeyIds , Key : KeyId , Output > {
47- fn encrypt (
48- & self ,
49- ctx : & mut KeyStoreContext < Ids > ,
50- key : Key ,
51- ) -> Result < Output , CryptoError > ;
47+ fn encrypt ( & self , ctx : & mut KeyStoreContext < Ids > , key : Key ) -> Result < Output , CryptoError > ;
5248}
5349
5450impl < Ids : KeyIds , Key : KeyId , T : TypedEncryptable < Ids , Key , Output > , Output >
@@ -65,8 +61,7 @@ impl<Ids: KeyIds, Key: KeyId, T: TypedEncryptable<Ids, Key, Output>, Output>
6561 }
6662}
6763
68- impl < Ids : KeyIds > TypedEncryptable < Ids , Ids :: Symmetric , EncString > for & str
69- {
64+ impl < Ids : KeyIds > TypedEncryptable < Ids , Ids :: Symmetric , EncString > for & str {
7065 fn encrypt (
7166 & self ,
7267 ctx : & mut KeyStoreContext < Ids > ,
@@ -76,8 +71,7 @@ impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for &str
7671 }
7772}
7873
79- impl < Ids : KeyIds > TypedEncryptable < Ids , Ids :: Symmetric , EncString > for String
80- {
74+ impl < Ids : KeyIds > TypedEncryptable < Ids , Ids :: Symmetric , EncString > for String {
8175 fn encrypt (
8276 & self ,
8377 ctx : & mut KeyStoreContext < Ids > ,
@@ -87,7 +81,8 @@ impl<Ids: KeyIds> TypedEncryptable<Ids, Ids::Symmetric, EncString> for String
8781 }
8882}
8983
90- /// An encryption operation that takes the input value - a primitive such as `Vec<u8>` - and encrypts it into the output value.
84+ /// An encryption operation that takes the input value - a primitive such as `Vec<u8>` - and
85+ /// encrypts it into the output value.
9186pub trait Encryptable < Ids : KeyIds , Key : KeyId , Output > {
9287 fn encrypt (
9388 & self ,
@@ -152,7 +147,8 @@ impl<Ids: KeyIds, Key: KeyId, T: Encryptable<Ids, Key, Output>, Output>
152147#[ cfg( test) ]
153148mod tests {
154149 use crate :: {
155- cose:: ContentFormat , traits:: tests:: * , AsymmetricCryptoKey , Decryptable , Encryptable , KeyStore , SymmetricCryptoKey , TypedEncryptable
150+ cose:: ContentFormat , traits:: tests:: * , AsymmetricCryptoKey , Decryptable , Encryptable ,
151+ KeyStore , SymmetricCryptoKey , TypedEncryptable ,
156152 } ;
157153
158154 fn test_store ( ) -> KeyStore < TestIds > {
@@ -207,12 +203,8 @@ mod tests {
207203 let string_data = "Hello, World!" . to_string ( ) ;
208204 let str_data: & str = string_data. as_str ( ) ;
209205
210- let string_encrypted = string_data
211- . encrypt ( & mut ctx, key)
212- . unwrap ( ) ;
213- let str_encrypted = str_data
214- . encrypt ( & mut ctx, key)
215- . unwrap ( ) ;
206+ let string_encrypted = string_data. encrypt ( & mut ctx, key) . unwrap ( ) ;
207+ let str_encrypted = str_data. encrypt ( & mut ctx, key) . unwrap ( ) ;
216208
217209 let string_decrypted: String = string_encrypted. decrypt ( & mut ctx, key) . unwrap ( ) ;
218210 let str_decrypted: String = str_encrypted. decrypt ( & mut ctx, key) . unwrap ( ) ;
@@ -229,9 +221,7 @@ mod tests {
229221
230222 let string_data = Some ( "Hello, World!" . to_string ( ) ) ;
231223
232- let string_encrypted = string_data
233- . encrypt ( & mut ctx, key)
234- . unwrap ( ) ;
224+ let string_encrypted = string_data. encrypt ( & mut ctx, key) . unwrap ( ) ;
235225
236226 let string_decrypted: Option < String > = string_encrypted. decrypt ( & mut ctx, key) . unwrap ( ) ;
237227
@@ -245,17 +235,13 @@ mod tests {
245235
246236 let key = TestSymmKey :: A ( 0 ) ;
247237 let none_data: Option < String > = None ;
248- let string_encrypted = none_data
249- . encrypt ( & mut ctx, key)
250- . unwrap ( ) ;
238+ let string_encrypted = none_data. encrypt ( & mut ctx, key) . unwrap ( ) ;
251239 assert_eq ! ( string_encrypted, None ) ;
252240
253241 // The None implementation will not do any decrypt operations, so it won't fail even if the
254242 // key doesn't exist
255243 let bad_key = TestSymmKey :: B ( ( 0 , 1 ) ) ;
256- let string_encrypted_bad = none_data
257- . encrypt ( & mut ctx, bad_key)
258- . unwrap ( ) ;
244+ let string_encrypted_bad = none_data. encrypt ( & mut ctx, bad_key) . unwrap ( ) ;
259245 assert_eq ! ( string_encrypted_bad, None ) ;
260246 }
261247}
0 commit comments