use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitives_WithSomeNonEnabledKeys_shouldWork.
@Test
public void testGetPrimitives_WithSomeNonEnabledKeys_shouldWork() throws Exception {
// Try a keyset with some keys non-ENABLED.
KeyTemplate template1 = AeadKeyTemplates.AES128_EAX;
KeyTemplate template2 = AeadKeyTemplates.AES128_CTR_HMAC_SHA256;
KeyData key1 = Registry.newKeyData(template1);
KeyData key2 = Registry.newKeyData(template1);
KeyData key3 = Registry.newKeyData(template2);
KeysetHandle keysetHandle = KeysetHandle.fromKeyset(Keyset.newBuilder().addKey(Keyset.Key.newBuilder().setKeyData(key1).setKeyId(1).setStatus(KeyStatusType.DESTROYED).setOutputPrefixType(OutputPrefixType.TINK).build()).addKey(Keyset.Key.newBuilder().setKeyData(key2).setKeyId(2).setStatus(KeyStatusType.DISABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).addKey(Keyset.Key.newBuilder().setKeyData(key3).setKeyId(3).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).setPrimaryKeyId(3).build());
PrimitiveSet<Aead> aeadSet = Registry.getPrimitives(keysetHandle);
assertThat(aeadSet.getPrimary().getPrimitive().getClass()).isEqualTo(EncryptThenAuthenticate.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitive_Hmac_shouldWork.
@Test
public void testGetPrimitive_Hmac_shouldWork() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
HmacKey hmacKey = (HmacKey) Registry.newKey(template);
KeyData hmacKeyData = Registry.newKeyData(template);
Mac mac = Registry.getPrimitive(hmacKeyData);
assertThat(hmacKey.getKeyValue().size()).isEqualTo(32);
assertThat(hmacKey.getParams().getTagSize()).isEqualTo(16);
assertThat(hmacKey.getParams().getHash()).isEqualTo(HashType.SHA256);
assertThat(hmacKeyData.getTypeUrl()).isEqualTo(MacConfig.HMAC_TYPE_URL);
// This might break when we add native implementations.
assertThat(mac.getClass()).isEqualTo(MacJce.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitives_shouldWork.
@Test
public void testGetPrimitives_shouldWork() throws Exception {
// Create a keyset, and get a PrimitiveSet.
KeyTemplate template1 = AeadKeyTemplates.AES128_EAX;
KeyTemplate template2 = AeadKeyTemplates.AES128_CTR_HMAC_SHA256;
KeyData key1 = Registry.newKeyData(template1);
KeyData key2 = Registry.newKeyData(template1);
KeyData key3 = Registry.newKeyData(template2);
KeysetHandle keysetHandle = KeysetHandle.fromKeyset(Keyset.newBuilder().addKey(Keyset.Key.newBuilder().setKeyData(key1).setKeyId(1).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).addKey(Keyset.Key.newBuilder().setKeyData(key2).setKeyId(2).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).addKey(Keyset.Key.newBuilder().setKeyData(key3).setKeyId(3).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).setPrimaryKeyId(2).build());
PrimitiveSet<Aead> aeadSet = Registry.getPrimitives(keysetHandle);
assertThat(aeadSet.getPrimary().getPrimitive().getClass()).isEqualTo(AesEaxJce.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitives_CustomManager_shouldWork.
@Test
public void testGetPrimitives_CustomManager_shouldWork() throws Exception {
// Create a keyset.
KeyTemplate template1 = AeadKeyTemplates.AES128_EAX;
KeyTemplate template2 = AeadKeyTemplates.AES128_CTR_HMAC_SHA256;
KeyData key1 = Registry.newKeyData(template1);
KeyData key2 = Registry.newKeyData(template2);
KeysetHandle keysetHandle = KeysetHandle.fromKeyset(Keyset.newBuilder().addKey(Keyset.Key.newBuilder().setKeyData(key1).setKeyId(1).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).addKey(Keyset.Key.newBuilder().setKeyData(key2).setKeyId(2).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.TINK).build()).setPrimaryKeyId(2).build());
// Get a PrimitiveSet using a custom key manager for key1.
KeyManager<Aead> customManager = new CustomAeadKeyManager();
PrimitiveSet<Aead> aeadSet = Registry.getPrimitives(keysetHandle, customManager);
List<PrimitiveSet.Entry<Aead>> aead1List = aeadSet.getPrimitive(keysetHandle.getKeyset().getKey(0));
List<PrimitiveSet.Entry<Aead>> aead2List = aeadSet.getPrimitive(keysetHandle.getKeyset().getKey(1));
assertThat(aead1List.size()).isEqualTo(1);
assertThat(aead1List.get(0).getPrimitive().getClass()).isEqualTo(DummyAead.class);
assertThat(aead2List.size()).isEqualTo(1);
assertThat(aead2List.get(0).getPrimitive().getClass()).isEqualTo(EncryptThenAuthenticate.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitive_AesGcm_shouldWork.
@Test
public void testGetPrimitive_AesGcm_shouldWork() throws Exception {
KeyTemplate template = AeadKeyTemplates.AES128_EAX;
AesEaxKey aesEaxKey = (AesEaxKey) Registry.newKey(template);
KeyData aesEaxKeyData = Registry.newKeyData(template);
Aead aead = Registry.getPrimitive(aesEaxKeyData);
assertThat(aesEaxKey.getKeyValue().size()).isEqualTo(16);
assertThat(aesEaxKeyData.getTypeUrl()).isEqualTo(AeadConfig.AES_EAX_TYPE_URL);
// This might break when we add native implementations.
assertThat(aead.getClass()).isEqualTo(AesEaxJce.class);
}
Aggregations