Skip to content

Commit 7735fff

Browse files
authored
Mark the majority of our Rust types as frozen (#9306)
This tells pyo3 that they are immutable, which makes them marginally cheaper. There's a handful of places where types _should_ be immutable, but aren't. For those I added `TODO` comments.
1 parent f10c821 commit 7735fff

File tree

18 files changed

+30
-20
lines changed

18 files changed

+30
-20
lines changed

src/rust/src/asn1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn encode_dss_signature(
136136
Ok(pyo3::types::PyBytes::new(py, &result).to_object(py))
137137
}
138138

139-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.asn1")]
139+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.asn1")]
140140
struct TestCertificate {
141141
#[pyo3(get)]
142142
not_before_tag: u8,

src/rust/src/backend/dh.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ use foreign_types_shared::ForeignTypeRef;
1111

1212
const MIN_MODULUS_SIZE: u32 = 512;
1313

14-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.dh")]
14+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.dh")]
1515
struct DHPrivateKey {
1616
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1717
}
1818

19-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.dh")]
19+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.dh")]
2020
struct DHPublicKey {
2121
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
2222
}
2323

24-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.dh")]
24+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.dh")]
2525
struct DHParameters {
2626
dh: openssl::dh::Dh<openssl::pkey::Params>,
2727
}

src/rust/src/backend/dsa.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::exceptions;
88
use foreign_types_shared::ForeignTypeRef;
99

1010
#[pyo3::prelude::pyclass(
11+
frozen,
1112
module = "cryptography.hazmat.bindings._rust.openssl.dsa",
1213
name = "DSAPrivateKey"
1314
)]
@@ -16,6 +17,7 @@ struct DsaPrivateKey {
1617
}
1718

1819
#[pyo3::prelude::pyclass(
20+
frozen,
1921
module = "cryptography.hazmat.bindings._rust.openssl.dsa",
2022
name = "DSAPublicKey"
2123
)]
@@ -24,6 +26,7 @@ struct DsaPublicKey {
2426
}
2527

2628
#[pyo3::prelude::pyclass(
29+
frozen,
2730
module = "cryptography.hazmat.bindings._rust.openssl.dsa",
2831
name = "DSAParameters"
2932
)]

src/rust/src/backend/ec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use foreign_types_shared::ForeignTypeRef;
99
use pyo3::basic::CompareOp;
1010
use pyo3::ToPyObject;
1111

12-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ec")]
12+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ec")]
1313
struct ECPrivateKey {
1414
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1515
#[pyo3(get)]
1616
curve: pyo3::Py<pyo3::PyAny>,
1717
}
1818

19-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ec")]
19+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ec")]
2020
struct ECPublicKey {
2121
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
2222
#[pyo3(get)]

src/rust/src/backend/ed25519.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use crate::error::{CryptographyError, CryptographyResult};
88
use crate::exceptions;
99
use foreign_types_shared::ForeignTypeRef;
1010

11-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ed25519")]
11+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ed25519")]
1212
struct Ed25519PrivateKey {
1313
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1414
}
1515

16-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ed25519")]
16+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ed25519")]
1717
struct Ed25519PublicKey {
1818
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
1919
}

src/rust/src/backend/ed448.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use crate::error::{CryptographyError, CryptographyResult};
88
use crate::exceptions;
99
use foreign_types_shared::ForeignTypeRef;
1010

11-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ed448")]
11+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ed448")]
1212
struct Ed448PrivateKey {
1313
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1414
}
1515

16-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.ed448")]
16+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.ed448")]
1717
struct Ed448PublicKey {
1818
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
1919
}

src/rust/src/backend/x25519.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::buf::CffiBuf;
77
use crate::error::CryptographyResult;
88
use foreign_types_shared::ForeignTypeRef;
99

10-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.x25519")]
10+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.x25519")]
1111
struct X25519PrivateKey {
1212
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1313
}
1414

15-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.x25519")]
15+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.x25519")]
1616
struct X25519PublicKey {
1717
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
1818
}

src/rust/src/backend/x448.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::buf::CffiBuf;
77
use crate::error::CryptographyResult;
88
use foreign_types_shared::ForeignTypeRef;
99

10-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.x448")]
10+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.x448")]
1111
struct X448PrivateKey {
1212
pkey: openssl::pkey::PKey<openssl::pkey::Private>,
1313
}
1414

15-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl.x448")]
15+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl.x448")]
1616
struct X448PublicKey {
1717
pkey: openssl::pkey::PKey<openssl::pkey::Public>,
1818
}

src/rust/src/exceptions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// for complete details.
44

55
#[pyo3::prelude::pyclass(
6+
frozen,
67
module = "cryptography.hazmat.bindings._rust.exceptions",
78
name = "_Reasons"
89
)]

src/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn raise_openssl_error() -> crate::error::CryptographyResult<()> {
8585
Err(openssl::error::ErrorStack::get().into())
8686
}
8787

88-
#[pyo3::prelude::pyclass(module = "cryptography.hazmat.bindings._rust.openssl")]
88+
#[pyo3::prelude::pyclass(frozen, module = "cryptography.hazmat.bindings._rust.openssl")]
8989
struct OpenSSLError {
9090
e: openssl::error::Error,
9191
}

0 commit comments

Comments
 (0)