Skip to content

Commit 6dcdd74

Browse files
committed
Convert symmetric ciphers to Rust
1 parent 4c5d2a4 commit 6dcdd74

File tree

19 files changed

+828
-573
lines changed

19 files changed

+828
-573
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
@@ -145,12 +144,8 @@ def __repr__(self) -> str:
145144
self._binding._legacy_provider_loaded,
146145
)
147146

148-
def openssl_assert(
149-
self,
150-
ok: bool,
151-
errors: list[rust_openssl.OpenSSLError] | None = None,
152-
) -> None:
153-
return binding._openssl_assert(self._lib, ok, errors=errors)
147+
def openssl_assert(self, ok: bool) -> None:
148+
return binding._openssl_assert(ok)
154149

155150
def _enable_fips(self) -> None:
156151
# This function enables FIPS mode for OpenSSL 3.0.0 on installs that
@@ -313,16 +308,6 @@ def _register_default_ciphers(self) -> None:
313308
_RC2, type(None), GetCipherByName("rc2")
314309
)
315310

316-
def create_symmetric_encryption_ctx(
317-
self, cipher: CipherAlgorithm, mode: Mode
318-
) -> _CipherContext:
319-
return _CipherContext(self, cipher, mode, _CipherContext._ENCRYPT)
320-
321-
def create_symmetric_decryption_ctx(
322-
self, cipher: CipherAlgorithm, mode: Mode
323-
) -> _CipherContext:
324-
return _CipherContext(self, cipher, mode, _CipherContext._DECRYPT)
325-
326311
def pbkdf2_hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
327312
return self.hmac_supported(algorithm)
328313

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: ...

0 commit comments

Comments
 (0)