EcdsaVerifyKeyManager extends KeyTypeManager<EcdsaPublicKey> { @Override public void validateKey(EcdsaPublicKey pubKey) throws GeneralSecurityException { Validators.validateVersion(pubKey.getVersion(), getVersion()); SigUtil.validateEcdsaParams(pubKey.getParams()); } EcdsaVerifyKeyManager(); @Override String getKeyType(); @Override int getVersion(); @Override KeyMaterialType keyMaterialType(); @Override EcdsaPublicKey parseKey(ByteString byteString); @Override void validateKey(EcdsaPublicKey pubKey);  }
@Test public void validateKey_usualPublicKey() throws Exception { verifyManager.validateKey( signManager.getPublicKey( createKey(HashType.SHA256, EllipticCurveType.NIST_P256, EcdsaSignatureEncoding.DER))); verifyManager.validateKey( signManager.getPublicKey( createKey( HashType.SHA256, EllipticCurveType.NIST_P256, EcdsaSignatureEncoding.IEEE_P1363))); verifyManager.validateKey( signManager.getPublicKey( createKey(HashType.SHA384, EllipticCurveType.NIST_P384, EcdsaSignatureEncoding.DER))); verifyManager.validateKey( signManager.getPublicKey( createKey( HashType.SHA384, EllipticCurveType.NIST_P384, EcdsaSignatureEncoding.IEEE_P1363))); verifyManager.validateKey( signManager.getPublicKey( createKey(HashType.SHA512, EllipticCurveType.NIST_P384, EcdsaSignatureEncoding.DER))); verifyManager.validateKey( signManager.getPublicKey( createKey( HashType.SHA512, EllipticCurveType.NIST_P384, EcdsaSignatureEncoding.IEEE_P1363))); verifyManager.validateKey( signManager.getPublicKey( createKey(HashType.SHA512, EllipticCurveType.NIST_P521, EcdsaSignatureEncoding.DER))); verifyManager.validateKey( signManager.getPublicKey( createKey( HashType.SHA512, EllipticCurveType.NIST_P521, EcdsaSignatureEncoding.IEEE_P1363))); }
@Test public void validateKey_wrongVersion_throws() throws Exception { EcdsaPublicKey wrongVersionKey = EcdsaPublicKey.newBuilder(validPublicKey()).setVersion(1).build(); try { verifyManager.validateKey(wrongVersionKey); fail(); } catch (GeneralSecurityException e) { } }
@Test public void validateKey_badParams_throws() throws Exception { EcdsaPublicKey validKey = validPublicKey(); EcdsaPublicKey wrongHashKey = EcdsaPublicKey.newBuilder(validKey) .setParams( EcdsaParams.newBuilder(validKey.getParams()) .setHashType(HashType.SHA256) .setCurve(EllipticCurveType.NIST_P521) .build()) .build(); try { verifyManager.validateKey(wrongHashKey); fail(); } catch (GeneralSecurityException e) { } }