EciesAeadHkdfPublicKeyManager extends KeyTypeManager<EciesAeadHkdfPublicKey> { @Override public void validateKey(EciesAeadHkdfPublicKey key) throws GeneralSecurityException { Validators.validateVersion(key.getVersion(), getVersion()); HybridUtil.validate(key.getParams()); } EciesAeadHkdfPublicKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override EciesAeadHkdfPublicKey parseKey(ByteString byteString); @Override void validateKey(EciesAeadHkdfPublicKey key);  }
@Test public void validateKey_empty_throws() throws Exception { try { publicManager.validateKey(EciesAeadHkdfPublicKey.getDefaultInstance()); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_valid() throws Exception { EciesAeadHkdfPrivateKey privateKey = createValidPrivateKey(); publicManager.validateKey(privateManager.getPublicKey(privateKey)); }
@Test public void validateKey_invalidWrongVersion_throws() throws Exception { EciesAeadHkdfPrivateKey privateKey = createValidPrivateKey(); EciesAeadHkdfPublicKey publicKey = privateManager.getPublicKey(privateKey); EciesAeadHkdfPublicKey invalidKey = EciesAeadHkdfPublicKey.newBuilder().setVersion(1).build(); try { publicManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_invalidPointFormat_throws() throws Exception { EciesAeadHkdfPrivateKey privateKey = createValidPrivateKey(); EciesAeadHkdfPublicKey publicKey = privateManager.getPublicKey(privateKey); EciesAeadHkdfPublicKey invalidKey = EciesAeadHkdfPublicKey.newBuilder() .setParams( createKeyFormat( EllipticCurveType.NIST_P256, HashType.SHA256, EcPointFormat.UNKNOWN_FORMAT, AeadKeyTemplates.AES128_CTR_HMAC_SHA256, "some salt".getBytes("UTF-8")) .getParams()).build(); try { publicManager.validateKey(invalidKey); fail(); } catch (GeneralSecurityException e) { } }