Exemplo n.º 1
0
 def test_fake_hybrid_fail_wrong_dec(self):
   enc = helper.FakeHybridEncrypt('Name')
   dec = helper.FakeHybridDecrypt('Wrong Name')
   ciphertext = enc.encrypt(b'plaintext', b'context_info')
   with self.assertRaisesRegex(core.TinkError,
                               'failed to decrypt ciphertext'):
     dec.decrypt(ciphertext, b'context_info')
Exemplo n.º 2
0
 def test_fake_hybrid_success(self):
   enc = helper.FakeHybridEncrypt('Name')
   dec = helper.FakeHybridDecrypt('Name')
   ciphertext = enc.encrypt(b'plaintext', b'context_info')
   self.assertEqual(
       dec.decrypt(ciphertext, b'context_info'),
       b'plaintext')
Exemplo n.º 3
0
def new_primitives_and_keys(key_id, output_prefix_type):
    fake_dec_key = helper.fake_key(
        key_material_type=tink_pb2.KeyData.ASYMMETRIC_PRIVATE,
        key_id=key_id,
        output_prefix_type=output_prefix_type)
    fake_enc_key = helper.fake_key(
        key_material_type=tink_pb2.KeyData.ASYMMETRIC_PUBLIC,
        key_id=key_id,
        output_prefix_type=output_prefix_type)
    fake_hybrid_decrypt = helper.FakeHybridDecrypt(
        'fakeHybrid {}'.format(key_id))
    fake_hybrid_encrypt = helper.FakeHybridEncrypt(
        'fakeHybrid {}'.format(key_id))
    return fake_hybrid_decrypt, fake_hybrid_encrypt, fake_dec_key, fake_enc_key
Exemplo n.º 4
0
 def primitive(self, key_data: tink_pb2.KeyData) -> hybrid.HybridDecrypt:
     return helper.FakeHybridDecrypt()
Exemplo n.º 5
0
 def test_fake_hybrid_fail_wrong_ciphertext(self):
     dec = helper.FakeHybridDecrypt('Name')
     with self.assertRaises(core.TinkError):
         dec.decrypt(b'wrong ciphertext', b'context_info')
Exemplo n.º 6
0
 def test_fake_hybrid_fail_wrong_context(self):
     enc = helper.FakeHybridEncrypt('Name')
     dec = helper.FakeHybridDecrypt('Name')
     ciphertext = enc.encrypt(b'plaintext', b'context_info')
     with self.assertRaises(core.TinkError):
         dec.decrypt(ciphertext, b'other_context_info')
Exemplo n.º 7
0
 def test_fake_hybrid_fail_wrong_ciphertext(self):
     dec = helper.FakeHybridDecrypt('Name')
     with self.assertRaisesRegex(tink_error.TinkError,
                                 'failed to decrypt ciphertext'):
         dec.decrypt(b'wrong ciphertext', b'context_info')