Search in sources :

Example 1 with HkdfPrfKeyFormat

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));
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) Test(org.junit.Test)

Example 2 with HkdfPrfKeyFormat

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());
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Example 3 with HkdfPrfKeyFormat

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);
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) Test(org.junit.Test)

Example 4 with HkdfPrfKeyFormat

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));
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) Test(org.junit.Test)

Example 5 with HkdfPrfKeyFormat

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);
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

HkdfPrfKeyFormat (com.google.crypto.tink.proto.HkdfPrfKeyFormat)7 Test (org.junit.Test)7 KeyTemplate (com.google.crypto.tink.KeyTemplate)1 HkdfPrfKey (com.google.crypto.tink.proto.HkdfPrfKey)1