Skip to content

Commit

Permalink
Refactor: s/enc_key/encrypted_key/
Browse files Browse the repository at this point in the history
  • Loading branch information
hexagonrecursion committed Mar 19, 2022
1 parent f63cf85 commit 280eb43
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/borg/crypto/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,19 @@ def decrypt_key_file(self, data, passphrase):
unpacker = get_limited_unpacker('key')
unpacker.feed(data)
data = unpacker.unpack()
enc_key = EncryptedKey(internal_dict=data)
if enc_key.version == 1:
return self.decrypt_key_file_v1(enc_key, passphrase)
elif enc_key.version == 2:
return self.decrypt_key_file_v2(enc_key, passphrase)
encrypted_key = EncryptedKey(internal_dict=data)
if encrypted_key.version == 1:
return self.decrypt_key_file_v1(encrypted_key, passphrase)
elif encrypted_key.version == 2:
return self.decrypt_key_file_v2(encrypted_key, passphrase)
else:
raise Exception('Your borg key is stored in an unsupported format. Try using a newer version of borg')

def decrypt_key_file_v1(self, enc_key, passphrase):
assert enc_key.algorithm == 'sha256'
key = passphrase.kdf(enc_key.salt, enc_key.iterations, 32)
data = AES(key, b'\0'*16).decrypt(enc_key.data)
if hmac_sha256(key, data) == enc_key.hash:
def decrypt_key_file_v1(self, encrypted_key, passphrase):
assert encrypted_key.algorithm == 'sha256'
key = passphrase.kdf(encrypted_key.salt, encrypted_key.iterations, 32)
data = AES(key, b'\0'*16).decrypt(encrypted_key.data)
if hmac_sha256(key, data) == encrypted_key.hash:
return data
return None

Expand Down

0 comments on commit 280eb43

Please sign in to comment.