mirror of
https://github.com/saymrwulf/cryptography.git
synced 2026-05-14 20:37:55 +00:00
Convert some types usage to bound (#10750)
This commit is contained in:
parent
85cc4e4311
commit
b93e165615
2 changed files with 30 additions and 15 deletions
|
|
@ -532,8 +532,8 @@ impl ChaCha20Poly1305 {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>) -> CryptographyResult<&pyo3::PyAny> {
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((32,))?)
|
||||
fn generate_key(py: pyo3::Python<'_>) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((32,))?)
|
||||
}
|
||||
|
||||
fn encrypt<'p>(
|
||||
|
|
@ -638,14 +638,17 @@ impl AesGcm {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>, bit_length: usize) -> CryptographyResult<&pyo3::PyAny> {
|
||||
fn generate_key(
|
||||
py: pyo3::Python<'_>,
|
||||
bit_length: usize,
|
||||
) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
if bit_length != 128 && bit_length != 192 && bit_length != 256 {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("bit_length must be 128, 192, or 256"),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
|
||||
}
|
||||
|
||||
fn encrypt<'p>(
|
||||
|
|
@ -746,14 +749,17 @@ impl AesCcm {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>, bit_length: usize) -> CryptographyResult<&pyo3::PyAny> {
|
||||
fn generate_key(
|
||||
py: pyo3::Python<'_>,
|
||||
bit_length: usize,
|
||||
) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
if bit_length != 128 && bit_length != 192 && bit_length != 256 {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("bit_length must be 128, 192, or 256"),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
|
||||
}
|
||||
|
||||
fn encrypt<'p>(
|
||||
|
|
@ -876,14 +882,17 @@ impl AesSiv {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>, bit_length: usize) -> CryptographyResult<&pyo3::PyAny> {
|
||||
fn generate_key(
|
||||
py: pyo3::Python<'_>,
|
||||
bit_length: usize,
|
||||
) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
if bit_length != 256 && bit_length != 384 && bit_length != 512 {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("bit_length must be 256, 384, or 512"),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
|
||||
}
|
||||
|
||||
#[pyo3(signature = (data, associated_data))]
|
||||
|
|
@ -970,14 +979,17 @@ impl AesOcb3 {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>, bit_length: usize) -> CryptographyResult<&pyo3::PyAny> {
|
||||
fn generate_key(
|
||||
py: pyo3::Python<'_>,
|
||||
bit_length: usize,
|
||||
) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
if bit_length != 128 && bit_length != 192 && bit_length != 256 {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("bit_length must be 128, 192, or 256"),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
|
||||
}
|
||||
|
||||
#[pyo3(signature = (nonce, data, associated_data))]
|
||||
|
|
@ -1076,14 +1088,17 @@ impl AesGcmSiv {
|
|||
}
|
||||
|
||||
#[staticmethod]
|
||||
fn generate_key(py: pyo3::Python<'_>, bit_length: usize) -> CryptographyResult<&pyo3::PyAny> {
|
||||
fn generate_key(
|
||||
py: pyo3::Python<'_>,
|
||||
bit_length: usize,
|
||||
) -> CryptographyResult<pyo3::Bound<'_, pyo3::PyAny>> {
|
||||
if bit_length != 128 && bit_length != 192 && bit_length != 256 {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("bit_length must be 128, 192, or 256"),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(types::OS_URANDOM.get(py)?.call1((bit_length / 8,))?)
|
||||
Ok(types::OS_URANDOM.get_bound(py)?.call1((bit_length / 8,))?)
|
||||
}
|
||||
|
||||
#[pyo3(signature = (nonce, data, associated_data))]
|
||||
|
|
|
|||
|
|
@ -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(py)?) {
|
||||
if !format.is(&types::PRIVATE_FORMAT_PKCS8.get_bound(py)?) {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err(
|
||||
"DH private keys support only PKCS8 serialization",
|
||||
|
|
@ -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(py)?) {
|
||||
if !format.is(&types::PUBLIC_FORMAT_SUBJECT_PUBLIC_KEY_INFO.get_bound(py)?) {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err(
|
||||
"DH public keys support only SubjectPublicKeyInfo serialization",
|
||||
|
|
@ -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(py)?) {
|
||||
if !format.is(&types::PARAMETER_FORMAT_PKCS3.get_bound(py)?) {
|
||||
return Err(CryptographyError::from(
|
||||
pyo3::exceptions::PyValueError::new_err("Only PKCS3 serialization is supported"),
|
||||
));
|
||||
|
|
|
|||
Loading…
Reference in a new issue