18
18
#[ cfg( all( not( feature = "std" ) , feature = "sgx" ) ) ]
19
19
extern crate sgx_tstd as std;
20
20
21
- mod ethereum_signature;
22
- mod identity;
23
- // mod trusted_call;
24
21
mod assertion;
25
22
mod enclave_quote;
23
+ mod ethereum_signature;
24
+ mod identity;
26
25
mod validation_data;
27
26
28
27
pub use ethereum_signature:: * ;
@@ -48,24 +47,31 @@ pub mod sgx_reexport_prelude {
48
47
49
48
use rand:: Rng ;
50
49
51
- // pub use trusted_call::*;
52
50
pub use assertion:: * ;
53
51
pub use enclave_quote:: * ;
54
52
pub use validation_data:: * ;
55
53
56
54
pub const CHALLENGE_CODE_SIZE : usize = 16 ;
57
55
pub type ChallengeCode = [ u8 ; CHALLENGE_CODE_SIZE ] ;
58
56
57
+ // Returns the default if any error happens
58
+ // We don't propagate the error to upper level as this function is used in too many places,
59
+ // it's too verbose to handle them all and pass back to the parentchain as events.
60
+ // We rely on the parentchain event consumers to handle them correctly (and they kind of
61
+ // have to, because they'll find all fields are 0)
59
62
pub fn aes_encrypt_default ( key : & UserShieldingKeyType , data : & [ u8 ] ) -> AesOutput {
60
63
let mut in_out = data. to_vec ( ) ;
61
64
62
65
let nonce = RingAeadNonceSequence :: new ( ) ;
63
66
let aad = b"" ;
64
- let unbound_key = UnboundKey :: new ( & AES_256_GCM , key. as_slice ( ) ) . unwrap ( ) ;
65
- let mut sealing_key = SealingKey :: new ( unbound_key, nonce. clone ( ) ) ;
66
- sealing_key. seal_in_place_append_tag ( Aad :: from ( aad) , & mut in_out) . unwrap ( ) ;
67
+ if let Ok ( unbound_key) = UnboundKey :: new ( & AES_256_GCM , key. as_slice ( ) ) {
68
+ let mut sealing_key = SealingKey :: new ( unbound_key, nonce. clone ( ) ) ;
69
+ if sealing_key. seal_in_place_append_tag ( Aad :: from ( aad) , & mut in_out) . is_ok ( ) {
70
+ return AesOutput { ciphertext : in_out. to_vec ( ) , aad : aad. to_vec ( ) , nonce : nonce. nonce }
71
+ }
72
+ }
67
73
68
- AesOutput { ciphertext : in_out . to_vec ( ) , aad : aad . to_vec ( ) , nonce : nonce . nonce }
74
+ AesOutput :: default ( )
69
75
}
70
76
71
77
#[ derive( Clone ) ]
0 commit comments