|
21 | 21 | import java.security.PublicKey; |
22 | 22 | import java.security.Signature; |
23 | 23 | import java.security.SignatureException; |
| 24 | +import java.security.cert.X509Certificate; |
24 | 25 |
|
25 | 26 | import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; |
26 | 27 | import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; |
|
30 | 31 | import org.junit.Rule; |
31 | 32 | import org.junit.Test; |
32 | 33 | import org.junit.rules.ExpectedException; |
| 34 | +import sun.security.util.DerValue; |
| 35 | +import sun.security.x509.X509Key; |
33 | 36 |
|
34 | 37 | /** |
35 | 38 | * @author str4d |
@@ -213,4 +216,21 @@ public void testVerifyOneShot() throws Exception { |
213 | 216 |
|
214 | 217 | assertThat("verifyOneShot() failed", sgr.verifyOneShot(TEST_MSG, TEST_MSG_SIG), is(true)); |
215 | 218 | } |
| 219 | + |
| 220 | + @Test |
| 221 | + public void testVerifyX509PublicKeyInfo() throws Exception { |
| 222 | + EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("Ed25519"); |
| 223 | + Signature sgr = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm())); |
| 224 | + for (Ed25519TestVectors.TestTuple testCase : Ed25519TestVectors.testCases) { |
| 225 | + EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(testCase.pk, spec); |
| 226 | + PublicKey vKey = new EdDSAPublicKey(pubKey); |
| 227 | + PublicKey x509Key = X509Key.parse(new DerValue(vKey.getEncoded())); |
| 228 | + sgr.initVerify(x509Key); |
| 229 | + |
| 230 | + sgr.update(testCase.message); |
| 231 | + |
| 232 | + assertThat("Test case " + testCase.caseNum + " failed", |
| 233 | + sgr.verify(testCase.sig), is(true)); |
| 234 | + } |
| 235 | + } |
216 | 236 | } |
0 commit comments