use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method createKey_checkValues.
@Test
public void createKey_checkValues() throws Exception {
HmacPrfKeyFormat keyFormat = makeHmacPrfKeyFormat(16, HashType.SHA256);
HmacPrfKey key = factory.createKey(keyFormat);
assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
assertThat(key.getParams().getHash()).isEqualTo(keyFormat.getParams().getHash());
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method validateKey_wrongVersion_throws.
@Test
public void validateKey_wrongVersion_throws() throws Exception {
HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setVersion(1).build()));
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method validateKey_notValid_throws.
@Test
public void validateKey_notValid_throws() throws Exception {
HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(15))).build()));
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setParams(HmacPrfParams.newBuilder(validKey.getParams()).setHash(HashType.UNKNOWN_HASH).build()).build()));
}
Aggregations