AesSivKeyManager extends KeyTypeManager<AesSivKey> { @Override public void validateKey(AesSivKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() != 64) { throw new InvalidKeyException( "invalid key size: " + key.getKeyValue().size() + ". Valid keys must have 64 bytes."); } } 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();  }
@Test public void validateKey_empty() throws Exception { try { new AesSivKeyManager().validateKey(AesSivKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_checkAllLengths() throws Exception { AesSivKeyManager manager = new AesSivKeyManager(); for (int i = 0; i < 100; i++) { if (i == 64) { manager.validateKey(createAesSivKey(i)); } else { try { manager.validateKey(createAesSivKey(i)); fail(); } catch (GeneralSecurityException e) { } } } }
@Test public void validateKey_version() throws Exception { AesSivKeyManager manager = new AesSivKeyManager(); try { manager.validateKey(AesSivKey.newBuilder(createAesSivKey(64)).setVersion(1).build()); fail(); } catch (GeneralSecurityException e) { } }