def test_write_encrypted(self): handle = core.new_keyset_handle(mac.mac_key_templates.HMAC_SHA256_128BITTAG) # Encrypt the keyset with Aead. master_key_aead = _master_key_aead() output_stream = io.BytesIO() writer = core.BinaryKeysetWriter(output_stream) handle.write(writer, master_key_aead) reader = core.BinaryKeysetReader(output_stream.getvalue()) handle2 = core.read_keyset_handle(reader, master_key_aead) # Check that handle2 has the same primitive as handle. handle2.primitive(mac.Mac).verify_mac( handle.primitive(mac.Mac).compute_mac(b'data'), b'data')
def test_read_empty_keyset_fails(self): with self.assertRaisesRegex(core.TinkError, 'No keyset found'): core.read_keyset_handle(core.BinaryKeysetReader(b''), _master_key_aead())