@@ -36,104 +36,15 @@ pub mod prepare_key_attestation;
36
36
37
37
use zeroize:: Zeroize ;
38
38
39
- use crate :: requests:: { ResponseStatus , Result } ;
40
- use log:: error;
41
- use psa_algorithm:: algorithm:: { aead:: AeadWithDefaultLengthTag , key_agreement:: Raw , Cipher , Hash } ;
42
- use psa_key_attributes:: key_type:: { DhFamily , EccFamily } ;
43
- use can_do_crypto:: CheckType ;
39
+ #[ cfg( test) ]
40
+ use crate :: requests:: ResponseStatus ;
41
+ #[ cfg( test) ]
42
+ use psa_algorithm:: algorithm:: { Cipher , Hash } ;
43
+ #[ cfg( test) ]
44
+ use psa_key_attributes:: key_type:: EccFamily ;
45
+ #[ cfg( test) ]
44
46
use std:: convert:: TryFrom ;
45
47
46
- impl TryFrom < i32 > for Cipher {
47
- type Error = ResponseStatus ;
48
- fn try_from ( cipher_val : i32 ) -> Result < Self > {
49
- Cipher :: from_i32 ( cipher_val) . ok_or_else ( || {
50
- error ! (
51
- "Value {} not supported as a cipher algorithm encoding." ,
52
- cipher_val
53
- ) ;
54
- ResponseStatus :: InvalidEncoding
55
- } )
56
- }
57
- }
58
-
59
- impl TryFrom < i32 > for Hash {
60
- type Error = ResponseStatus ;
61
- fn try_from ( hash_val : i32 ) -> Result < Self > {
62
- Hash :: from_i32 ( hash_val) . ok_or_else ( || {
63
- error ! (
64
- "Value {} not supported as a hash algorithm encoding." ,
65
- hash_val
66
- ) ;
67
- ResponseStatus :: InvalidEncoding
68
- } )
69
- }
70
- }
71
-
72
- impl TryFrom < i32 > for AeadWithDefaultLengthTag {
73
- type Error = ResponseStatus ;
74
- fn try_from ( aead_val : i32 ) -> Result < Self > {
75
- AeadWithDefaultLengthTag :: from_i32 ( aead_val) . ok_or_else ( || {
76
- error ! (
77
- "Value {} not supported as an AEAD with default tag length algorithm encoding." ,
78
- aead_val
79
- ) ;
80
- ResponseStatus :: InvalidEncoding
81
- } )
82
- }
83
- }
84
-
85
- impl TryFrom < i32 > for Raw {
86
- type Error = ResponseStatus ;
87
- fn try_from ( key_agreement_val : i32 ) -> Result < Self > {
88
- Raw :: from_i32 ( key_agreement_val) . ok_or_else ( || {
89
- error ! (
90
- "Value {} not supported as a raw key agreement algorithm encoding." ,
91
- key_agreement_val
92
- ) ;
93
- ResponseStatus :: InvalidEncoding
94
- } )
95
- }
96
- }
97
-
98
- impl TryFrom < i32 > for EccFamily {
99
- type Error = ResponseStatus ;
100
- fn try_from ( ecc_family_val : i32 ) -> Result < Self > {
101
- EccFamily :: from_i32 ( ecc_family_val) . ok_or_else ( || {
102
- error ! (
103
- "Value {} not supported as an ECC family encoding." ,
104
- ecc_family_val
105
- ) ;
106
- ResponseStatus :: InvalidEncoding
107
- } )
108
- }
109
- }
110
-
111
- impl TryFrom < i32 > for DhFamily {
112
- type Error = ResponseStatus ;
113
- fn try_from ( dh_family_val : i32 ) -> Result < Self > {
114
- DhFamily :: from_i32 ( dh_family_val) . ok_or_else ( || {
115
- error ! (
116
- "Value {} not supported as a DH family encoding." ,
117
- dh_family_val
118
- ) ;
119
- ResponseStatus :: InvalidEncoding
120
- } )
121
- }
122
- }
123
-
124
- impl TryFrom < i32 > for CheckType {
125
- type Error = ResponseStatus ;
126
- fn try_from ( check_type_val : i32 ) -> Result < Self > {
127
- CheckType :: from_i32 ( check_type_val) . ok_or_else ( || {
128
- error ! (
129
- "Value {} not supported as a check type." ,
130
- check_type_val
131
- ) ;
132
- ResponseStatus :: InvalidEncoding
133
- } )
134
- }
135
- }
136
-
137
48
pub ( super ) trait ClearProtoMessage {
138
49
fn clear_message ( & mut self ) { }
139
50
}
@@ -299,11 +210,15 @@ impl ClearProtoMessage for psa_cipher_decrypt::Operation {
299
210
}
300
211
301
212
impl ClearProtoMessage for psa_cipher_encrypt:: Result {
302
- fn clear_message ( & mut self ) { self . ciphertext . zeroize ( ) ; }
213
+ fn clear_message ( & mut self ) {
214
+ self . ciphertext . zeroize ( ) ;
215
+ }
303
216
}
304
217
305
218
impl ClearProtoMessage for psa_cipher_decrypt:: Result {
306
- fn clear_message ( & mut self ) { self . plaintext . zeroize ( ) ; }
219
+ fn clear_message ( & mut self ) {
220
+ self . plaintext . zeroize ( ) ;
221
+ }
307
222
}
308
223
309
224
impl ClearProtoMessage for psa_generate_random:: Result {
@@ -402,23 +317,23 @@ impl ClearProtoMessage for prepare_key_attestation::Result {
402
317
#[ test]
403
318
fn i32_conversions ( ) {
404
319
assert_eq ! (
405
- Cipher :: try_from( 56 ) . unwrap_err( ) ,
320
+ < :: prost :: DecodeError as Into < ResponseStatus >> :: into ( Cipher :: try_from( 56 ) . unwrap_err( ) ) ,
406
321
ResponseStatus :: InvalidEncoding
407
322
) ;
408
323
assert_eq ! (
409
- Cipher :: try_from( -5 ) . unwrap_err( ) ,
324
+ < :: prost :: DecodeError as Into < ResponseStatus >> :: into ( Cipher :: try_from( -5 ) . unwrap_err( ) ) ,
410
325
ResponseStatus :: InvalidEncoding
411
326
) ;
412
327
assert_eq ! (
413
- Hash :: try_from( 89 ) . unwrap_err( ) ,
328
+ < :: prost :: DecodeError as Into < ResponseStatus >> :: into ( Hash :: try_from( 89 ) . unwrap_err( ) ) ,
414
329
ResponseStatus :: InvalidEncoding
415
330
) ;
416
331
assert_eq ! (
417
- Hash :: try_from( -4 ) . unwrap_err( ) ,
332
+ < :: prost :: DecodeError as Into < ResponseStatus >> :: into ( Hash :: try_from( -4 ) . unwrap_err( ) ) ,
418
333
ResponseStatus :: InvalidEncoding
419
334
) ;
420
335
assert_eq ! (
421
- EccFamily :: try_from( 78 ) . unwrap_err( ) ,
336
+ < :: prost :: DecodeError as Into < ResponseStatus >> :: into ( EccFamily :: try_from( 78 ) . unwrap_err( ) ) ,
422
337
ResponseStatus :: InvalidEncoding
423
338
) ;
424
339
}
0 commit comments