use of com.google.crypto.tink.proto.HkdfPrfKeyFormat in project tink by google.
the class HkdfPrfKeyManagerTest method validateKeyFormat_invalidSha1_throws.
@Test
public void validateKeyFormat_invalidSha1_throws() throws Exception {
HkdfPrfKeyFormat format = HkdfPrfKeyFormat.newBuilder().setKeySize(32).setParams(HkdfPrfParams.newBuilder().setHash(HashType.SHA1)).build();
assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
use of com.google.crypto.tink.proto.HkdfPrfKeyFormat in project tink by google.
the class HkdfPrfKeyManagerTest method createKey_valuesAreOk.
@Test
public void createKey_valuesAreOk() throws Exception {
HkdfPrfKeyFormat format = HkdfPrfKeyFormat.newBuilder().setKeySize(77).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFrom(Random.randBytes(5))).setHash(HashType.SHA256)).build();
HkdfPrfKey key = factory.createKey(format);
assertThat(key.getVersion()).isEqualTo(0);
assertThat(key.getKeyValue()).hasSize(77);
assertThat(key.getParams()).isEqualTo(format.getParams());
}
use of com.google.crypto.tink.proto.HkdfPrfKeyFormat in project tink by google.
the class PrfKeyTemplatesTest method hkdfSha256_worksWithKeyManager.
@Test
public void hkdfSha256_worksWithKeyManager() throws Exception {
HkdfPrfKeyFormat format = HkdfPrfKeyFormat.parseFrom(PrfKeyTemplates.HKDF_SHA256.getValue(), ExtensionRegistryLite.getEmptyRegistry());
new HkdfPrfKeyManager().keyFactory().validateKeyFormat(format);
}
use of com.google.crypto.tink.proto.HkdfPrfKeyFormat in project tink by google.
the class HkdfPrfKeyManagerTest method validateKeyFormat_invalid31Byte_throws.
@Test
public void validateKeyFormat_invalid31Byte_throws() throws Exception {
HkdfPrfKeyFormat keyFormat = HkdfPrfKeyFormat.newBuilder().setKeySize(31).setParams(HkdfPrfParams.newBuilder().setHash(HashType.SHA256)).build();
assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(keyFormat));
}
use of com.google.crypto.tink.proto.HkdfPrfKeyFormat in project tink by google.
the class HkdfPrfKeyManagerTest method testHkdfSha256Template.
@Test
public void testHkdfSha256Template() throws Exception {
KeyTemplate kt = HkdfPrfKeyManager.hkdfSha256Template();
assertThat(kt.getTypeUrl()).isEqualTo(new HkdfPrfKeyManager().getKeyType());
assertThat(kt.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
HkdfPrfKeyFormat format = HkdfPrfKeyFormat.parseFrom(kt.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(32);
assertThat(format.getParams().getHash()).isEqualTo(HashType.SHA256);
}
Aggregations