summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-06-01 16:13:24 -0300
committerTorsten Grote <t@grobox.de>2020-06-02 09:22:14 -0300
commit75667b9fd2644b737aee17c5c43f1c0f260f7c0d (patch)
tree91f18f4ad25d8aedf43d1aab7e1945b2d1213b92 /src
parentb8b5c986cdd3f50ea4f6e5441e8d8cc41c06ef60 (diff)
downloadwallet-kotlin-75667b9fd2644b737aee17c5c43f1c0f260f7c0d.tar.gz
wallet-kotlin-75667b9fd2644b737aee17c5c43f1c0f260f7c0d.tar.bz2
wallet-kotlin-75667b9fd2644b737aee17c5c43f1c0f260f7c0d.zip
Fix Base32Crockford decoding
and add decoder test for FUCK (which still fails)
Diffstat (limited to 'src')
-rw-r--r--src/commonMain/kotlin/net/taler/wallet/kotlin/Base32Crockford.kt2
-rw-r--r--src/commonTest/kotlin/net/taler/wallet/kotlin/Base32CrockfordTest.kt13
2 files changed, 12 insertions, 3 deletions
diff --git a/src/commonMain/kotlin/net/taler/wallet/kotlin/Base32Crockford.kt b/src/commonMain/kotlin/net/taler/wallet/kotlin/Base32Crockford.kt
index ac49dc6..c966af2 100644
--- a/src/commonMain/kotlin/net/taler/wallet/kotlin/Base32Crockford.kt
+++ b/src/commonMain/kotlin/net/taler/wallet/kotlin/Base32Crockford.kt
@@ -76,7 +76,7 @@ object Base32Crockford {
if (a in '0'..'9')
return a - '0'
if (a in 'a'..'z')
- a.toUpperCase()
+ a = a.toUpperCase()
var dec = 0
if (a in 'A'..'Z') {
if ('I' < a) dec++
diff --git a/src/commonTest/kotlin/net/taler/wallet/kotlin/Base32CrockfordTest.kt b/src/commonTest/kotlin/net/taler/wallet/kotlin/Base32CrockfordTest.kt
index c5940e6..daa505a 100644
--- a/src/commonTest/kotlin/net/taler/wallet/kotlin/Base32CrockfordTest.kt
+++ b/src/commonTest/kotlin/net/taler/wallet/kotlin/Base32CrockfordTest.kt
@@ -1,5 +1,6 @@
package net.taler.wallet.kotlin
+import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -79,10 +80,18 @@ class Base32CrockfordTest {
for (vector in vectors) {
for (encoding in vector.encoding) {
assertTrue(vector.value contentEquals Base32Crockford.decode(encoding))
- // TODO current implementation is throwing [EncodingException] for alternative encodings
- break
}
}
}
+ @Ignore // TODO
+ @Test
+ fun testDecodeFuck() {
+ val bytes = byteArrayOf(0x7e, 0xd9.toByte())
+ assertTrue(bytes contentEquals Base32Crockford.decode("FUCK"))
+ assertTrue(bytes contentEquals Base32Crockford.decode("FuCk"))
+ assertTrue(bytes contentEquals Base32Crockford.decode("fUcK"))
+ assertTrue(bytes contentEquals Base32Crockford.decode("FVCK"))
+ }
+
}