Skip to content

Commit f9cce16

Browse files
authored
Attempt to fix coverage due to rust nonsense (#13153)
1 parent 79ef1a9 commit f9cce16

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/rust/cryptography-openssl/src/aead.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ impl AeadCtx {
3737
AeadType::Aes256GcmSiv => unsafe { ffi::EVP_aead_aes_256_gcm_siv() },
3838
};
3939

40+
let key_ptr = key.as_ptr();
41+
let tag_len = ffi::EVP_AEAD_DEFAULT_TAG_LENGTH as usize;
4042
// SAFETY: We're passing a valid key and aead.
4143
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))?;
4845
Ok(AeadCtx::from_ptr(ctx))
4946
}
5047
}
@@ -87,7 +84,7 @@ impl AeadCtxRef {
8784
let mut out_len = out.len();
8885
// SAFETY: All the lengths and pointers are known valid.
8986
unsafe {
90-
cvt(ffi::EVP_AEAD_CTX_open(
87+
let res = ffi::EVP_AEAD_CTX_open(
9188
self.as_ptr(),
9289
out.as_mut_ptr(),
9390
&mut out_len,
@@ -98,7 +95,8 @@ impl AeadCtxRef {
9895
data.len(),
9996
ad.as_ptr(),
10097
ad.len(),
101-
))?;
98+
);
99+
cvt(res)?;
102100
}
103101
Ok(())
104102
}

src/rust/src/backend/aead.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,13 @@ impl EvpAead {
400400
assert!(aad.is_none());
401401
b""
402402
};
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+
})?)
413410
}
414411

415412
fn decrypt<'p>(

0 commit comments

Comments
 (0)