Skip to content

Commit

Permalink
crypto: low_level: reduce class inheritance depth
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Mar 22, 2022
1 parent f30c3b2 commit 2b05541
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/borg/crypto/low_level.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -598,19 +598,7 @@ cdef class _AEAD_BASE:
return iv + 1


cdef class _AES_BASE(_AEAD_BASE):
def __init__(self, *args, **kwargs):
self.cipher_blk_len = 16
super().__init__(*args, **kwargs)


cdef class _CHACHA_BASE(_AEAD_BASE):
def __init__(self, *args, **kwargs):
self.cipher_blk_len = 64
super().__init__(*args, **kwargs)


cdef class AES256_OCB(_AES_BASE):
cdef class AES256_OCB(_AEAD_BASE):
@classmethod
def requirements_check(cls):
if is_libressl:
Expand All @@ -619,10 +607,11 @@ cdef class AES256_OCB(_AES_BASE):
def __init__(self, key, iv=None, header_len=0, aad_offset=0):
self.requirements_check()
self.cipher = EVP_aes_256_ocb
self.cipher_blk_len = 16
super().__init__(key, iv=iv, header_len=header_len, aad_offset=aad_offset)


cdef class CHACHA20_POLY1305(_CHACHA_BASE):
cdef class CHACHA20_POLY1305(_AEAD_BASE):
@classmethod
def requirements_check(cls):
if is_libressl:
Expand All @@ -631,6 +620,7 @@ cdef class CHACHA20_POLY1305(_CHACHA_BASE):
def __init__(self, key, iv=None, header_len=0, aad_offset=0):
self.requirements_check()
self.cipher = EVP_chacha20_poly1305
self.cipher_blk_len = 64
super().__init__(key, iv=iv, header_len=header_len, aad_offset=aad_offset)


Expand Down Expand Up @@ -735,7 +725,6 @@ cdef class AES:
return iv + self.blocks



def hmac_sha256(key, data):
return hmac.digest(key, data, 'sha256')

Expand Down

0 comments on commit 2b05541

Please sign in to comment.