HkdfPrfKeyManager extends KeyTypeManager<HkdfPrfKey> { public static final KeyTemplate hkdfSha256Template() { HkdfPrfKeyFormat format = HkdfPrfKeyFormat.newBuilder() .setKeySize(32) .setParams(HkdfPrfParams.newBuilder().setHash(HashType.SHA256)) .build(); return KeyTemplate.create( HkdfPrfKeyManager.staticKeyType(), format.toByteArray(), KeyTemplate.OutputPrefixType.RAW); } HkdfPrfKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(HkdfPrfKey key); @Override HkdfPrfKey parseKey(ByteString byteString); @Override KeyFactory<HkdfPrfKeyFormat, HkdfPrfKey> keyFactory(); static void register(boolean newKeyAllowed); static String staticKeyType(); static final KeyTemplate hkdfSha256Template();  }
@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); }
@Test public void testKeyTemplateAndManagerCompatibility() throws Exception { HkdfPrfKeyManager manager = new HkdfPrfKeyManager(); testKeyTemplateCompatible(manager, HkdfPrfKeyManager.hkdfSha256Template()); }