mirror of
https://github.com/corda/corda.git
synced 2025-03-21 03:25:43 +00:00
CORDA-1009 Remove X509EdDSAEngine dependency on X509Key (#2506)
This commit is contained in:
parent
1487c411b4
commit
fa4b5d16ba
@ -27,12 +27,11 @@ class X509EdDSAEngine : Signature {
|
||||
override fun engineInitSign(privateKey: PrivateKey, random: SecureRandom) = engine.initSign(privateKey, random)
|
||||
|
||||
override fun engineInitVerify(publicKey: PublicKey) {
|
||||
val parsedKey = if (publicKey is sun.security.x509.X509Key) {
|
||||
EdDSAPublicKey(X509EncodedKeySpec(publicKey.encoded))
|
||||
} else {
|
||||
publicKey
|
||||
val parsedKey = try {
|
||||
publicKey as? EdDSAPublicKey ?: EdDSAPublicKey(X509EncodedKeySpec(publicKey.encoded))
|
||||
} catch(e: Exception) {
|
||||
throw (InvalidKeyException(e.message))
|
||||
}
|
||||
|
||||
engine.initVerify(parsedKey)
|
||||
}
|
||||
|
||||
|
@ -114,4 +114,12 @@ class X509EdDSAEngineTest {
|
||||
engine.verify(signature)
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify will fail if the input public key cannot be converted to EdDSA public key. */
|
||||
@Test
|
||||
fun `verify with non-supported key type fails`() {
|
||||
val engine = EdDSAEngine()
|
||||
val keyPair = Crypto.deriveKeyPairFromEntropy(Crypto.ECDSA_SECP256K1_SHA256, BigInteger.valueOf(SEED))
|
||||
assertFailsWith<InvalidKeyException> { engine.initVerify(keyPair.public) }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user