Skip to content

Commit 5b8dd74

Browse files
okke-formsmaOkke Formsma
authored andcommitted
Use cryptography's non-deprecated CFB location when available
CFB moved from cryptography.hazmat.primitives.ciphers.modes to cryptography.hazmat.decrepit.ciphers.modes in cryptography 47, which is also exactly when the old location started emitting CryptographyDeprecationWarning on attribute access. Prefer the new location when it exists, falling back to the old one on cryptography < 47 where decrepit does not exist yet. This removes the warning both at import time and when AESCipher is actually used with cfb mode, for every supported cryptography version. Fixes #1033
1 parent 9e597e1 commit 5b8dd74

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/saml2/cryptography/symmetric.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
from .errors import SymmetricCryptographyError
1616

1717

18+
try:
19+
# cryptography >= 47 moved CFB here; use it to avoid CryptographyDeprecationWarning.
20+
from cryptography.hazmat.decrepit.ciphers.modes import CFB as _CFB
21+
except ImportError:
22+
# older cryptography versions don't have the "decrepit" module yet.
23+
_CFB = _ciphers.modes.CFB
24+
25+
1826
logger = logging.getLogger(__name__)
1927

2028

@@ -105,7 +113,7 @@ class AESCipher:
105113

106114
POSTFIX_MODE = {
107115
"cbc": _ciphers.modes.CBC,
108-
"cfb": _ciphers.modes.CFB,
116+
"cfb": _CFB,
109117
}
110118

111119
AES_BLOCK_SIZE = int(_ciphers.algorithms.AES.block_size / 8)

0 commit comments

Comments
 (0)