This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ddc8f
commit 992a2d1
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
kmp-advcrypto/src/linuxX64Test/kotlin/io/karma/advcrypto/linux/tests/KeyReaderHelperTests.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,73 @@ | ||
package io.karma.advcrypto.linux.tests | ||
|
||
import io.karma.advcrypto.keys.Key | ||
import io.karma.advcrypto.keys.enum.KeyFormat | ||
import io.karma.advcrypto.keys.enum.KeyType | ||
import io.karma.advcrypto.linux.utils.KeyReaderHelper | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.addressOf | ||
import kotlinx.cinterop.usePinned | ||
import okio.FileSystem | ||
import okio.Path.Companion.toPath | ||
import kotlin.experimental.ExperimentalNativeApi | ||
import kotlin.test.Test | ||
|
||
@OptIn(ExperimentalForeignApi::class, ExperimentalNativeApi::class) | ||
class KeyReaderHelperTests { | ||
private val fileSystem = FileSystem.SYSTEM | ||
|
||
@Test | ||
fun testPEM() { | ||
fileSystem.read("./testkeys/rsa-private-key.pem".toPath()) { | ||
val byteArray = readByteArray() | ||
val size = byteArray.size.toULong() | ||
byteArray.usePinned { array -> | ||
val key = KeyReaderHelper.tryParse(array.addressOf(0), size, Key.PURPOSES_ALL)!! | ||
assert(key.algorithm == "RSA") | ||
assert(key.format == KeyFormat.PEM) | ||
assert(key.type == KeyType.PRIVATE) | ||
} | ||
close() | ||
} | ||
|
||
fileSystem.read("./testkeys/rsa-public-key.pem".toPath()) { | ||
val byteArray = readByteArray() | ||
val size = byteArray.size.toULong() | ||
byteArray.usePinned { array -> | ||
val key = KeyReaderHelper.tryParse(array.addressOf(0), size, Key.PURPOSES_ALL)!! | ||
assert(key.algorithm == "RSA") | ||
assert(key.format == KeyFormat.PEM) | ||
assert(key.type == KeyType.PUBLIC) | ||
} | ||
close() | ||
} | ||
} | ||
|
||
@Test | ||
fun testDER() { | ||
fileSystem.read("./testkeys/rsa-private-key.der".toPath()) { | ||
val byteArray = readByteArray() | ||
val size = byteArray.size.toULong() | ||
byteArray.usePinned { array -> | ||
val key = KeyReaderHelper.tryParse(array.addressOf(0), size, Key.PURPOSES_ALL)!! | ||
assert(key.algorithm == "RSA") | ||
assert(key.format == KeyFormat.DER) | ||
assert(key.type == KeyType.PRIVATE) | ||
} | ||
close() | ||
} | ||
|
||
fileSystem.read("./testkeys/rsa-public-key.der".toPath()) { | ||
val byteArray = readByteArray() | ||
val size = byteArray.size.toULong() | ||
byteArray.usePinned { array -> | ||
val key = KeyReaderHelper.tryParse(array.addressOf(0), size, Key.PURPOSES_ALL)!! | ||
assert(key.algorithm == "RSA") | ||
assert(key.format == KeyFormat.DER) | ||
assert(key.type == KeyType.PUBLIC) | ||
} | ||
close() | ||
} | ||
} | ||
|
||
} |
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 @@ | ||
These keys are only used to test the key reader. Don't use these keys in real-world applications! |
Binary file not shown.
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDRL2KirGInFB9R | ||
bDN5quewxjY6wC2IkSmPSiZq75p7aLegCiuaKCowdfTD6fUrLBuf/w2qgI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ZqkGqTT+GP | ||
dkh34/BtfR4zipHhQ7Be/44UVw/WYRFtMaKq/lG8Okevd/+DsF0w5AFUPVlxAozk | ||
FPt/MedbZBNl/ZG6DIXJKkAxJUuMrZXwUsOAUrA+UHWy6INAdGnAPPPjIQKBgQDU | ||
JpngWgAnMcLkOsUJ0Z32HP9LP5mqUvYMAwkBoNvl0bd0iRXuwPQIQV2fy/m27iKW | ||
GFqMFKNWBkxs3wfWhhWRWIBDiET9++LH5l50N7H8BTnfFujGYLNhql4+sLQWtN9m | ||
LMk/y/RiQF0cGuF1T6jzuV/cbT4Un2t3oRq7emEe7wKBgQCxzcc2KAjM4YvkVnUZ | ||
X4yb5+LSb/z5p7ekrQrr+jrHBiketzyeGDqYTEYRDYnUb4KwO1XNPob6T2dqfpHA | ||
om5+Mj8n64SkX7n56qXnupmTGqAXl1XnJFkCqlHBQHVjWhbhMJmEb13+iyCzGVgn | ||
G/YpJeIggEz7BaVSfqqXAY1SJQ== | ||
-----END PRIVATE KEY----- |
Binary file not shown.
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,9 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0S9ioqxiJxQfUWwzearn | ||
sMY2OsAtiJEpj0omau+ae2i3oAormigqMHX0w+n1Kywbn/8NqoCKI9eSnEUCM2Zf | ||
TGDMzXPAT2P66yhO3fPNOmi6bfURM412jLsyp5PBaBIbFncWDGlj0JPiZMB4eIqL | ||
MfoHE481h1fo7QpGbff+si30EbIVXpzwe2BIMoCVRDsKTU5yAlVYDgMLMxh8lXXo | ||
txxBLGrToV+K4z42MfFdT0FTqwJ+Jdtx7LCYRsPoeP9MJqrylY0//Drk8nwAMH/K | ||
M5oxLswNjjcpiYnj/B1Wwz50DQDtFH3xXceU7/udNG+hP6QQR8zn1zpIO9AiTapY | ||
QwIDAQAB | ||
-----END PUBLIC KEY----- |