Ed25519PublicKeyManager extends KeyTypeManager<Ed25519PublicKey> { @Override public void validateKey(Ed25519PublicKey keyProto) throws GeneralSecurityException { Validators.validateVersion(keyProto.getVersion(), getVersion()); if (keyProto.getKeyValue().size() != Ed25519Verify.PUBLIC_KEY_LEN) { throw new GeneralSecurityException("invalid Ed25519 public key: incorrect key length"); } } Ed25519PublicKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override Ed25519PublicKey parseKey(ByteString byteString); @Override void validateKey(Ed25519PublicKey keyProto);  }
@Test public void validateKey_empty_throws() throws Exception { try { verifyManager.validateKey(Ed25519PublicKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey() throws Exception { Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey()); verifyManager.validateKey(publicKey); }
@Test public void validateKey_wrongVersion() throws Exception { Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey()); Ed25519PublicKey invalidKey = Ed25519PublicKey.newBuilder(publicKey).setVersion(1).build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_wrongLength31_throws() throws Exception { Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey()); Ed25519PublicKey invalidKey = Ed25519PublicKey.newBuilder(publicKey) .setKeyValue(ByteString.copyFrom(Random.randBytes(31))) .build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_wrongLength64_throws() throws Exception { Ed25519PublicKey publicKey = signManager.getPublicKey(createPrivateKey()); Ed25519PublicKey invalidKey = Ed25519PublicKey.newBuilder(publicKey) .setKeyValue(ByteString.copyFrom(Random.randBytes(64))) .build(); try { verifyManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }