From 9af197e5908523b895c715a043b0beed1270fe02 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Tue, 21 Jul 2015 01:19:23 +0000
Subject: [PATCH] Add KeyCert test that fails

---
 .../net/i2p/data/KeyCertificateTest.java      | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 core/java/test/junit/net/i2p/data/KeyCertificateTest.java

diff --git a/core/java/test/junit/net/i2p/data/KeyCertificateTest.java b/core/java/test/junit/net/i2p/data/KeyCertificateTest.java
new file mode 100644
index 0000000000..032b3ef700
--- /dev/null
+++ b/core/java/test/junit/net/i2p/data/KeyCertificateTest.java
@@ -0,0 +1,45 @@
+package net.i2p.data;
+/*
+ * free (adj.): unencumbered; not under the control of others
+ * Written by str4d in 2015 and released into the public domain 
+ * with no warranty of any kind, either expressed or implied.  
+ * It probably won't make your computer catch on fire, or eat 
+ * your children, but it might.  Use at your own risk.
+ *
+ */
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import net.i2p.crypto.EncType;
+import net.i2p.crypto.SigType;
+import junit.framework.TestCase;
+
+/**
+ * @author str4d
+ */
+public class KeyCertificateTest extends TestCase {
+    private static final byte[] P256_PAYLOAD = new byte[] {
+                                    0, (byte) (SigType.ECDSA_SHA256_P256.getCode()),
+                                    0, (byte) (EncType.EC_P256.getCode())
+    };
+
+    private static final byte[] P521_PAYLOAD = new byte[] {
+                                    0, (byte) (SigType.ECDSA_SHA512_P521.getCode()),
+                                    0, (byte) (EncType.ELGAMAL_2048.getCode()),
+                                    0, 0, 0, 0
+    };
+
+    public void testFromP256Payload() throws DataFormatException {
+        KeyCertificate cert = new KeyCertificate(P256_PAYLOAD);
+        assertThat(cert.getSigTypeCode(), is(equalTo(SigType.ECDSA_SHA256_P256.getCode())));
+        assertThat(cert.getCryptoTypeCode(), is(equalTo(EncType.EC_P256.getCode())));
+        assertThat(cert.getExtraSigningKeyData(), is(nullValue()));
+    }
+
+    public void testFromEd25519Payload() throws DataFormatException {
+        KeyCertificate cert = new KeyCertificate(P521_PAYLOAD);
+        assertThat(cert.getSigTypeCode(), is(equalTo(SigType.ECDSA_SHA512_P521.getCode())));
+        assertThat(cert.getCryptoTypeCode(), is(equalTo(EncType.ELGAMAL_2048.getCode())));
+        assertThat(cert.getExtraSigningKeyData().length, is(4));
+    }
+}
\ No newline at end of file
-- 
GitLab