def filter_write(self, cleartext, repo, toplevel): if not self.keyid: return cleartext symmetric_key = self.get_symmetric_key(repo, toplevel) return obnamlib.encrypt_symmetric(cleartext, symmetric_key, gpghome=self.gnupghome)
def test_encrypts_into_different_string_than_cleartext(self): cleartext = 'hello world' key = 'sekr1t' encrypted = obnamlib.encrypt_symmetric(cleartext, key, gpghome=self.gpghome) self.assertNotEqual(cleartext, encrypted)
def test_encrypt_decrypt_round_trip(self): cleartext = 'hello, world' key = 'sekr1t' encrypted = obnamlib.encrypt_symmetric(cleartext, key, gpghome=self.gpghome) decrypted = obnamlib.decrypt_symmetric(encrypted, key, gpghome=self.gpghome) self.assertEqual(decrypted, cleartext)
def toplevel_init(self, repo, toplevel): '''Initialize a new toplevel for encryption.''' if not self.keyid: return pubkeys = obnamlib.Keyring() pubkeys.add(self.pubkey) symmetric_key = obnamlib.generate_symmetric_key( self.symmetric_key_bits, filename=self.devrandom) encrypted = obnamlib.encrypt_with_keyring(symmetric_key, pubkeys) self._write_file(repo, os.path.join(toplevel, 'key'), encrypted) encoded = str(pubkeys) encrypted = obnamlib.encrypt_symmetric(encoded, symmetric_key) self._write_file(repo, os.path.join(toplevel, 'userkeys'), encrypted)
def test_encrypts_into_different_string_than_cleartext(self): cleartext = 'hello world' key = 'sekr1t' encrypted = obnamlib.encrypt_symmetric(cleartext, key) self.assertNotEqual(cleartext, encrypted)
def filter_write(self, cleartext, repo, toplevel): if not self.keyid: return cleartext symmetric_key = self.get_symmetric_key(repo, toplevel) return obnamlib.encrypt_symmetric(cleartext, symmetric_key)