verify HMAC-SHA256 signature and decrypt data with AES-CBC
(self, data)
| 45 | return data + sig |
| 46 | |
| 47 | def decrypt(self, data): |
| 48 | """verify HMAC-SHA256 signature and decrypt data with AES-CBC""" |
| 49 | aes_key, hmac_key = self.keys |
| 50 | sig = data[-self.SIG_SIZE:] |
| 51 | data = data[:-self.SIG_SIZE] |
| 52 | if hmac.new(hmac_key, data, hashlib.sha256).digest() != sig: |
| 53 | raise AuthenticationError("message authentication failed") |
| 54 | iv_bytes = data[:self.AES_BLOCK_SIZE] |
| 55 | data = data[self.AES_BLOCK_SIZE:] |
| 56 | cypher = AES.new(aes_key, AES.MODE_CBC, iv_bytes) |
| 57 | data = cypher.decrypt(data) |
| 58 | return data[:-ord(data[-1])] |
| 59 | |
| 60 | def dumps(self, obj, pickler=pickle): |
| 61 | """pickle and encrypt a python object""" |
no test coverage detected