def new_aes_eax_key_template(self, iv_size, key_size): key_format = aes_eax_pb2.AesEaxKeyFormat() key_format.params.iv_size = iv_size key_format.key_size = key_size key_template = tink_pb2.KeyTemplate() key_template.type_url = 'type.googleapis.com/google.crypto.tink.AesEaxKey' key_template.value = key_format.SerializeToString() return key_template.SerializeToString()
def test_aes256_eax(self): template = aead_key_templates.AES256_EAX self.assertEqual('type.googleapis.com/google.crypto.tink.AesEaxKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_eax_pb2.AesEaxKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(32, key_format.key_size) self.assertEqual(16, key_format.params.iv_size)
def create_aes_eax_key_template(key_size: int, iv_size: int) -> tink_pb2.KeyTemplate: """Creates an AES EAX KeyTemplate, and fills in its values.""" key_format = aes_eax_pb2.AesEaxKeyFormat() key_format.params.iv_size = iv_size key_format.key_size = key_size key_template = tink_pb2.KeyTemplate() key_template.value = key_format.SerializeToString() key_template.type_url = _AES_EAX_KEY_TYPE_URL key_template.output_prefix_type = tink_pb2.TINK return key_template
def test_create_aes_eax_key_template(self): # Intentionally using 'weird' or invalid values for parameters, # to test that the function correctly puts them in the resulting template. template = aead_key_templates.create_aes_eax_key_template(key_size=42, iv_size=72) self.assertEqual('type.googleapis.com/google.crypto.tink.AesEaxKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_eax_pb2.AesEaxKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(42, key_format.key_size) self.assertEqual(72, key_format.params.iv_size)