tomato42/tlslite-ng

View on GitHub
tlslite/utils/pycrypto_aes.py

Summary

Maintainability
C
1 day
Test Coverage
A
100%
Similar blocks of code found in 2 locations. Consider refactoring.
# Author: Trevor Perrin
Similar blocks of code found in 2 locations. Consider refactoring.
# See the LICENSE file for legal information regarding use of this file.
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
"""PyCrypto AES implementation."""
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
from .cryptomath import *
Similar blocks of code found in 2 locations. Consider refactoring.
from .aes import *
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
if pycryptoLoaded:
Similar blocks of code found in 2 locations. Consider refactoring.
import Crypto.Cipher.AES
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def new(key, mode, IV):
Similar blocks of code found in 2 locations. Consider refactoring.
return PyCrypto_AES(key, mode, IV)
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
class PyCrypto_AES(AES):
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def __init__(self, key, mode, IV):
Similar blocks of code found in 2 locations. Consider refactoring.
AES.__init__(self, key, mode, IV, "pycrypto")
Similar blocks of code found in 2 locations. Consider refactoring.
key = bytes(key)
Similar blocks of code found in 2 locations. Consider refactoring.
IV = bytes(IV)
Similar blocks of code found in 2 locations. Consider refactoring.
self.context = Crypto.Cipher.AES.new(key, mode, IV)
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def encrypt(self, plaintext):
Similar blocks of code found in 2 locations. Consider refactoring.
plaintext = bytes(plaintext)
Similar blocks of code found in 2 locations. Consider refactoring.
return bytearray(self.context.encrypt(plaintext))
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def decrypt(self, ciphertext):
Similar blocks of code found in 2 locations. Consider refactoring.
ciphertext = bytes(ciphertext)
Similar blocks of code found in 2 locations. Consider refactoring.
return bytearray(self.context.decrypt(ciphertext))