Skip to content

Commit 61d4c0a

Browse files
committed
Convert symmetric ciphers to Rust
1 parent 2c9e705 commit 61d4c0a

File tree

17 files changed

+882
-535
lines changed

17 files changed

+882
-535
lines changed

src/cryptography/hazmat/backends/openssl/backend.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from cryptography import utils, x509
1313
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
1414
from cryptography.hazmat.backends.openssl import aead
15-
from cryptography.hazmat.backends.openssl.ciphers import _CipherContext
1615
from cryptography.hazmat.bindings._rust import openssl as rust_openssl
1716
from cryptography.hazmat.bindings.openssl import binding
1817
from cryptography.hazmat.primitives import hashes, serialization
@@ -142,12 +141,8 @@ def __repr__(self) -> str:
142141
self._binding._legacy_provider_loaded,
143142
)
144143

145-
def openssl_assert(
146-
self,
147-
ok: bool,
148-
errors: list[rust_openssl.OpenSSLError] | None = None,
149-
) -> None:
150-
return binding._openssl_assert(ok, errors=errors)
144+
def openssl_assert(self, ok: bool) -> None:
145+
return binding._openssl_assert(ok)
151146

152147
def _enable_fips(self) -> None:
153148
# This function enables FIPS mode for OpenSSL 3.0.0 on installs that
@@ -310,16 +305,6 @@ def _register_default_ciphers(self) -> None:
310305
_RC2, type(None), GetCipherByName("rc2")
311306
)
312307

313-
def create_symmetric_encryption_ctx(
314-
self, cipher: CipherAlgorithm, mode: Mode
315-
) -> _CipherContext:
316-
return _CipherContext(self, cipher, mode, _CipherContext._ENCRYPT)
317-
318-
def create_symmetric_decryption_ctx(
319-
self, cipher: CipherAlgorithm, mode: Mode
320-
) -> _CipherContext:
321-
return _CipherContext(self, cipher, mode, _CipherContext._DECRYPT)
322-
323308
def pbkdf2_hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
324309
return self.hmac_supported(algorithm)
325310

src/cryptography/hazmat/backends/openssl/ciphers.py

Lines changed: 0 additions & 282 deletions
This file was deleted.

src/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import typing
66

77
from cryptography.hazmat.bindings._rust.openssl import (
88
aead,
9+
ciphers,
910
cmac,
1011
dh,
1112
dsa,
@@ -26,6 +27,7 @@ __all__ = [
2627
"openssl_version",
2728
"raise_openssl_error",
2829
"aead",
30+
"ciphers",
2931
"cmac",
3032
"dh",
3133
"dsa",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This file is dual licensed under the terms of the Apache License, Version
2+
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3+
# for complete details.
4+
5+
import typing
6+
7+
from cryptography.hazmat.primitives import ciphers
8+
from cryptography.hazmat.primitives.ciphers import modes
9+
10+
@typing.overload
11+
def create_encryption_ctx(
12+
algorithm: ciphers.CipherAlgorithm, mode: modes.ModeWithAuthenticationTag
13+
) -> ciphers.AEADEncryptionContext: ...
14+
@typing.overload
15+
def create_encryption_ctx(
16+
algorithm: ciphers.CipherAlgorithm, mode: modes.Mode
17+
) -> ciphers.CipherContext: ...
18+
@typing.overload
19+
def create_decryption_ctx(
20+
algorithm: ciphers.CipherAlgorithm, mode: modes.ModeWithAuthenticationTag
21+
) -> ciphers.AEADDecryptionContext: ...
22+
@typing.overload
23+
def create_decryption_ctx(
24+
algorithm: ciphers.CipherAlgorithm, mode: modes.Mode
25+
) -> ciphers.CipherContext: ...
26+
def _advance(
27+
ctx: ciphers.AEADEncryptionContext | ciphers.AEADDecryptionContext, n: int
28+
) -> None: ...
29+
def _advance_aad(
30+
ctx: ciphers.AEADEncryptionContext | ciphers.AEADDecryptionContext, n: int
31+
) -> None: ...
32+
33+
class CipherContext: ...
34+
class AEADEncryptionContext: ...
35+
class AEADDecryptionContext: ...

src/cryptography/hazmat/bindings/openssl/binding.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
from cryptography.hazmat.bindings.openssl._conditional import CONDITIONAL_NAMES
1818

1919

20-
def _openssl_assert(
21-
ok: bool,
22-
errors: list[openssl.OpenSSLError] | None = None,
23-
) -> None:
20+
def _openssl_assert(ok: bool) -> None:
2421
if not ok:
25-
if errors is None:
26-
errors = openssl.capture_error_stack()
22+
errors = openssl.capture_error_stack()
2723

2824
raise InternalError(
2925
"Unknown OpenSSL error. This error is commonly encountered when "

0 commit comments

Comments
 (0)