MCPcopy
hub / github.com/borgbackup/borg / _load

Method _load

src/borg/crypto/key.py:411–430  ·  view source on GitHub ↗
(self, key_data, passphrase)

Source from the content-addressed store, hash-verified

409 return key
410
411 def _load(self, key_data, passphrase):
412 try:
413 key = binascii.a2b_base64(key_data)
414 except (ValueError, binascii.Error):
415 raise KeyfileInvalidError(self.repository._location.canonical_path(), "(repokey)") from None
416 if len(key) < 20:
417 # this is in no way a precise check, usually we have about 400b key data.
418 raise KeyfileInvalidError(self.repository._location.canonical_path(), "(repokey)")
419 data = self.decrypt_key_file(key, passphrase)
420 if data:
421 data = msgpack.unpackb(data)
422 key = Key(internal_dict=data)
423 if key.version not in (1, 2): # legacy: item.Key can still process v1 keys
424 raise UnsupportedKeyFormatError()
425 self.repository_id = key.repository_id
426 self.crypt_key = key.crypt_key
427 self.id_key = key.id_key
428 self.chunk_seed = key.chunk_seed
429 return True
430 return False
431
432 def decrypt_key_file(self, data, passphrase):
433 unpacker = get_limited_unpacker("key")

Callers 2

loadMethod · 0.95
_loadMethod · 0.45

Calls 4

decrypt_key_fileMethod · 0.95
KeyfileInvalidErrorClass · 0.85
canonical_pathMethod · 0.45

Tested by

no test coverage detected