1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 01:06:50 +00:00

Use buffer instead of string slicing to reduce memory usage.

This commit is contained in:
Jonas Borgström 2013-06-02 15:55:23 +02:00
parent 994473352d
commit bda6bc47d7
3 changed files with 10 additions and 7 deletions

View file

@ -83,7 +83,7 @@ def encrypt(self, data):
def decrypt(self, id, data):
if data[0] != self.TYPE:
raise IntegrityError('Invalid encryption envelope')
data = zlib.decompress(data[1:])
data = zlib.decompress(buffer(data, 1))
if id and SHA256.new(data).digest() != id:
raise IntegrityError('Chunk id verification failed')
return data
@ -107,12 +107,12 @@ def encrypt(self, data):
def decrypt(self, id, data):
if data[0] != self.TYPE:
raise IntegrityError('Invalid encryption envelope')
hash = data[1:33]
if HMAC.new(self.enc_hmac_key, data[33:], SHA256).digest() != hash:
hash = buffer(data, 1, 32)
if buffer(HMAC.new(self.enc_hmac_key, buffer(data, 33), SHA256).digest()) != hash:
raise IntegrityError('Encryption envelope checksum mismatch')
nonce = bytes_to_long(data[33:41])
nonce = bytes_to_long(buffer(data, 33, 8))
counter = Counter.new(64, initial_value=nonce, prefix=PREFIX)
data = zlib.decompress(AES.new(self.enc_key, AES.MODE_CTR, counter=counter).decrypt(data[41:]))
data = zlib.decompress(AES.new(self.enc_key, AES.MODE_CTR, counter=counter).decrypt(buffer(data, 41)))
if id and HMAC.new(self.id_key, data, SHA256).digest() != id:
raise IntegrityError('Chunk id verification failed')
return data

View file

@ -127,7 +127,7 @@ def call(self, cmd, args, wait=True):
if to_send:
n = os.write(self.stdin_fd, to_send)
assert n > 0
to_send = to_send[n:]
to_send = buffer(to_send, n)
else:
w_fds = []
@ -212,7 +212,7 @@ def call_multi(self, cmd, argsv, wait=True, peek=None):
if self.to_send:
n = os.write(self.stdin_fd, self.to_send)
assert n > 0
self.to_send = self.to_send[n:]
self.to_send = buffer(self.to_send, n)
else:
w_fds = []
if not wait:

View file

@ -92,6 +92,9 @@ def diff_dirs(self, dir1, dir2):
attrs.append('st_mtime')
d1 = [filename] + [getattr(s1, a) for a in attrs]
d2 = [filename] + [getattr(s2, a) for a in attrs]
if(len(d1) == 6):
d1[-1] = int(d1[-1])
d2[-1] = int(d2[-1])
d1.append(self.get_xattrs(path1))
d2.append(self.get_xattrs(path2))
self.assertEqual(d1, d2)