Skip to content
Snippets Groups Projects
Commit 8510cbbf authored by Pierre Lalet's avatar Pierre Lalet Committed by GitHub
Browse files

Merge pull request #772 from gpotter2/py3-set3-3

[Python 2 to 3] Fix Exception format
parents a90aeb6b f8fe525f
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ class AnsweringMachine(six.with_metaclass(ReferenceAM, object)): ...@@ -55,7 +55,7 @@ class AnsweringMachine(six.with_metaclass(ReferenceAM, object)):
for d in [self.optam2, self.optam1]: for d in [self.optam2, self.optam1]:
if attr in d: if attr in d:
return d[attr] return d[attr]
raise AttributeError,attr raise AttributeError(attr)
def __setattr__(self, attr, val): def __setattr__(self, attr, val):
mode = self.__dict__.get("mode",0) mode = self.__dict__.get("mode",0)
......
...@@ -136,7 +136,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)): ...@@ -136,7 +136,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)):
actually is a _AEADCipher_TLS13 (even though others are not). actually is a _AEADCipher_TLS13 (even though others are not).
""" """
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, (P, A) raise CipherError(P, A)
if hasattr(self, "pc_cls"): if hasattr(self, "pc_cls"):
self._cipher.mode._initialization_vector = self._get_nonce() self._cipher.mode._initialization_vector = self._get_nonce()
...@@ -180,7 +180,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)): ...@@ -180,7 +180,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)):
C[-self.tag_len:]) C[-self.tag_len:])
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, (nonce_explicit_str, C, mac) raise CipherError(nonce_explicit_str, C, mac)
self.nonce_explicit = pkcs_os2ip(nonce_explicit_str) self.nonce_explicit = pkcs_os2ip(nonce_explicit_str)
if add_length: if add_length:
...@@ -195,7 +195,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)): ...@@ -195,7 +195,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)):
try: try:
decryptor.finalize() decryptor.finalize()
except InvalidTag: except InvalidTag:
raise AEADTagError, (nonce_explicit_str, P, mac) raise AEADTagError(nonce_explicit_str, P, mac)
else: else:
try: try:
if isinstance(self._cipher, AESCCM): if isinstance(self._cipher, AESCCM):
...@@ -204,7 +204,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)): ...@@ -204,7 +204,7 @@ class _AEADCipher(six.with_metaclass(_AEADCipherMetaclass, object)):
else: else:
P = self._cipher.decrypt(self._get_nonce(), C + mac, A) P = self._cipher.decrypt(self._get_nonce(), C + mac, A)
except InvalidTag: except InvalidTag:
raise AEADTagError, (nonce_explicit_str, raise AEADTagError(nonce_explicit_str,
"<unauthenticated data>", "<unauthenticated data>",
mac) mac)
return nonce_explicit_str, P, mac return nonce_explicit_str, P, mac
...@@ -308,7 +308,7 @@ class _AEADCipher_TLS13(object): ...@@ -308,7 +308,7 @@ class _AEADCipher_TLS13(object):
Note that the cipher's authentication tag must be None when encrypting. Note that the cipher's authentication tag must be None when encrypting.
""" """
if False in self.ready.itervalues(): if False in self.ready.itervalues():
raise CipherError, (P, A) raise CipherError(P, A)
if hasattr(self, "pc_cls"): if hasattr(self, "pc_cls"):
self._cipher.mode._tag = None self._cipher.mode._tag = None
...@@ -336,7 +336,7 @@ class _AEADCipher_TLS13(object): ...@@ -336,7 +336,7 @@ class _AEADCipher_TLS13(object):
""" """
C, mac = C[:-self.tag_len], C[-self.tag_len:] C, mac = C[:-self.tag_len], C[-self.tag_len:]
if False in self.ready.itervalues(): if False in self.ready.itervalues():
raise CipherError, (C, mac) raise CipherError(C, mac)
if hasattr(self, "pc_cls"): if hasattr(self, "pc_cls"):
self._cipher.mode._initialization_vector = self._get_nonce(seq_num) self._cipher.mode._initialization_vector = self._get_nonce(seq_num)
...@@ -347,7 +347,7 @@ class _AEADCipher_TLS13(object): ...@@ -347,7 +347,7 @@ class _AEADCipher_TLS13(object):
try: try:
decryptor.finalize() decryptor.finalize()
except InvalidTag: except InvalidTag:
raise AEADTagError, (P, mac) raise AEADTagError(P, mac)
else: else:
try: try:
if (conf.crypto_valid_advanced and if (conf.crypto_valid_advanced and
...@@ -360,7 +360,7 @@ class _AEADCipher_TLS13(object): ...@@ -360,7 +360,7 @@ class _AEADCipher_TLS13(object):
A += struct.pack("!H", len(C)) A += struct.pack("!H", len(C))
P = self._cipher.decrypt(self._get_nonce(seq_num), C + mac, A) P = self._cipher.decrypt(self._get_nonce(seq_num), C + mac, A)
except InvalidTag: except InvalidTag:
raise AEADTagError, ("<unauthenticated data>", mac) raise AEADTagError("<unauthenticated data>", mac)
return P, mac return P, mac
def snapshot(self): def snapshot(self):
......
...@@ -81,7 +81,7 @@ class _BlockCipher(six.with_metaclass(_BlockCipherMetaclass, object)): ...@@ -81,7 +81,7 @@ class _BlockCipher(six.with_metaclass(_BlockCipherMetaclass, object)):
and TLS 1.0. For TLS 1.1/1.2, it is overwritten in TLS.post_build(). and TLS 1.0. For TLS 1.1/1.2, it is overwritten in TLS.post_build().
""" """
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, data raise CipherError(data)
encryptor = self._cipher.encryptor() encryptor = self._cipher.encryptor()
tmp = encryptor.update(data) + encryptor.finalize() tmp = encryptor.update(data) + encryptor.finalize()
self.iv = tmp[-self.block_size:] self.iv = tmp[-self.block_size:]
...@@ -94,7 +94,7 @@ class _BlockCipher(six.with_metaclass(_BlockCipherMetaclass, object)): ...@@ -94,7 +94,7 @@ class _BlockCipher(six.with_metaclass(_BlockCipherMetaclass, object)):
If we lack the key, we raise a CipherError which contains the input. If we lack the key, we raise a CipherError which contains the input.
""" """
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, data raise CipherError(data)
decryptor = self._cipher.decryptor() decryptor = self._cipher.decryptor()
tmp = decryptor.update(data) + decryptor.finalize() tmp = decryptor.update(data) + decryptor.finalize()
self.iv = data[-self.block_size:] self.iv = data[-self.block_size:]
......
...@@ -82,13 +82,13 @@ class _StreamCipher(six.with_metaclass(_StreamCipherMetaclass, object)): ...@@ -82,13 +82,13 @@ class _StreamCipher(six.with_metaclass(_StreamCipherMetaclass, object)):
def encrypt(self, data): def encrypt(self, data):
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, data raise CipherError(data)
self._enc_updated_with += data self._enc_updated_with += data
return self.encryptor.update(data) return self.encryptor.update(data)
def decrypt(self, data): def decrypt(self, data):
if False in six.itervalues(self.ready): if False in six.itervalues(self.ready):
raise CipherError, data raise CipherError(data)
self._dec_updated_with += data self._dec_updated_with += data
return self.decryptor.update(data) return self.decryptor.update(data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment