Skip to content

Commit

Permalink
crypto: key: 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 2b05541 commit 5d38251
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
20 changes: 3 additions & 17 deletions src/borg/crypto/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ def init_ciphers(self, manifest_data=None):
self.nonce_manager = NonceManager(self.repository, nonce)


class FlexiKeyBase:
class FlexiKey:
FILE_ID = 'BORG_KEY'

@classmethod
def detect(cls, repository, manifest_data):
key = cls(repository)
Expand All @@ -406,12 +408,6 @@ def detect(cls, repository, manifest_data):
key._passphrase = passphrase
return key

def find_key(self):
raise NotImplementedError

def load(self, target, passphrase):
raise NotImplementedError

def _load(self, key_data, passphrase):
cdata = a2b_base64(key_data)
data = self.decrypt_key_file(cdata, passphrase)
Expand Down Expand Up @@ -489,16 +485,6 @@ def create(cls, repository, args):
logger.info('Keep this key safe. Your data will be inaccessible without it.')
return key

def save(self, target, passphrase, create=False):
raise NotImplementedError

def get_new_target(self, args):
raise NotImplementedError


class FlexiKey(FlexiKeyBase):
FILE_ID = 'BORG_KEY'

def sanity_check(self, filename, id):
file_id = self.FILE_ID.encode() + b' '
repo_id = hexlify(id)
Expand Down
4 changes: 2 additions & 2 deletions src/borg/testsuite/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ..chunker import has_seek_hole
from ..constants import * # NOQA
from ..crypto.low_level import bytes_to_long, num_cipher_blocks
from ..crypto.key import FlexiKeyBase, RepoKey, KeyfileKey, Passphrase, TAMRequiredError
from ..crypto.key import FlexiKey, RepoKey, KeyfileKey, Passphrase, TAMRequiredError
from ..crypto.keymanager import RepoIdMismatch, NotABorgKeyFile
from ..crypto.file_integrity import FileIntegrityError
from ..helpers import Location, get_security_dir
Expand Down Expand Up @@ -2882,7 +2882,7 @@ def test_init_interrupt(self):
def raise_eof(*args):
raise EOFError

with patch.object(FlexiKeyBase, 'create', raise_eof):
with patch.object(FlexiKey, 'create', raise_eof):
self.cmd('init', '--encryption=repokey', self.repository_location, exit_code=1)
assert not os.path.exists(self.repository_location)

Expand Down

0 comments on commit 5d38251

Please sign in to comment.