Example #1
0
 def test_fake_deterministic_aead_fail_wrong_primitive(self):
   daead = helper.FakeDeterministicAead('Name')
   ciphertext = daead.encrypt_deterministically(b'plaintext',
                                                b'associated_data')
   wrong_daead = helper.FakeDeterministicAead('Wrong Name')
   with self.assertRaisesRegex(tink_error.TinkError,
                               'failed to decrypt ciphertext'):
     wrong_daead.decrypt_deterministically(ciphertext, b'associated_data')
Example #2
0
 def test_fake_deterministic_aead_success(self):
   daead = helper.FakeDeterministicAead('Name')
   ciphertext = daead.encrypt_deterministically(b'plaintext',
                                                b'associated_data')
   self.assertEqual(
       daead.decrypt_deterministically(ciphertext, b'associated_data'),
       b'plaintext')
Example #3
0
  def test_decrypt_unknown_ciphertext_fails(self):
    unknown_primitive = helper.FakeDeterministicAead(
        'unknownFakeDeterministicAead')
    unknown_ciphertext = unknown_primitive.encrypt_deterministically(
        b'plaintext', b'associated_data')

    pset = primitive_set.new_primitive_set(deterministic_aead.DeterministicAead)
    primitive, raw_key = self.new_primitive_key_pair(1234, tink_pb2.RAW)
    new_primitive, new_key = self.new_primitive_key_pair(5678, tink_pb2.TINK)
    pset.add_primitive(primitive, raw_key)
    new_entry = pset.add_primitive(new_primitive, new_key)
    pset.set_primary(new_entry)
    wrapped_daead = deterministic_aead_wrapper.DeterministicAeadWrapper().wrap(
        pset)

    with self.assertRaisesRegex(tink_error.TinkError, 'Decryption failed'):
      wrapped_daead.decrypt_deterministically(unknown_ciphertext,
                                              b'associated_data')
 def new_primitive_key_pair(self, key_id, output_prefix_type):
     fake_key = helper.fake_key(key_id=key_id,
                                output_prefix_type=output_prefix_type)
     fake_aead = helper.FakeDeterministicAead(
         'fakeDeterministicAead {}'.format(key_id))
     return fake_aead, fake_key
Example #5
0
 def test_fake_deterministic_aead_fail_wrong_cipertext(self):
   daead = helper.FakeDeterministicAead('Name')
   with self.assertRaisesRegex(tink_error.TinkError,
                               'failed to decrypt ciphertext'):
     daead.decrypt_deterministically(b'wrong ciphertext', b'associated_data')