Skip to content

Commit

Permalink
Use native binop methods instead of weird calls (#10716)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Apr 5, 2024
1 parent 166d21a commit c913f88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
13 changes: 4 additions & 9 deletions src/rust/src/backend/dsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,10 @@ fn check_dsa_private_numbers(
));
}

if numbers
.public_numbers
.get()
.y
.as_ref(py)
.ne(params.g.as_ref(py).call_method1(
pyo3::intern!(py, "__pow__"),
(numbers.x.as_ref(py), params.p.as_ref(py)),
)?)?
if numbers.public_numbers.get().y.as_ref(py).ne(params
.g
.bind(py)
.pow(numbers.x.as_ref(py), Some(params.p.as_ref(py)))?)?
{
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("y must be equal to (g ** x % p)."),
Expand Down
12 changes: 5 additions & 7 deletions src/rust/src/backend/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,26 +636,25 @@ fn check_private_key_components(
));
}

// No `bitand` method.
if public_exponent.call_method1("__and__", (1,))?.eq(0)? {
if public_exponent.bitand(1)?.eq(0)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("public_exponent must be odd."),
));
}

if dmp1.call_method1("__and__", (1,))?.eq(0)? {
if dmp1.bitand(1)?.eq(0)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("dmp1 must be odd."),
));
}

if dmq1.call_method1("__and__", (1,))?.eq(0)? {
if dmq1.bitand(1)?.eq(0)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("dmq1 must be odd."),
));
}

if p.call_method1("__mul__", (q,))?.ne(modulus)? {
if p.mul(q)?.ne(modulus)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("p*q must equal modulus."),
));
Expand Down Expand Up @@ -771,8 +770,7 @@ fn check_public_key_components(
));
}

// No `bitand` method.
if e.call_method1("__and__", (1,))?.eq(0)? {
if e.bitand(1)?.eq(0)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("e must be odd."),
));
Expand Down

0 comments on commit c913f88

Please sign in to comment.