(pt, key, alg, iv=None)
| 16 | |
| 17 | |
| 18 | def _encrypt(pt, key, alg, iv=None): |
| 19 | if iv is None: |
| 20 | iv = b'\x00' * (alg.block_size // 8) |
| 21 | |
| 22 | if alg.is_insecure: |
| 23 | raise PGPInsecureCipherError("{:s} is not secure. Do not use it for encryption!".format(alg.name)) |
| 24 | |
| 25 | if not alg.is_supported: |
| 26 | raise PGPEncryptionError("Cipher {:s} not supported".format(alg.name)) |
| 27 | |
| 28 | try: |
| 29 | encryptor = Cipher(alg.cipher(key), modes.CFB(iv), default_backend()).encryptor() |
| 30 | |
| 31 | except UnsupportedAlgorithm as ex: # pragma: no cover |
| 32 | raise PGPEncryptionError from ex |
| 33 | |
| 34 | else: |
| 35 | return bytearray(encryptor.update(pt) + encryptor.finalize()) |
| 36 | |
| 37 | |
| 38 | def _decrypt(ct, key, alg, iv=None): |
no test coverage detected
searching dependent graphs…