def new_aes_gcm_key_template(self, key_size): key_format = aes_gcm_pb2.AesGcmKeyFormat() key_format.key_size = key_size key_template = tink_pb2.KeyTemplate() key_template.type_url = ('type.googleapis.com/google.crypto.tink.AesGcmKey') key_template.value = key_format.SerializeToString() return key_template
def test_aes256_gcm(self): template = aead.aead_key_templates.AES256_GCM self.assertEqual('type.googleapis.com/google.crypto.tink.AesGcmKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_gcm_pb2.AesGcmKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(32, key_format.key_size)
def create_aes_gcm_key_template(key_size: int) -> tink_pb2.KeyTemplate: """Creates an AES GCM KeyTemplate, and fills in its values.""" key_format = aes_gcm_pb2.AesGcmKeyFormat() key_format.key_size = key_size key_template = tink_pb2.KeyTemplate() key_template.value = key_format.SerializeToString() key_template.type_url = _AES_GCM_KEY_TYPE_URL key_template.output_prefix_type = tink_pb2.TINK return key_template
def test_create_aes_gcm_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_gcm_key_template(key_size=42) self.assertEqual('type.googleapis.com/google.crypto.tink.AesGcmKey', template.type_url) self.assertEqual(tink_pb2.TINK, template.output_prefix_type) key_format = aes_gcm_pb2.AesGcmKeyFormat() key_format.ParseFromString(template.value) self.assertEqual(42, key_format.key_size)