mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 09:47:58 +00:00
use cipher.block_count()
there are some more places where it is used.
This commit is contained in:
parent
de0707d3dd
commit
f76f42c2a0
2 changed files with 4 additions and 4 deletions
|
@ -358,7 +358,7 @@ class AESKeyBase(KeyBase):
|
||||||
|
|
||||||
def encrypt(self, chunk):
|
def encrypt(self, chunk):
|
||||||
data = self.compressor.compress(chunk)
|
data = self.compressor.compress(chunk)
|
||||||
self.nonce_manager.ensure_reservation(num_aes_blocks(len(data)))
|
self.nonce_manager.ensure_reservation(self.cipher.block_count(len(data)))
|
||||||
return self.cipher.encrypt(data, header=self.TYPE_STR, aad_offset=1)
|
return self.cipher.encrypt(data, header=self.TYPE_STR, aad_offset=1)
|
||||||
|
|
||||||
def decrypt(self, id, data, decompress=True):
|
def decrypt(self, id, data, decompress=True):
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
from ..crypto.key import ID_HMAC_SHA_256, ID_BLAKE2b_256
|
from ..crypto.key import ID_HMAC_SHA_256, ID_BLAKE2b_256
|
||||||
from ..crypto.key import TAMRequiredError, TAMInvalid, TAMUnsupportedSuiteError, UnsupportedManifestError
|
from ..crypto.key import TAMRequiredError, TAMInvalid, TAMUnsupportedSuiteError, UnsupportedManifestError
|
||||||
from ..crypto.key import identify_key
|
from ..crypto.key import identify_key
|
||||||
from ..crypto.low_level import bytes_to_long, num_aes_blocks
|
from ..crypto.low_level import bytes_to_long
|
||||||
from ..crypto.low_level import IntegrityError as IntegrityErrorBase
|
from ..crypto.low_level import IntegrityError as IntegrityErrorBase
|
||||||
from ..helpers import IntegrityError
|
from ..helpers import IntegrityError
|
||||||
from ..helpers import Location
|
from ..helpers import Location
|
||||||
|
@ -126,7 +126,7 @@ def test_keyfile(self, monkeypatch, keys_dir):
|
||||||
assert key.extract_nonce(manifest2) == 1
|
assert key.extract_nonce(manifest2) == 1
|
||||||
iv = key.extract_nonce(manifest)
|
iv = key.extract_nonce(manifest)
|
||||||
key2 = KeyfileKey.detect(self.MockRepository(), manifest)
|
key2 = KeyfileKey.detect(self.MockRepository(), manifest)
|
||||||
assert bytes_to_long(key2.cipher.next_iv(), 8) >= iv + num_aes_blocks(len(manifest) - KeyfileKey.PAYLOAD_OVERHEAD)
|
assert bytes_to_long(key2.cipher.next_iv(), 8) >= iv + key2.cipher.block_count(len(manifest) - KeyfileKey.PAYLOAD_OVERHEAD)
|
||||||
# Key data sanity check
|
# Key data sanity check
|
||||||
assert len({key2.id_key, key2.enc_key, key2.enc_hmac_key}) == 3
|
assert len({key2.id_key, key2.enc_key, key2.enc_hmac_key}) == 3
|
||||||
assert key2.chunk_seed != 0
|
assert key2.chunk_seed != 0
|
||||||
|
@ -199,7 +199,7 @@ def test_passphrase(self, keys_dir, monkeypatch):
|
||||||
assert key.extract_nonce(manifest2) == 1
|
assert key.extract_nonce(manifest2) == 1
|
||||||
iv = key.extract_nonce(manifest)
|
iv = key.extract_nonce(manifest)
|
||||||
key2 = PassphraseKey.detect(self.MockRepository(), manifest)
|
key2 = PassphraseKey.detect(self.MockRepository(), manifest)
|
||||||
assert bytes_to_long(key2.cipher.next_iv(), 8) == iv + num_aes_blocks(len(manifest) - PassphraseKey.PAYLOAD_OVERHEAD)
|
assert bytes_to_long(key2.cipher.next_iv(), 8) == iv + key2.cipher.block_count(len(manifest) - PassphraseKey.PAYLOAD_OVERHEAD)
|
||||||
assert key.id_key == key2.id_key
|
assert key.id_key == key2.id_key
|
||||||
assert key.enc_hmac_key == key2.enc_hmac_key
|
assert key.enc_hmac_key == key2.enc_hmac_key
|
||||||
assert key.enc_key == key2.enc_key
|
assert key.enc_key == key2.enc_key
|
||||||
|
|
Loading…
Reference in a new issue