@Test public void validateKeyFormat_notValid_throws() throws Exception { AesCmacKeyManager manager = new AesCmacKeyManager(); try { manager.keyFactory().validateKeyFormat(makeAesCmacKeyFormat(32, 9)); fail(); } catch (GeneralSecurityException e) { } try { manager.keyFactory().validateKeyFormat(makeAesCmacKeyFormat(32, 17)); fail(); } catch (GeneralSecurityException e) { } try { manager.keyFactory().validateKeyFormat(makeAesCmacKeyFormat(32, 32)); fail(); } catch (GeneralSecurityException e) { } try { manager.keyFactory().validateKeyFormat(makeAesCmacKeyFormat(16, 16)); fail(); } catch (GeneralSecurityException e) { } try { manager.keyFactory().validateKeyFormat(makeAesCmacKeyFormat(64, 16)); fail(); } catch (GeneralSecurityException e) { } }
@Override public KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory() { return new KeyFactory<AesCmacKeyFormat, AesCmacKey>(AesCmacKeyFormat.class) { @Override public void validateKeyFormat(AesCmacKeyFormat format) throws GeneralSecurityException { validateParams(format.getParams()); validateSize(format.getKeySize()); } @Override public AesCmacKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacKey createKey(AesCmacKeyFormat format) throws GeneralSecurityException { return AesCmacKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setParams(format.getParams()) .build(); } }; }
AesCmacKeyManager extends KeyTypeManager<AesCmacKey> { @Override public KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory() { return new KeyFactory<AesCmacKeyFormat, AesCmacKey>(AesCmacKeyFormat.class) { @Override public void validateKeyFormat(AesCmacKeyFormat format) throws GeneralSecurityException { validateParams(format.getParams()); validateSize(format.getKeySize()); } @Override public AesCmacKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacKey createKey(AesCmacKeyFormat format) throws GeneralSecurityException { return AesCmacKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setParams(format.getParams()) .build(); } }; } }
AesCmacKeyManager extends KeyTypeManager<AesCmacKey> { @Override public KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory() { return new KeyFactory<AesCmacKeyFormat, AesCmacKey>(AesCmacKeyFormat.class) { @Override public void validateKeyFormat(AesCmacKeyFormat format) throws GeneralSecurityException { validateParams(format.getParams()); validateSize(format.getKeySize()); } @Override public AesCmacKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacKey createKey(AesCmacKeyFormat format) throws GeneralSecurityException { return AesCmacKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setParams(format.getParams()) .build(); } }; } AesCmacKeyManager(); }
AesCmacKeyManager extends KeyTypeManager<AesCmacKey> { @Override public KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory() { return new KeyFactory<AesCmacKeyFormat, AesCmacKey>(AesCmacKeyFormat.class) { @Override public void validateKeyFormat(AesCmacKeyFormat format) throws GeneralSecurityException { validateParams(format.getParams()); validateSize(format.getKeySize()); } @Override public AesCmacKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacKey createKey(AesCmacKeyFormat format) throws GeneralSecurityException { return AesCmacKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setParams(format.getParams()) .build(); } }; } AesCmacKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesCmacKey key); @Override AesCmacKey parseKey(ByteString byteString); @Override KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256CmacTemplate(); static final KeyTemplate rawAes256CmacTemplate(); }
AesCmacKeyManager extends KeyTypeManager<AesCmacKey> { @Override public KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory() { return new KeyFactory<AesCmacKeyFormat, AesCmacKey>(AesCmacKeyFormat.class) { @Override public void validateKeyFormat(AesCmacKeyFormat format) throws GeneralSecurityException { validateParams(format.getParams()); validateSize(format.getKeySize()); } @Override public AesCmacKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesCmacKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesCmacKey createKey(AesCmacKeyFormat format) throws GeneralSecurityException { return AesCmacKey.newBuilder() .setVersion(VERSION) .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setParams(format.getParams()) .build(); } }; } AesCmacKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesCmacKey key); @Override AesCmacKey parseKey(ByteString byteString); @Override KeyFactory<AesCmacKeyFormat, AesCmacKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256CmacTemplate(); static final KeyTemplate rawAes256CmacTemplate();  }