commit f1674d9ca0f2cdf54531b766ab499a721dd867f9
parent 0e157a5c06d5080c7b7b527f76483cbb784cd77d
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Fri, 8 Nov 2019 17:57:40 +0100
Add helper function to chunk strings.
Will be used to format the /keyletter.
Diffstat:
2 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
@@ -79,6 +79,35 @@ fun testData() {
}
}
+/**
+ * Inserts spaces every 2 characters.
+ */
+fun chunkString(input: String): String {
+
+ val ret = StringBuilder()
+ var columns = 0
+
+ for (i in input.indices) {
+
+ if ((i + 1).rem(2) == 0) {
+
+ if (columns == 7) {
+ ret.append(input[i] + "\n")
+ columns = 0
+ continue
+ }
+
+ ret.append(input[i] + " ")
+ columns++
+ continue
+ }
+ ret.append(input[i])
+ }
+
+ return ret.toString()
+
+}
+
fun expectId(param: String?) : Int {
try {
@@ -227,6 +256,32 @@ fun main() {
return@get
}
+ get("/ebics/subscribers/{id}/keyletter") {
+
+ val id = expectId(call.parameters["id"])
+ val (signPub, authPub, encPub) = transaction {
+ val subscriber = EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+
+ val signPubTmp = CryptoUtil.getRsaPublicFromPrivate(
+ CryptoUtil.loadRsaPrivateKey(subscriber.signaturePrivateKey.toByteArray())
+ )
+ val authPubTmp = CryptoUtil.getRsaPublicFromPrivate(
+ CryptoUtil.loadRsaPrivateKey(subscriber.authenticationPrivateKey.toByteArray())
+ )
+ val encPubTmp = CryptoUtil.getRsaPublicFromPrivate(
+ CryptoUtil.loadRsaPrivateKey(subscriber.encryptionPrivateKey.toByteArray())
+ )
+
+ Triple(signPubTmp, authPubTmp, encPubTmp)
+ }
+
+ call.respondText(
+ "Not implemented",
+ ContentType.Text.Plain,
+ HttpStatusCode.NotImplemented
+ )
+ }
+
get("/ebics/subscribers") {
val ebicsSubscribers = transaction {
diff --git a/nexus/src/test/kotlin/LetterFormatTest.kt b/nexus/src/test/kotlin/LetterFormatTest.kt
@@ -0,0 +1,13 @@
+package tech.libeufin.nexus
+
+import org.junit.Test
+import tech.libeufin.sandbox.toHexString
+
+class LetterFormatTest {
+
+ @Test
+ fun chunkerTest() {
+ val blob = getNonce(1024)
+ println(chunkString(blob.toHexString()))
+ }
+}
+\ No newline at end of file