This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Base64 decode when no padding is provided (#37)
* Add tests from Korio + add test reproducing and fixing the issue #64 * Fixes Base64 decoding when no padding is provided
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
krypto/src/commonTest/kotlin/com/soywiz/krypto/Base64Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.soywiz.krypto | ||
|
||
import com.soywiz.krypto.encoding.Base64 | ||
import com.soywiz.krypto.encoding.fromBase64 | ||
import com.soywiz.krypto.encoding.toBase64 | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class Base64Test { | ||
@Test | ||
fun name() { | ||
assertEquals("AQID", Base64.encode(byteArrayOf(1, 2, 3))) | ||
assertEquals("aGVsbG8=", Base64.encode("hello".encodeToByteArray())) | ||
assertEquals(byteArrayOf(1, 2, 3).toList(), Base64.decode("AQID").toList()) | ||
assertEquals("hello", Base64.decode("aGVsbG8=").decodeToString()) | ||
} | ||
|
||
@Test | ||
fun testSeveral() { | ||
for (item in listOf("", "a", "aa", "aaa", "aaaa", "aaaaa", "Hello World!")) { | ||
assertEquals(item, item.encodeToByteArray().toBase64().fromBase64().decodeToString()) | ||
} | ||
} | ||
|
||
@Test | ||
fun testGlobal() { | ||
assertEquals("hello", globalBase64) | ||
assertEquals("hello", ObjectBase64.globalBase64) | ||
} | ||
|
||
@Test | ||
fun testIssue64DecodeWithMissingPadding() { | ||
assertEquals( | ||
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ==", | ||
Base64.encode(Base64.decode("eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ")) | ||
) | ||
} | ||
} | ||
|
||
object ObjectBase64 { | ||
val globalBase64 = "aGVsbG8=".fromBase64().decodeToString() | ||
} | ||
|
||
val globalBase64 = "aGVsbG8=".fromBase64().decodeToString() |