[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Add helper function to chunk strings.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Add helper function to chunk strings. |
Date: |
Fri, 08 Nov 2019 17:58:19 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new f1674d9 Add helper function to chunk strings.
f1674d9 is described below
commit f1674d9ca0f2cdf54531b766ab499a721dd867f9
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Nov 8 17:57:40 2019 +0100
Add helper function to chunk strings.
Will be used to format the /keyletter.
---
nexus/src/main/kotlin/Main.kt | 55 +++++++++++++++++++++++++++++++
nexus/src/test/kotlin/LetterFormatTest.kt | 13 ++++++++
2 files changed, 68 insertions(+)
diff --git a/nexus/src/main/kotlin/Main.kt b/nexus/src/main/kotlin/Main.kt
index 3f1d9e7..4c8ef38 100644
--- 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
new file mode 100644
index 0000000..f6a559c
--- /dev/null
+++ 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
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Add helper function to chunk strings.,
gnunet <=