|
@@ -152,8 +152,7 @@ class KeyBase:
|
|
|
|
|
|
def compress(self, chunk):
|
|
def compress(self, chunk):
|
|
meta, data = chunk
|
|
meta, data = chunk
|
|
- data = meta.get('compress', self.compressor).compress(data)
|
|
|
|
- return Chunk(data, **meta)
|
|
|
|
|
|
+ return meta.get('compress', self.compressor).compress(data)
|
|
|
|
|
|
def encrypt(self, chunk):
|
|
def encrypt(self, chunk):
|
|
pass
|
|
pass
|
|
@@ -255,8 +254,8 @@ class PlaintextKey(KeyBase):
|
|
return sha256(data).digest()
|
|
return sha256(data).digest()
|
|
|
|
|
|
def encrypt(self, chunk):
|
|
def encrypt(self, chunk):
|
|
- chunk = self.compress(chunk)
|
|
|
|
- return b''.join([self.TYPE_STR, chunk.data])
|
|
|
|
|
|
+ data = self.compress(chunk)
|
|
|
|
+ return b''.join([self.TYPE_STR, data])
|
|
|
|
|
|
def decrypt(self, id, data, decompress=True):
|
|
def decrypt(self, id, data, decompress=True):
|
|
if data[0] != self.TYPE:
|
|
if data[0] != self.TYPE:
|
|
@@ -333,10 +332,10 @@ class AESKeyBase(KeyBase):
|
|
MAC = hmac_sha256
|
|
MAC = hmac_sha256
|
|
|
|
|
|
def encrypt(self, chunk):
|
|
def encrypt(self, chunk):
|
|
- chunk = self.compress(chunk)
|
|
|
|
- self.nonce_manager.ensure_reservation(num_aes_blocks(len(chunk.data)))
|
|
|
|
|
|
+ data = self.compress(chunk)
|
|
|
|
+ self.nonce_manager.ensure_reservation(num_aes_blocks(len(data)))
|
|
self.enc_cipher.reset()
|
|
self.enc_cipher.reset()
|
|
- data = b''.join((self.enc_cipher.iv[8:], self.enc_cipher.encrypt(chunk.data)))
|
|
|
|
|
|
+ data = b''.join((self.enc_cipher.iv[8:], self.enc_cipher.encrypt(data)))
|
|
assert (self.MAC is blake2b_256 and len(self.enc_hmac_key) == 128 or
|
|
assert (self.MAC is blake2b_256 and len(self.enc_hmac_key) == 128 or
|
|
self.MAC is hmac_sha256 and len(self.enc_hmac_key) == 32)
|
|
self.MAC is hmac_sha256 and len(self.enc_hmac_key) == 32)
|
|
hmac = self.MAC(self.enc_hmac_key, data)
|
|
hmac = self.MAC(self.enc_hmac_key, data)
|
|
@@ -745,8 +744,8 @@ class AuthenticatedKey(ID_BLAKE2b_256, RepoKey):
|
|
STORAGE = KeyBlobStorage.REPO
|
|
STORAGE = KeyBlobStorage.REPO
|
|
|
|
|
|
def encrypt(self, chunk):
|
|
def encrypt(self, chunk):
|
|
- chunk = self.compress(chunk)
|
|
|
|
- return b''.join([self.TYPE_STR, chunk.data])
|
|
|
|
|
|
+ data = self.compress(chunk)
|
|
|
|
+ return b''.join([self.TYPE_STR, data])
|
|
|
|
|
|
def decrypt(self, id, data, decompress=True):
|
|
def decrypt(self, id, data, decompress=True):
|
|
if data[0] != self.TYPE:
|
|
if data[0] != self.TYPE:
|