Skip to content

Commit

Permalink
Simplify code with new pyo3 method (#9794)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Oct 28, 2023
1 parent 8cce93b commit ed57fbb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/rust/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use asn1::SimpleAsn1Readable;
use cryptography_x509::certificate::Certificate;
use cryptography_x509::common::{DssSignature, SubjectPublicKeyInfo, Time};
use cryptography_x509::name::Name;
use pyo3::basic::CompareOp;
use pyo3::types::IntoPyDict;
use pyo3::ToPyObject;

Expand Down Expand Up @@ -68,7 +67,7 @@ pub(crate) fn py_uint_to_big_endian_bytes<'p>(
v: &'p pyo3::types::PyLong,
) -> pyo3::PyResult<&'p [u8]> {
let zero = (0).to_object(py);
if v.rich_compare(zero, CompareOp::Lt)?.is_true()? {
if v.lt(zero)? {
return Err(pyo3::exceptions::PyValueError::new_err(
"Negative integers are not supported",
));
Expand Down
5 changes: 1 addition & 4 deletions src/rust/src/backend/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::backend::utils;
use crate::error::{CryptographyError, CryptographyResult};
use crate::{exceptions, types};
use foreign_types_shared::ForeignTypeRef;
use pyo3::basic::CompareOp;
use pyo3::ToPyObject;

#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ec")]
Expand Down Expand Up @@ -214,9 +213,7 @@ fn public_key_from_numbers(
let py_y = numbers.getattr(pyo3::intern!(py, "y"))?;

let zero = (0).to_object(py);
if py_x.rich_compare(&zero, CompareOp::Lt)?.is_true()?
|| py_y.rich_compare(&zero, CompareOp::Lt)?.is_true()?
{
if py_x.lt(&zero)? || py_y.lt(&zero)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err(
"Invalid EC key. Both x and y must be non-negative.",
Expand Down

0 comments on commit ed57fbb

Please sign in to comment.