Search in sources :

Example 1 with KmsEnvelopeAeadKeyFormat

use of com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat in project tink by google.

the class AeadKeyTemplatesTest method testCreateKmsEnvelopeAeadKeyTemplate.

@Test
public void testCreateKmsEnvelopeAeadKeyTemplate() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    String kekUri = "some example KEK URI";
    KeyTemplate dekTemplate = AeadKeyTemplates.AES256_GCM;
    KeyTemplate template = AeadKeyTemplates.createKmsEnvelopeAeadKeyTemplate(kekUri, dekTemplate);
    assertEquals(new KmsEnvelopeAeadKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(kekUri, format.getKekUri());
    assertEquals(dekTemplate.toString(), format.getDekTemplate().toString());
}
Also used : KmsEnvelopeAeadKeyFormat(com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 2 with KmsEnvelopeAeadKeyFormat

use of com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat in project tink by google.

the class AeadKeyTemplatesTest method testCreateKmsEnvelopeAeadKeyFormat.

@Test
public void testCreateKmsEnvelopeAeadKeyFormat() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    String kekUri = "some example KEK URI";
    KeyTemplate dekTemplate = AeadKeyTemplates.AES256_GCM;
    KeyTemplate template = AeadKeyTemplates.createKmsEnvelopeAeadKeyTemplate(kekUri, dekTemplate);
    assertEquals(KmsEnvelopeAeadKeyManager.TYPE_URL, template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.parseFrom(template.getValue());
    assertEquals(kekUri, format.getKekUri());
    assertEquals(dekTemplate.toString(), format.getDekTemplate().toString());
}
Also used : KmsEnvelopeAeadKeyFormat(com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 3 with KmsEnvelopeAeadKeyFormat

use of com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat in project tink by google.

the class KmsEnvelopeAeadKeyManagerTest method createKeyTemplate.

@Test
public void createKeyTemplate() throws Exception {
    // Intentionally using "weird" or invalid values for parameters,
    // to test that the function correctly puts them in the resulting template.
    String kekUri = "some example KEK URI";
    KeyTemplate dekTemplate = AesCtrHmacAeadKeyManager.aes128CtrHmacSha256Template();
    KeyTemplate template = KmsEnvelopeAeadKeyManager.createKeyTemplate(kekUri, dekTemplate);
    assertThat(new KmsEnvelopeAeadKeyManager().getKeyType()).isEqualTo(template.getTypeUrl());
    assertThat(KeyTemplate.OutputPrefixType.RAW).isEqualTo(template.getOutputPrefixType());
    KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(kekUri).isEqualTo(format.getKekUri());
    assertThat(dekTemplate.getTypeUrl()).isEqualTo(format.getDekTemplate().getTypeUrl());
    assertThat(dekTemplate.getValue()).isEqualTo(format.getDekTemplate().getValue().toByteArray());
}
Also used : KmsEnvelopeAeadKeyFormat(com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat) ByteString(com.google.protobuf.ByteString) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

KmsEnvelopeAeadKeyFormat (com.google.crypto.tink.proto.KmsEnvelopeAeadKeyFormat)3 Test (org.junit.Test)3 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)2 KeyTemplate (com.google.crypto.tink.KeyTemplate)1 ByteString (com.google.protobuf.ByteString)1