use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.
the class AesCmacPrfKeyManagerTest method validateKey_notValid_throws.
@Test
public void validateKey_notValid_throws() throws Exception {
AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(16))).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(64))).build()));
}
use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.
the class AesCmacPrfKeyManagerTest method getPrimitive_works.
@Test
public void getPrimitive_works() throws Exception {
AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
Prf directPrf = new PrfAesCmac(validKey.getKeyValue().toByteArray());
byte[] message = Random.randBytes(50);
assertThat(managerPrf.compute(message, 16)).isEqualTo(directPrf.compute(message, 16));
}
use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.
the class AesCmacPrfKeyManagerTest method createKey_checkValues.
@Test
public void createKey_checkValues() throws Exception {
AesCmacPrfKeyFormat keyFormat = makeAesCmacPrfKeyFormat(32);
AesCmacPrfKey key = new AesCmacPrfKeyManager().keyFactory().createKey(keyFormat);
assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
}
use of com.google.crypto.tink.proto.AesCmacPrfKey in project tink by google.
the class AesCmacPrfKeyManagerTest method validateKey_wrongVersion_throws.
@Test
public void validateKey_wrongVersion_throws() throws Exception {
AesCmacPrfKeyManager manager = new AesCmacPrfKeyManager();
AesCmacPrfKey validKey = manager.keyFactory().createKey(makeAesCmacPrfKeyFormat(32));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(AesCmacPrfKey.newBuilder(validKey).setVersion(1).build()));
}
Aggregations