Skip to content

Commit fff8c78

Browse files
committed
fix test and remove coverage skip
1 parent cfe75d4 commit fff8c78

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/rust/src/backend/kdf.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,10 @@ impl HkdfExpand {
834834
}
835835
}
836836

837-
// NO-COVERAGE-START
838837
#[pyo3::pyclass(
839838
module = "cryptography.hazmat.primitives.kdf.x963kdf",
840839
name = "X963KDF"
841840
)]
842-
// NO-COVERAGE-END
843841
struct X963Kdf {
844842
algorithm: pyo3::Py<pyo3::PyAny>,
845843
length: usize,
@@ -863,15 +861,15 @@ impl X963Kdf {
863861
let digest_size = algorithm
864862
.bind(py)
865863
.getattr(pyo3::intern!(py, "digest_size"))?
866-
.extract::<usize>()?;
864+
.extract::<u64>()?;
867865

868-
let max_len = digest_size.checked_mul(u32::MAX as usize).ok_or_else(|| {
866+
let max_len = digest_size.checked_mul(u32::MAX as u64).ok_or_else(|| {
869867
pyo3::exceptions::PyValueError::new_err(
870868
"Digest size too large, would cause overflow in max length calculation",
871869
)
872870
})?;
873871

874-
if length > max_len {
872+
if length as u64 > max_len {
875873
return Err(CryptographyError::from(
876874
pyo3::exceptions::PyValueError::new_err(format!(
877875
"Cannot derive keys larger than {max_len} bits."

tests/hazmat/primitives/test_x963kdf.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
import binascii
7-
import sys
87

98
import pytest
109

@@ -111,13 +110,8 @@ def test_unicode_typeerror(self, backend):
111110
xkdf.verify(b"foo", "bar") # type: ignore[arg-type]
112111

113112
def test_digest_size_overflow(self):
114-
# Create a mock algorithm with a digest_size that would overflow
115-
# when multiplied by u32::MAX (2^32 - 1)
116-
# Using sys.maxsize // 2 works on both 32-bit and 64-bit:
117-
# - 32-bit: ~2^30 * 2^32 = 2^62 > 2^32-1 (overflow)
118-
# - 64-bit: ~2^62 * 2^32 = 2^94 > 2^64-1 (overflow)
119113
class MockHashAlgorithm(hashes.HashAlgorithm):
120-
digest_size = sys.maxsize // 2
114+
digest_size = 2**62
121115
name = "MockHashAlgorithm"
122116
block_size = 2**16
123117

0 commit comments

Comments
 (0)