summaryrefslogtreecommitdiff
path: root/lib/Crypto/Util
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 10:55:06 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 18:32:04 -0700
commitb6ad2b47d9b7f3799c29097b4324dff2540fe77d (patch)
treeadd26f4b539dadecb45f21e265f04c827db195db /lib/Crypto/Util
parent0ee73a1b571f540cfca8d656853f2bc3df2e3767 (diff)
downloadpycrypto-b6ad2b47d9b7f3799c29097b4324dff2540fe77d.tar.gz
Counter: Deprecate disable_shortcut; Remove __PCT_CTR_SHORTCUT__ entirely
The `disable_shortcut` option served as a workaround in case `__PCT_CTR_SHORTCUT__` leaked through a wrapper object, but I don't think anyone actually used it, and it was a bad idea to expose it as part of the public API. Now that we do strong type checking inside block_template.c, there shoujld be no need to ever use this option. It's now a no-op, retained for backward compatibility only. It will be removed in some future version of PyCrypto.
Diffstat (limited to 'lib/Crypto/Util')
-rw-r--r--lib/Crypto/Util/Counter.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/Crypto/Util/Counter.py b/lib/Crypto/Util/Counter.py
index 60e281c..2068fb3 100644
--- a/lib/Crypto/Util/Counter.py
+++ b/lib/Crypto/Util/Counter.py
@@ -57,11 +57,15 @@ if sys.version_info[0] == 2 and sys.version_info[1] == 1:
from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
+from Crypto.pct_warnings import DisableShortcut_DeprecationWarning
from Crypto.Util import _counter
import struct
+import warnings
+
# Factory function
-def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_endian=False, allow_wraparound=False, disable_shortcut=False):
+_deprecated = "deprecated"
+def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_endian=False, allow_wraparound=False, disable_shortcut=_deprecated):
"""Create a stateful counter block function suitable for CTR encryption modes.
Each call to the function returns the next counter block.
@@ -89,10 +93,9 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
If True, the function will raise an *OverflowError* exception as soon
as the counter wraps around. If False (default), the counter will
simply restart from zero.
- disable_shortcut : boolean
- If True, do not make ciphers from `Crypto.Cipher` bypass the Python
- layer when invoking the counter block function.
- If False (default), bypass the Python layer.
+ disable_shortcut : deprecated
+ This option is a no-op for backward compatibility. It will be removed
+ in a future version. Don't use it.
:Returns:
The counter block function.
"""
@@ -109,10 +112,13 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
initval = _encode(initial_value, nbytes, little_endian)
+ if disable_shortcut is not _deprecated: # exact object comparison
+ warnings.warn("disable_shortcut has no effect and is deprecated", DisableShortcut_DeprecationWarning)
+
if little_endian:
- return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
+ return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound)
else:
- return _counter._newBE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
+ return _counter._newBE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound)
def _encode(n, nbytes, little_endian=False):
retval = []