Skip to content

Commit

Permalink
Rename get_bound back to get (#10803)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Apr 12, 2024
1 parent 5c559e0 commit 8d36296
Show file tree
Hide file tree
Showing 25 changed files with 304 additions and 370 deletions.
4 changes: 2 additions & 2 deletions src/rust/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub(crate) fn encode_der_data<'p>(
data: Vec<u8>,
encoding: &pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if encoding.is(&types::ENCODING_DER.get_bound(py)?) {
if encoding.is(&types::ENCODING_DER.get(py)?) {
Ok(pyo3::types::PyBytes::new_bound(py, &data))
} else if encoding.is(&types::ENCODING_PEM.get_bound(py)?) {
} else if encoding.is(&types::ENCODING_PEM.get(py)?) {
Ok(pyo3::types::PyBytes::new_bound(
py,
&pem::encode_config(
Expand Down
12 changes: 6 additions & 6 deletions src/rust/src/backend/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl ChaCha20Poly1305 {

#[staticmethod]
fn generate_key(py: pyo3::Python<'_>) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
Ok(types::OS_URANDOM.get_bound(py)?.call1((32,))?)
Ok(types::OS_URANDOM.get(py)?.call1((32,))?)
}

fn encrypt<'p>(
Expand Down Expand Up @@ -648,7 +648,7 @@ impl AesGcm {
));
}

Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
}

fn encrypt<'p>(
Expand Down Expand Up @@ -759,7 +759,7 @@ impl AesCcm {
));
}

Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
}

fn encrypt<'p>(
Expand Down Expand Up @@ -892,7 +892,7 @@ impl AesSiv {
));
}

Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
}

#[pyo3(signature = (data, associated_data))]
Expand Down Expand Up @@ -989,7 +989,7 @@ impl AesOcb3 {
));
}

Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
}

#[pyo3(signature = (nonce, data, associated_data))]
Expand Down Expand Up @@ -1098,7 +1098,7 @@ impl AesGcmSiv {
));
}

Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
}

#[pyo3(signature = (nonce, data, associated_data))]
Expand Down
44 changes: 22 additions & 22 deletions src/rust/src/backend/cipher_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,38 @@ fn get_cipher_registry(
REGISTRY.get_or_try_init(py, || {
let mut m = RegistryBuilder::new(py);

let aes = types::AES.get_bound(py)?;
let aes128 = types::AES128.get_bound(py)?;
let aes256 = types::AES256.get_bound(py)?;
let triple_des = types::TRIPLE_DES.get_bound(py)?;
let aes = types::AES.get(py)?;
let aes128 = types::AES128.get(py)?;
let aes256 = types::AES256.get(py)?;
let triple_des = types::TRIPLE_DES.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_CAMELLIA"))]
let camellia = types::CAMELLIA.get_bound(py)?;
let camellia = types::CAMELLIA.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_BF"))]
let blowfish = types::BLOWFISH.get_bound(py)?;
let blowfish = types::BLOWFISH.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_CAST"))]
let cast5 = types::CAST5.get_bound(py)?;
let cast5 = types::CAST5.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_IDEA"))]
let idea = types::IDEA.get_bound(py)?;
let idea = types::IDEA.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_SM4"))]
let sm4 = types::SM4.get_bound(py)?;
let sm4 = types::SM4.get(py)?;
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_SEED"))]
let seed = types::SEED.get_bound(py)?;
let arc4 = types::ARC4.get_bound(py)?;
let seed = types::SEED.get(py)?;
let arc4 = types::ARC4.get(py)?;
#[cfg(not(CRYPTOGRAPHY_IS_BORINGSSL))]
let chacha20 = types::CHACHA20.get_bound(py)?;
let rc2 = types::RC2.get_bound(py)?;
let chacha20 = types::CHACHA20.get(py)?;
let rc2 = types::RC2.get(py)?;

let cbc = types::CBC.get_bound(py)?;
let cbc = types::CBC.get(py)?;
#[cfg(not(CRYPTOGRAPHY_IS_BORINGSSL))]
let cfb = types::CFB.get_bound(py)?;
let cfb = types::CFB.get(py)?;
#[cfg(not(CRYPTOGRAPHY_IS_BORINGSSL))]
let cfb8 = types::CFB8.get_bound(py)?;
let ofb = types::OFB.get_bound(py)?;
let ecb = types::ECB.get_bound(py)?;
let ctr = types::CTR.get_bound(py)?;
let gcm = types::GCM.get_bound(py)?;
let cfb8 = types::CFB8.get(py)?;
let ofb = types::OFB.get(py)?;
let ecb = types::ECB.get(py)?;
let ctr = types::CTR.get(py)?;
let gcm = types::GCM.get(py)?;
#[cfg(not(CRYPTOGRAPHY_IS_BORINGSSL))]
let xts = types::XTS.get_bound(py)?;
let xts = types::XTS.get(py)?;

let none = py.None();
let none_type = none.bind(py).get_type();
Expand Down Expand Up @@ -265,7 +265,7 @@ fn get_cipher_registry(
// this should't be necessary but OpenSSL 3 will return an EVP_CIPHER
// even when the cipher is unavailable.
if cfg!(not(CRYPTOGRAPHY_OPENSSL_300_OR_GREATER))
|| types::LEGACY_PROVIDER_LOADED.get_bound(py)?.is_truthy()?
|| types::LEGACY_PROVIDER_LOADED.get(py)?.is_truthy()?
{
#[cfg(not(CRYPTOGRAPHY_OSSLCONF = "OPENSSL_NO_BF"))]
{
Expand Down
63 changes: 29 additions & 34 deletions src/rust/src/backend/ciphers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@ impl CipherContext {
}
};

let iv_nonce =
if mode.is_instance(&types::MODE_WITH_INITIALIZATION_VECTOR.get_bound(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "initialization_vector"))?
.extract::<CffiBuf<'_>>()?,
)
} else if mode.is_instance(&types::MODE_WITH_TWEAK.get_bound(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "tweak"))?
.extract::<CffiBuf<'_>>()?,
)
} else if mode.is_instance(&types::MODE_WITH_NONCE.get_bound(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "nonce"))?
.extract::<CffiBuf<'_>>()?,
)
} else if algorithm.is_instance(&types::CHACHA20.get_bound(py)?)? {
Some(
algorithm
.getattr(pyo3::intern!(py, "nonce"))?
.extract::<CffiBuf<'_>>()?,
)
} else {
None
};
let iv_nonce = if mode.is_instance(&types::MODE_WITH_INITIALIZATION_VECTOR.get(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "initialization_vector"))?
.extract::<CffiBuf<'_>>()?,
)
} else if mode.is_instance(&types::MODE_WITH_TWEAK.get(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "tweak"))?
.extract::<CffiBuf<'_>>()?,
)
} else if mode.is_instance(&types::MODE_WITH_NONCE.get(py)?)? {
Some(
mode.getattr(pyo3::intern!(py, "nonce"))?
.extract::<CffiBuf<'_>>()?,
)
} else if algorithm.is_instance(&types::CHACHA20.get(py)?)? {
Some(
algorithm
.getattr(pyo3::intern!(py, "nonce"))?
.extract::<CffiBuf<'_>>()?,
)
} else {
None
};

let key = algorithm
.getattr(pyo3::intern!(py, "key"))?
Expand All @@ -88,7 +87,7 @@ impl CipherContext {
}
}

if mode.is_instance(&types::XTS.get_bound(py)?)? {
if mode.is_instance(&types::XTS.get(py)?)? {
init_op(
&mut ctx,
None,
Expand Down Expand Up @@ -146,11 +145,7 @@ impl CipherContext {
for chunk in buf.chunks(1 << 29) {
// SAFETY: We ensure that outbuf is sufficiently large above.
unsafe {
let n = if self
.py_mode
.bind(py)
.is_instance(&types::XTS.get_bound(py)?)?
{
let n = if self.py_mode.bind(py).is_instance(&types::XTS.get(py)?)? {
self.ctx.cipher_update_unchecked(chunk, Some(&mut out_buf[total_written..])).map_err(|_| {
pyo3::exceptions::PyValueError::new_err(
"In XTS mode you must supply at least a full block in the first update call. For AES this is 16 bytes."
Expand Down Expand Up @@ -182,7 +177,7 @@ impl CipherContext {
&& self
.py_mode
.bind(py)
.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get_bound(py)?)?
.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get(py)?)?
{
return Err(CryptographyError::from(exceptions::InvalidTag::new_err(())));
}
Expand Down Expand Up @@ -483,7 +478,7 @@ fn create_encryption_ctx(
) -> CryptographyResult<pyo3::PyObject> {
let ctx = CipherContext::new(py, algorithm, mode.clone(), openssl::symm::Mode::Encrypt)?;

if mode.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get_bound(py)?)? {
if mode.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get(py)?)? {
Ok(PyAEADEncryptionContext {
ctx: Some(ctx),
tag: None,
Expand All @@ -509,7 +504,7 @@ fn create_decryption_ctx(
) -> CryptographyResult<pyo3::PyObject> {
let mut ctx = CipherContext::new(py, algorithm, mode.clone(), openssl::symm::Mode::Decrypt)?;

if mode.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get_bound(py)?)? {
if mode.is_instance(&types::MODE_WITH_AUTHENTICATION_TAG.get(py)?)? {
if let Some(tag) = mode
.getattr(pyo3::intern!(py, "tag"))?
.extract::<Option<pyo3::pybacked::PyBackedBytes>>()?
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/backend/cmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ impl Cmac {
) -> CryptographyResult<Self> {
let _ = backend;

if !algorithm.is_instance(&types::BLOCK_CIPHER_ALGORITHM.get_bound(py)?)? {
if !algorithm.is_instance(&types::BLOCK_CIPHER_ALGORITHM.get(py)?)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyTypeError::new_err(
"Expected instance of BlockCipherAlgorithm.",
),
));
}

let cipher = cipher_registry::get_cipher(py, algorithm.clone(), types::CBC.get_bound(py)?)?
let cipher = cipher_registry::get_cipher(py, algorithm.clone(), types::CBC.get(py)?)?
.ok_or_else(|| {
exceptions::UnsupportedAlgorithm::new_err((
"CMAC is not supported with this algorithm",
Expand Down
6 changes: 3 additions & 3 deletions src/rust/src/backend/dh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl DHPrivateKey {
format: &pyo3::Bound<'p, pyo3::PyAny>,
encryption_algorithm: &pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if !format.is(&types::PRIVATE_FORMAT_PKCS8.get_bound(py)?) {
if !format.is(&types::PRIVATE_FORMAT_PKCS8.get(py)?) {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err(
"DH private keys support only PKCS8 serialization",
Expand Down Expand Up @@ -263,7 +263,7 @@ impl DHPublicKey {
encoding: &pyo3::Bound<'p, pyo3::PyAny>,
format: &pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if !format.is(&types::PUBLIC_FORMAT_SUBJECT_PUBLIC_KEY_INFO.get_bound(py)?) {
if !format.is(&types::PUBLIC_FORMAT_SUBJECT_PUBLIC_KEY_INFO.get(py)?) {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err(
"DH public keys support only SubjectPublicKeyInfo serialization",
Expand Down Expand Up @@ -345,7 +345,7 @@ impl DHParameters {
encoding: pyo3::Bound<'p, pyo3::PyAny>,
format: pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if !format.is(&types::PARAMETER_FORMAT_PKCS3.get_bound(py)?) {
if !format.is(&types::PARAMETER_FORMAT_PKCS3.get(py)?) {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("Only PKCS3 serialization is supported"),
));
Expand Down
14 changes: 7 additions & 7 deletions src/rust/src/backend/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn curve_from_py_curve(
py_curve: pyo3::Bound<'_, pyo3::PyAny>,
allow_curve_class: bool,
) -> CryptographyResult<openssl::ec::EcGroup> {
if !py_curve.is_instance(&types::ELLIPTIC_CURVE.get_bound(py)?)? {
if !py_curve.is_instance(&types::ELLIPTIC_CURVE.get(py)?)? {
if allow_curve_class {
let warning_cls = types::DEPRECATED_IN_42.get_bound(py)?;
let warning_cls = types::DEPRECATED_IN_42.get(py)?;
let warning_msg = "Curve argument must be an instance of an EllipticCurve class. Did you pass a class by mistake? This will be an exception in a future version of cryptography.";
pyo3::PyErr::warn_bound(py, &warning_cls, warning_msg, 1)?;
} else {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn py_curve_from_curve<'p>(
let name = curve.curve_name().unwrap().short_name()?;

types::CURVE_TYPES
.get_bound(py)?
.get(py)?
.extract::<pyo3::Bound<'_, pyo3::types::PyDict>>()?
.get_item(name)?
.ok_or_else(|| {
Expand Down Expand Up @@ -231,7 +231,7 @@ impl ECPrivateKey {
algorithm: pyo3::Bound<'_, pyo3::PyAny>,
peer_public_key: &ECPublicKey,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if !algorithm.is_instance(&types::ECDH.get_bound(py)?)? {
if !algorithm.is_instance(&types::ECDH.get(py)?)? {
return Err(CryptographyError::from(
exceptions::UnsupportedAlgorithm::new_err((
"Unsupported EC exchange algorithm",
Expand Down Expand Up @@ -270,7 +270,7 @@ impl ECPrivateKey {
data: CffiBuf<'_>,
signature_algorithm: pyo3::Bound<'_, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
if !signature_algorithm.is_instance(&types::ECDSA.get_bound(py)?)? {
if !signature_algorithm.is_instance(&types::ECDSA.get(py)?)? {
return Err(CryptographyError::from(
exceptions::UnsupportedAlgorithm::new_err((
"Unsupported elliptic curve signature algorithm",
Expand Down Expand Up @@ -391,7 +391,7 @@ impl ECPublicKey {
data: CffiBuf<'_>,
signature_algorithm: pyo3::Bound<'_, pyo3::PyAny>,
) -> CryptographyResult<()> {
if !signature_algorithm.is_instance(&types::ECDSA.get_bound(py)?)? {
if !signature_algorithm.is_instance(&types::ECDSA.get(py)?)? {
return Err(CryptographyError::from(
exceptions::UnsupportedAlgorithm::new_err((
"Unsupported elliptic curve signature algorithm",
Expand Down Expand Up @@ -588,7 +588,7 @@ impl EllipticCurvePublicNumbers {
) -> CryptographyResult<EllipticCurvePublicNumbers> {
if !curve
.bind(py)
.is_instance(&types::ELLIPTIC_CURVE.get_bound(py)?)?
.is_instance(&types::ELLIPTIC_CURVE.get(py)?)?
{
return Err(CryptographyError::from(
pyo3::exceptions::PyTypeError::new_err(
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/backend/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn message_digest_from_algorithm(
py: pyo3::Python<'_>,
algorithm: &pyo3::Bound<'_, pyo3::PyAny>,
) -> CryptographyResult<openssl::hash::MessageDigest> {
if !algorithm.is_instance(&types::HASH_ALGORITHM.get_bound(py)?)? {
if !algorithm.is_instance(&types::HASH_ALGORITHM.get(py)?)? {
return Err(CryptographyError::from(
pyo3::exceptions::PyTypeError::new_err("Expected instance of hashes.HashAlgorithm."),
));
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Hash {
{
let algorithm = self.algorithm.clone_ref(py);
let algorithm = algorithm.bind(py);
if algorithm.is_instance(&types::EXTENDABLE_OUTPUT_FUNCTION.get_bound(py)?)? {
if algorithm.is_instance(&types::EXTENDABLE_OUTPUT_FUNCTION.get(py)?)? {
let ctx = self.get_mut_ctx()?;
let digest_size = algorithm
.getattr(pyo3::intern!(py, "digest_size"))?
Expand Down
Loading

0 comments on commit 8d36296

Please sign in to comment.