File tree Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,11 @@ impl AeadCtx {
37
37
AeadType :: Aes256GcmSiv => unsafe { ffi:: EVP_aead_aes_256_gcm_siv ( ) } ,
38
38
} ;
39
39
40
+ let key_ptr = key. as_ptr ( ) ;
41
+ let tag_len = ffi:: EVP_AEAD_DEFAULT_TAG_LENGTH as usize ;
40
42
// SAFETY: We're passing a valid key and aead.
41
43
unsafe {
42
- let ctx = cvt_p ( ffi:: EVP_AEAD_CTX_new (
43
- aead,
44
- key. as_ptr ( ) ,
45
- key. len ( ) ,
46
- ffi:: EVP_AEAD_DEFAULT_TAG_LENGTH as usize ,
47
- ) ) ?;
44
+ let ctx = cvt_p ( ffi:: EVP_AEAD_CTX_new ( aead, key_ptr, key. len ( ) , tag_len) ) ?;
48
45
Ok ( AeadCtx :: from_ptr ( ctx) )
49
46
}
50
47
}
@@ -87,7 +84,7 @@ impl AeadCtxRef {
87
84
let mut out_len = out. len ( ) ;
88
85
// SAFETY: All the lengths and pointers are known valid.
89
86
unsafe {
90
- cvt ( ffi:: EVP_AEAD_CTX_open (
87
+ let res = ffi:: EVP_AEAD_CTX_open (
91
88
self . as_ptr ( ) ,
92
89
out. as_mut_ptr ( ) ,
93
90
& mut out_len,
@@ -98,7 +95,8 @@ impl AeadCtxRef {
98
95
data. len ( ) ,
99
96
ad. as_ptr ( ) ,
100
97
ad. len ( ) ,
101
- ) ) ?;
98
+ ) ;
99
+ cvt ( res) ?;
102
100
}
103
101
Ok ( ( ) )
104
102
}
Original file line number Diff line number Diff line change @@ -400,16 +400,13 @@ impl EvpAead {
400
400
assert ! ( aad. is_none( ) ) ;
401
401
b""
402
402
} ;
403
- Ok ( pyo3:: types:: PyBytes :: new_with (
404
- py,
405
- plaintext. len ( ) + self . tag_len ,
406
- |b| {
407
- self . ctx
408
- . encrypt ( plaintext, nonce. unwrap_or ( b"" ) , ad, b)
409
- . map_err ( CryptographyError :: from) ?;
410
- Ok ( ( ) )
411
- } ,
412
- ) ?)
403
+ let out_len = plaintext. len ( ) + self . tag_len ;
404
+ Ok ( pyo3:: types:: PyBytes :: new_with ( py, out_len, |b| {
405
+ self . ctx
406
+ . encrypt ( plaintext, nonce. unwrap_or ( b"" ) , ad, b)
407
+ . map_err ( CryptographyError :: from) ?;
408
+ Ok ( ( ) )
409
+ } ) ?)
413
410
}
414
411
415
412
fn decrypt < ' p > (
You can’t perform that action at this time.
0 commit comments