Skip to content

Commit

Permalink
Remove various pointless borrows (#12026)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Nov 24, 2024
1 parent d3403c0 commit 050b656
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ mod tests {
critical: bool,
ext: &T,
) -> Vec<u8> {
let ext_value = asn1::write_single(&ext).unwrap();
let ext_value = asn1::write_single(ext).unwrap();
let ext = Extension {
extn_id: oid,
critical,
Expand Down
6 changes: 3 additions & 3 deletions src/rust/cryptography-x509-verification/src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ mod tests {
assert!(WEBPKI_PERMITTED_SIGNATURE_ALGORITHMS.contains(&RSASSA_PSS_SHA256.deref()));
let exp_encoding = b"0A\x06\t*\x86H\x86\xf7\r\x01\x01\n04\xa0\x0f0\r\x06\t`\x86H\x01e\x03\x04\x02\x01\x05\x00\xa1\x1c0\x1a\x06\t*\x86H\x86\xf7\r\x01\x01\x080\r\x06\t`\x86H\x01e\x03\x04\x02\x01\x05\x00\xa2\x03\x02\x01 ";
assert_eq!(
asn1::write_single(&RSASSA_PSS_SHA256.deref()).unwrap(),
asn1::write_single(RSASSA_PSS_SHA256.deref()).unwrap(),
exp_encoding
);
}
Expand All @@ -689,7 +689,7 @@ mod tests {
assert!(WEBPKI_PERMITTED_SIGNATURE_ALGORITHMS.contains(&RSASSA_PSS_SHA384.deref()));
let exp_encoding = b"0A\x06\t*\x86H\x86\xf7\r\x01\x01\n04\xa0\x0f0\r\x06\t`\x86H\x01e\x03\x04\x02\x02\x05\x00\xa1\x1c0\x1a\x06\t*\x86H\x86\xf7\r\x01\x01\x080\r\x06\t`\x86H\x01e\x03\x04\x02\x02\x05\x00\xa2\x03\x02\x010";
assert_eq!(
asn1::write_single(&RSASSA_PSS_SHA384.deref()).unwrap(),
asn1::write_single(RSASSA_PSS_SHA384.deref()).unwrap(),
exp_encoding
);
}
Expand All @@ -698,7 +698,7 @@ mod tests {
assert!(WEBPKI_PERMITTED_SIGNATURE_ALGORITHMS.contains(&RSASSA_PSS_SHA512.deref()));
let exp_encoding = b"0A\x06\t*\x86H\x86\xf7\r\x01\x01\n04\xa0\x0f0\r\x06\t`\x86H\x01e\x03\x04\x02\x03\x05\x00\xa1\x1c0\x1a\x06\t*\x86H\x86\xf7\r\x01\x01\x080\r\x06\t`\x86H\x01e\x03\x04\x02\x03\x05\x00\xa2\x03\x02\x01@";
assert_eq!(
asn1::write_single(&RSASSA_PSS_SHA512.deref()).unwrap(),
asn1::write_single(RSASSA_PSS_SHA512.deref()).unwrap(),
exp_encoding
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/rust/src/pkcs7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ fn sign_and_serialize<'p>(
// Subset of values OpenSSL provides:
// https://github.com/openssl/openssl/blob/667a8501f0b6e5705fd611d5bb3ca24848b07154/crypto/pkcs7/pk7_smime.c#L150
// removing all the ones that are bad cryptography
&asn1::SequenceOfWriter::new([oid::AES_256_CBC_OID]),
&asn1::SequenceOfWriter::new([oid::AES_192_CBC_OID]),
&asn1::SequenceOfWriter::new([oid::AES_128_CBC_OID]),
asn1::SequenceOfWriter::new([oid::AES_256_CBC_OID]),
asn1::SequenceOfWriter::new([oid::AES_192_CBC_OID]),
asn1::SequenceOfWriter::new([oid::AES_128_CBC_OID]),
]))?;

#[allow(clippy::type_complexity)]
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/x509/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Certificate {
py: pyo3::Python<'p>,
algorithm: &pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let serialized = asn1::write_single(&self.raw.borrow_dependent())?;
let serialized = asn1::write_single(self.raw.borrow_dependent())?;

let mut h = hashes::Hash::new(py, algorithm, None)?;
h.update_bytes(&serialized)?;
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/x509/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) struct CertificateRevocationList {

impl CertificateRevocationList {
fn public_bytes_der(&self) -> CryptographyResult<Vec<u8>> {
Ok(asn1::write_single(&self.owned.borrow_dependent())?)
Ok(asn1::write_single(self.owned.borrow_dependent())?)
}

fn revoked_cert(&self, py: pyo3::Python<'_>, idx: usize) -> RevokedCertificate {
Expand Down Expand Up @@ -239,7 +239,7 @@ impl CertificateRevocationList {
py: pyo3::Python<'p>,
encoding: pyo3::Bound<'p, pyo3::PyAny>,
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
let result = asn1::write_single(&self.owned.borrow_dependent())?;
let result = asn1::write_single(self.owned.borrow_dependent())?;

encode_der_data(py, "X509 CRL".to_string(), result, &encoding)
}
Expand Down

0 comments on commit 050b656

Please sign in to comment.