ChaCha20Poly1305KeyManager extends KeyTypeManager<ChaCha20Poly1305Key> { @Override public void validateKey(ChaCha20Poly1305Key key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); if (key.getKeyValue().size() != KEY_SIZE_IN_BYTES) { throw new GeneralSecurityException("invalid ChaCha20Poly1305Key: incorrect key length"); } } ChaCha20Poly1305KeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override void validateKey(ChaCha20Poly1305Key key); @Override ChaCha20Poly1305Key parseKey(ByteString byteString); @Override KeyFactory<ChaCha20Poly1305KeyFormat, ChaCha20Poly1305Key> keyFactory(); static void register(boolean newKeyAllowed); static final KeyTemplate chaCha20Poly1305Template(); static final KeyTemplate rawChaCha20Poly1305Template();  }
@Test public void validateKey_empty() throws Exception { try { new ChaCha20Poly1305KeyManager().validateKey(ChaCha20Poly1305Key.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_checkAllLengths() throws Exception { ChaCha20Poly1305KeyManager manager = new ChaCha20Poly1305KeyManager(); for (int i = 0; i < 100; i++) { if (i == 32) { manager.validateKey(createChaCha20Poly1305Key(i)); } else { try { manager.validateKey(createChaCha20Poly1305Key(i)); fail(); } catch (GeneralSecurityException e) { } } } }
@Test public void validateKey_version() throws Exception { ChaCha20Poly1305KeyManager manager = new ChaCha20Poly1305KeyManager(); try { manager.validateKey( ChaCha20Poly1305Key.newBuilder(createChaCha20Poly1305Key(32)).setVersion(1).build()); fail(); } catch (GeneralSecurityException e) { } }