gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/02: crypto util test


From: gnunet
Subject: [libeufin] 01/02: crypto util test
Date: Thu, 31 Oct 2019 19:01:24 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

commit 7db6c2a92931d72d35216d923bc02f3a9af005df
Author: Florian Dold <address@hidden>
AuthorDate: Wed Oct 30 20:47:23 2019 +0100

    crypto util test
---
 sandbox/src/test/kotlin/CryptoUtilTest.kt         | 59 +++++++++++++++++++++++
 sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt | 28 -----------
 2 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/sandbox/src/test/kotlin/CryptoUtilTest.kt 
b/sandbox/src/test/kotlin/CryptoUtilTest.kt
new file mode 100644
index 0000000..3ea9cfe
--- /dev/null
+++ b/sandbox/src/test/kotlin/CryptoUtilTest.kt
@@ -0,0 +1,59 @@
+/*
+ * This file is part of LibEuFin.
+ * Copyright (C) 2019 Stanisci and Dold.
+
+ * LibEuFin is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3, or
+ * (at your option) any later version.
+
+ * LibEuFin is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
+ * Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public
+ * License along with LibEuFin; see the file COPYING.  If not, see
+ * <http://www.gnu.org/licenses/>
+ */
+
+package tech.libeufin.sandbox
+
+import org.junit.Test
+import java.security.KeyPairGenerator
+import java.security.interfaces.RSAPrivateCrtKey
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class CryptoUtilTest {
+
+    @Test
+    fun loadFromModulusAndExponent() {
+        val keyPair = CryptoUtil.generateRsaKeyPair(1024)
+        val pub2 = CryptoUtil.loadRsaPublicKeyFromComponents(
+            keyPair.public.modulus.toByteArray(),
+            keyPair.public.publicExponent.toByteArray()
+        )
+        assertEquals(keyPair.public, pub2)
+    }
+
+    @Test
+    fun keyGeneration() {
+        val gen: KeyPairGenerator = KeyPairGenerator.getInstance("RSA")
+        gen.initialize(2048)
+        val pair = gen.genKeyPair()
+        println(pair.private)
+        assertTrue(pair.private is RSAPrivateCrtKey)
+    }
+
+    @Test
+    fun testCryptoUtilBasics() {
+        val keyPair = CryptoUtil.generateRsaKeyPair(1024)
+        val encodedPriv = keyPair.private.encoded
+        val encodedPub = keyPair.public.encoded
+        val otherKeyPair =
+            RsaCrtKeyPair(CryptoUtil.loadRsaPrivateKey(encodedPriv), 
CryptoUtil.loadRsaPublicKey(encodedPub))
+        assertEquals(keyPair.private, otherKeyPair.private)
+        assertEquals(keyPair.public, otherKeyPair.public)
+    }
+}
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt 
b/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt
deleted file mode 100644
index 4dad69c..0000000
--- a/sandbox/src/test/kotlin/GeneratePrivateKeyTest.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package tech.libeufin.sandbox
-
-import org.junit.Test
-import junit.framework.TestCase.assertTrue
-import org.jetbrains.exposed.sql.transactions.transaction
-import org.junit.Before
-import tech.libeufin.sandbox.db.EbicsBankPrivateKey
-import tech.libeufin.sandbox.db.dbCreateTables
-
-class GeneratePrivateKeyTest {
-
-    @Before
-    fun setUp() {
-        dbCreateTables()
-    }
-
-    @Test
-    fun loadOrGeneratePrivateKey() {
-
-        getOrMakePrivateKey()
-
-        assertTrue(
-            transaction {
-                EbicsBankPrivateKey.findById(1)
-            } != null
-        )
-    }
-}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]