@Test public void validateKeyFormat_checkAllLengths() throws Exception { AesSivKeyManager manager = new AesSivKeyManager(); for (int i = 0; i < 100; i++) { if (i == 64) { manager.keyFactory().validateKeyFormat(createAesSivKeyFormat(i)); } else { try { manager.keyFactory().validateKeyFormat(createAesSivKeyFormat(i)); fail(); } catch (GeneralSecurityException e) { } } } }
@Override public KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory() { return new KeyFactory<AesSivKeyFormat, AesSivKey>(AesSivKeyFormat.class) { @Override public void validateKeyFormat(AesSivKeyFormat format) throws GeneralSecurityException { if (format.getKeySize() != 64) { throw new InvalidAlgorithmParameterException( "invalid key size: " + format.getKeySize() + ". Valid keys must have 64 bytes."); } } @Override public AesSivKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesSivKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesSivKey createKey(AesSivKeyFormat format) throws GeneralSecurityException { return AesSivKey.newBuilder() .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(getVersion()) .build(); } }; }
AesSivKeyManager extends KeyTypeManager<AesSivKey> { @Override public KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory() { return new KeyFactory<AesSivKeyFormat, AesSivKey>(AesSivKeyFormat.class) { @Override public void validateKeyFormat(AesSivKeyFormat format) throws GeneralSecurityException { if (format.getKeySize() != 64) { throw new InvalidAlgorithmParameterException( "invalid key size: " + format.getKeySize() + ". Valid keys must have 64 bytes."); } } @Override public AesSivKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesSivKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesSivKey createKey(AesSivKeyFormat format) throws GeneralSecurityException { return AesSivKey.newBuilder() .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(getVersion()) .build(); } }; } }
AesSivKeyManager extends KeyTypeManager<AesSivKey> { @Override public KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory() { return new KeyFactory<AesSivKeyFormat, AesSivKey>(AesSivKeyFormat.class) { @Override public void validateKeyFormat(AesSivKeyFormat format) throws GeneralSecurityException { if (format.getKeySize() != 64) { throw new InvalidAlgorithmParameterException( "invalid key size: " + format.getKeySize() + ". Valid keys must have 64 bytes."); } } @Override public AesSivKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesSivKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesSivKey createKey(AesSivKeyFormat format) throws GeneralSecurityException { return AesSivKey.newBuilder() .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(getVersion()) .build(); } }; } AesSivKeyManager(); }
AesSivKeyManager extends KeyTypeManager<AesSivKey> { @Override public KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory() { return new KeyFactory<AesSivKeyFormat, AesSivKey>(AesSivKeyFormat.class) { @Override public void validateKeyFormat(AesSivKeyFormat format) throws GeneralSecurityException { if (format.getKeySize() != 64) { throw new InvalidAlgorithmParameterException( "invalid key size: " + format.getKeySize() + ". Valid keys must have 64 bytes."); } } @Override public AesSivKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesSivKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesSivKey createKey(AesSivKeyFormat format) throws GeneralSecurityException { return AesSivKey.newBuilder() .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(getVersion()) .build(); } }; } AesSivKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesSivKey key); @Override AesSivKey parseKey(ByteString byteString); @Override KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256SivTemplate(); static final KeyTemplate rawAes256SivTemplate(); }
AesSivKeyManager extends KeyTypeManager<AesSivKey> { @Override public KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory() { return new KeyFactory<AesSivKeyFormat, AesSivKey>(AesSivKeyFormat.class) { @Override public void validateKeyFormat(AesSivKeyFormat format) throws GeneralSecurityException { if (format.getKeySize() != 64) { throw new InvalidAlgorithmParameterException( "invalid key size: " + format.getKeySize() + ". Valid keys must have 64 bytes."); } } @Override public AesSivKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException { return AesSivKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry()); } @Override public AesSivKey createKey(AesSivKeyFormat format) throws GeneralSecurityException { return AesSivKey.newBuilder() .setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))) .setVersion(getVersion()) .build(); } }; } AesSivKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(AesSivKey key); @Override AesSivKey parseKey(ByteString byteString); @Override KeyFactory<AesSivKeyFormat, AesSivKey> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate aes256SivTemplate(); static final KeyTemplate rawAes256SivTemplate();  }