Ed25519PrivateKeyManager extends PrivateKeyTypeManager<Ed25519PrivateKey, Ed25519PublicKey> { @Override public void validateKey(Ed25519PrivateKey keyProto) throws GeneralSecurityException { Validators.validateVersion(keyProto.getVersion(), getVersion()); new Ed25519PublicKeyManager().validateKey(keyProto.getPublicKey()); if (keyProto.getKeyValue().size() != Ed25519Sign.SECRET_KEY_LEN) { throw new GeneralSecurityException("invalid Ed25519 private key: incorrect key length"); } } Ed25519PrivateKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override Ed25519PublicKey getPublicKey(Ed25519PrivateKey key); @Override KeyMaterialType keyMaterialType(); @Override Ed25519PrivateKey parseKey(ByteString byteString); @Override void validateKey(Ed25519PrivateKey keyProto); @Override KeyFactory<Ed25519KeyFormat, Ed25519PrivateKey> keyFactory(); static void registerPair(boolean newKeyAllowed); static final KeyTemplate ed25519Template(); static final KeyTemplate rawEd25519Template();  }
@Test public void validateKey_empty_throws() throws Exception { try { manager.validateKey(Ed25519PrivateKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void createKeyThenValidate() throws Exception { manager.validateKey(factory.createKey(Ed25519KeyFormat.getDefaultInstance())); }
@Test public void validateKey_wrongVersion() throws Exception { Ed25519PrivateKey validKey = factory.createKey(Ed25519KeyFormat.getDefaultInstance()); Ed25519PrivateKey invalidKey = Ed25519PrivateKey.newBuilder(validKey).setVersion(1).build(); try { manager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_wrongLength64_throws() throws Exception { Ed25519PrivateKey validKey = factory.createKey(Ed25519KeyFormat.getDefaultInstance()); Ed25519PrivateKey invalidKey = Ed25519PrivateKey.newBuilder(validKey) .setKeyValue(ByteString.copyFrom(Random.randBytes(64))) .build(); try { manager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }