ソースを参照

crypto: key: reduce class inheritance depth

Thomas Waldmann 3 年 前
コミット
dd2a054ac4
2 ファイル変更5 行追加19 行削除
  1. 3 17
      src/borg/crypto/key.py
  2. 2 2
      src/borg/testsuite/archiver.py

+ 3 - 17
src/borg/crypto/key.py

@@ -383,7 +383,9 @@ class AESKeyBase(KeyBase):
         self.nonce_manager = NonceManager(self.repository, nonce)
         self.nonce_manager = NonceManager(self.repository, nonce)
 
 
 
 
-class FlexiKeyBase:
+class FlexiKey:
+    FILE_ID = 'BORG_KEY'
+
     @classmethod
     @classmethod
     def detect(cls, repository, manifest_data):
     def detect(cls, repository, manifest_data):
         key = cls(repository)
         key = cls(repository)
@@ -406,12 +408,6 @@ class FlexiKeyBase:
         key._passphrase = passphrase
         key._passphrase = passphrase
         return key
         return key
 
 
-    def find_key(self):
-        raise NotImplementedError
-
-    def load(self, target, passphrase):
-        raise NotImplementedError
-
     def _load(self, key_data, passphrase):
     def _load(self, key_data, passphrase):
         cdata = a2b_base64(key_data)
         cdata = a2b_base64(key_data)
         data = self.decrypt_key_file(cdata, passphrase)
         data = self.decrypt_key_file(cdata, passphrase)
@@ -489,16 +485,6 @@ class FlexiKeyBase:
         logger.info('Keep this key safe. Your data will be inaccessible without it.')
         logger.info('Keep this key safe. Your data will be inaccessible without it.')
         return key
         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):
     def sanity_check(self, filename, id):
         file_id = self.FILE_ID.encode() + b' '
         file_id = self.FILE_ID.encode() + b' '
         repo_id = hexlify(id)
         repo_id = hexlify(id)

+ 2 - 2
src/borg/testsuite/archiver.py

@@ -36,7 +36,7 @@ from ..cache import Cache, LocalCache
 from ..chunker import has_seek_hole
 from ..chunker import has_seek_hole
 from ..constants import *  # NOQA
 from ..constants import *  # NOQA
 from ..crypto.low_level import bytes_to_long, num_cipher_blocks
 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.keymanager import RepoIdMismatch, NotABorgKeyFile
 from ..crypto.file_integrity import FileIntegrityError
 from ..crypto.file_integrity import FileIntegrityError
 from ..helpers import Location, get_security_dir
 from ..helpers import Location, get_security_dir
@@ -2882,7 +2882,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         def raise_eof(*args):
         def raise_eof(*args):
             raise EOFError
             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)
             self.cmd('init', '--encryption=repokey', self.repository_location, exit_code=1)
         assert not os.path.exists(self.repository_location)
         assert not os.path.exists(self.repository_location)