Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class DESCFBCipher(BaseCipher):
KEY_LENGTH = 8
IV_LENGTH = 8
def setup(self):
self.cipher = DES.new(self.key, DES.MODE_CFB, iv=self.iv, segment_size=64)
MAPPINGS = {\
'table': TableCipher,
'rc4': RC4Cipher,
'rc4-md5': RC4MD5Cipher,
'chacha20': ChaCha20Cipher,
'salsa20': Salsa20Cipher,
'aes-128-cfb': AES128CFBCipher,
'aes-192-cfb': AES192CFBCipher,
'aes-256-cfb': AES256CFBCipher,
'bf-cfb': BFCFBCipher,
'cast5-cfb': CAST5CFBCipher,
'des-cfb': DESCFBCipher,
}
def get_cipher(cipher_key):
cipher, _, key = cipher_key.partition(':')
cipher, ota, _ = cipher.partition('!')
if not key:
raise argparse.ArgumentTypeError('empty key')
if cipher not in MAPPINGS:
raise argparse.ArgumentTypeError(f'existing ciphers: {list(MAPPINGS.keys())}')
cipher, key, ota = MAPPINGS[cipher], key.encode(), bool(ota) if ota else False
def apply_cipher(reader, writer):
reader_cipher, writer_cipher = cipher(key, ota=ota), cipher(key, ota=ota)
def feed_data(s, o=reader.feed_data):
def setup(self):
self.cipher = ChaCha20.new(key=self.key, nonce=self.iv)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
class CAST5CFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = CAST.new(self.key, CAST.MODE_CFB, iv=self.iv, segment_size=64)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
class CAST5CFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = CAST.new(self.key, CAST.MODE_CFB, iv=self.iv, segment_size=64)
class DESCFBCipher(BaseCipher):
KEY_LENGTH = 8