Skip to content

Commit

Permalink
test fixes (incomplete)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Sep 15, 2023
1 parent 737a9ed commit ed44d42
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/id/walt/crypto/CryptFun.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fun buildKey(
keyId: String,
algorithm: String,
provider: String,
publicPart: String?,
publicPart: String,
privatePart: String?,
format: KeyFormat = KeyFormat.PEM
): Key {
Expand All @@ -179,15 +179,15 @@ fun buildKey(
}
val keyPair = when (format) {
KeyFormat.PEM -> KeyPair(
publicPart?.let { decodePubKeyPem(it, keyFactory) },
decodePubKeyPem(publicPart, keyFactory),
privatePart?.let { decodePrivKeyPem(it, keyFactory) })

KeyFormat.BASE64_DER -> KeyPair(
publicPart?.let { decodePubKeyBase64(it, keyFactory) },
decodePubKeyBase64(publicPart, keyFactory),
privatePart?.let { decodePrivKeyBase64(it, keyFactory) })

KeyFormat.BASE64_RAW -> KeyPair(
publicPart?.let { decodeRawPubKeyBase64(it, keyFactory) },
decodeRawPubKeyBase64(publicPart, keyFactory),
privatePart?.let { decodeRawPrivKey(it, keyFactory) })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ open class HKVKeyStoreService : KeyStoreService() {
val algorithm = metaData.substringBefore(delimiter = ";")
val provider = metaData.substringAfter(delimiter = ";")

val publicPart = if (keyType == KeyType.PUBLIC) loadKey(keyId, "enc-pubkey").decodeToString() else null
val publicPart = loadKey(keyId, "enc-pubkey").decodeToString()
val privatePart = if (keyType == KeyType.PRIVATE) loadKey(keyId, "enc-privkey").decodeToString() else null


Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/id/walt/cli/DidCommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DidCommandTest : StringSpec({
var didKeyRsa: String? = null
"5. Create did:web RSA" {
rsaKeyId = KeyService.getService()
.importKey(readWhenContent(Path.of("src/test/resources/key/rsa.pem")))
.importKey(readWhenContent(Path.of("src/test/resources/key/pem/rsa/rsa.pem")))

CreateDidCommand().parse(listOf("-m", "web", "-k", rsaKeyId!!.id, "test-dest.json"))
/*didWebRsa = Path.of("test-dest.json")
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/id/walt/cli/KeyCommandTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class KeyCommandTest : StringSpec({
// Ed25519 pub key JWK
row("src/test/resources/cli/pubKeyEd25519Jwk.json", "12374a4ac169f7f4716804393d20480138a"),
// RSA key PEM
row("src/test/resources/key/rsa.pem", ""),
row("src/test/resources/key/pem/rsa/rsa.pem", ""),
// Secp256k1 key PEM
row("src/test/resources/key/secp256k1.pem", ""),
row("src/test/resources/key/pem/ecdsa/secp256k1.pem", ""),
// Ed25519 key PEM
row("src/test/resources/key/secp256k1.pem", ""),
row("src/test/resources/key/pem/ed25519/ed25519.pem", ""),
// RSA priv key JWK
row("src/test/resources/key/privkey.jwk", ""),
// Secp256k1 priv key JWK
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/id/walt/rest/CustodianApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ class CustodianApiTest : StringSpec({
"Test import key PEM" {
forAll(
// RSA PEM
row(readWhenContent(File("src/test/resources/key/rsa.pem"))),
row(readWhenContent(File("src/test/resources/key/pem/rsa/rsa.pem"))),
// Ed25519 PEM
row(readWhenContent(File("src/test/resources/key/ed25519.pem"))),
row(readWhenContent(File("src/test/resources/key/pem/ed25519/ed25519.pem"))),
// Secp256k1 PEM
row(readWhenContent(File("src/test/resources/key/secp256k1.pem"))),
row(readWhenContent(File("src/test/resources/key/pem/ecdsa/secp256k1.pem"))),
) { keyStr ->
runBlocking {
val response =
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/id/walt/services/key/KeyServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class KeyServiceTest : AnnotationSpec() {
// Ed25519
row(File("src/test/resources/key/pem/ed25519/ed25519.pem").readText(), 0x11),
row(File("src/test/resources/key/pem/ed25519/ed25519.public.pem").readText(), 0x10),
row(File("src/test/resources/key/pem/ed25519/ed25519.private.pem").readText(), 0x01),
// row(File("src/test/resources/key/pem/ed25519/ed25519.private.pem").readText(), 0x01),
// Secp256k1
row(File("src/test/resources/key/pem/ecdsa/secp256k1.pem").readText(), 0x11),
row(File("src/test/resources/key/pem/ecdsa/secp256k1.public.pem").readText(), 0x10),
Expand Down

0 comments on commit ed44d42

Please sign in to comment.