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 {
com.google.crypto.tink.proto.KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
HmacKey hmacKey = (HmacKey) Registry.newKey(template);
KeyData hmacKeyData = Registry.newKeyData(template);
Mac mac = Registry.getPrimitive(hmacKeyData, Mac.class);
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(PrfMac.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 {
AesEaxKey aesEaxKey = (AesEaxKey) Registry.newKey(AesEaxKeyManager.aes128EaxTemplate().getProto());
KeyData aesEaxKeyData = Registry.newKeyData(AesEaxKeyManager.aes128EaxTemplate().getProto());
Aead aead = Registry.getPrimitive(aesEaxKeyData, Aead.class);
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);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testParseKeyData_succeeds.
@Test
public void testParseKeyData_succeeds() throws Exception {
Registry.reset();
Registry.registerKeyManager(new TestKeyTypeManager(), true);
AesGcmKey key = AesGcmKey.newBuilder().setKeyValue(ByteString.copyFrom("0123456789abcdef".getBytes(UTF_8))).build();
KeyData keyData = KeyData.newBuilder().setTypeUrl(new TestKeyTypeManager().getKeyType()).setValue(key.toByteString()).build();
assertThat(Registry.parseKeyData(keyData)).isEqualTo(key);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitive_legacy_hmac_shouldWork.
@Test
public void testGetPrimitive_legacy_hmac_shouldWork() throws Exception {
com.google.crypto.tink.proto.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(PrfMac.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPublicKeyData_shouldThrow.
@Test
public void testGetPublicKeyData_shouldThrow() throws Exception {
KeyData keyData = Registry.newKeyData(MacKeyTemplates.HMAC_SHA256_128BITTAG);
GeneralSecurityException e = assertThrows(GeneralSecurityException.class, () -> Registry.getPublicKeyData(keyData.getTypeUrl(), keyData.getValue()));
assertThat(e.toString()).contains("not a PrivateKeyManager");
}
Aggregations