Skip to content

Commit

Permalink
Merge branch 'development' into feature/moreTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Nov 7, 2024
2 parents 59b9c3f + aa7c896 commit 9b88bdf
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ class Asn1IntegerRepresentationTest : FreeSpec({
}
}
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ class Asn1NumberEncodingTest:FreeSpec( {

}

})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.matthewnelson.encoding.core.Decoder.Companion.decodeToByteArray
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.Json

/**
* Representation of a signed JSON Web Signature object, i.e. consisting of header, payload and signature.
*
Expand Down Expand Up @@ -93,18 +94,14 @@ data class JwsSigned<out P : Any>(
plainSignatureInput = it.plainSignatureInput
)
}

/**
* Called by JWS signing implementations to get the string that will be
* used as the input for signature calculation
*/
@Suppress("unused")
inline fun prepareJwsSignatureInput(
header: JwsHeader,
payload: ByteArray,
json: Json = Json,
): ByteArray = ("${header.serialize().encodeToByteArray().encodeToString(Base64UrlStrict)}" +
".${payload.encodeToString(Base64UrlStrict)}").encodeToByteArray()
fun prepareJwsSignatureInput(header: JwsHeader, payload: ByteArray): ByteArray =
(header.serialize().encodeToByteArray().encodeToString(Base64UrlStrict) +
".${payload.encodeToString(Base64UrlStrict)}").encodeToByteArray()

/**
* Called by JWS signing implementations to get the string that will be
Expand All @@ -116,8 +113,7 @@ data class JwsSigned<out P : Any>(
payload: T,
serializer: SerializationStrategy<T>,
json: Json = Json,
): ByteArray = ("${header.serialize().encodeToByteArray().encodeToString(Base64UrlStrict)}" +
".${json.encodeToString(serializer, payload).encodeToByteArray().encodeToString(Base64UrlStrict)}").encodeToByteArray()
): ByteArray = prepareJwsSignatureInput(header, json.encodeToString(serializer, payload).encodeToByteArray())
}
}

2 changes: 1 addition & 1 deletion indispensable/src/commonTest/kotlin/EncodingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class EncodingTest: FreeSpec({
"Correct serialName is determined by encoders" {
ByteArrayBase64UrlSerializer.descriptor.serialName shouldBe "ByteArrayBase64UrlSerializer"
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ class BitLengthTest : FreeSpec({
bitSpacing shouldBe 7u
}
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class ECCurveTest : FreeSpec({
ECCurve.SECP_384_R_1.coordinateLength.bytes shouldBe 48u
ECCurve.SECP_521_R_1.coordinateLength.bytes shouldBe 66u
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ class ECPointTest : FreeSpec({
shouldThrow<IllegalArgumentException> { ECPoint.fromUncompressed(curve, g.xBytes, byteArrayOf(0)) }
}
}
})
})

0 comments on commit 9b88bdf

Please sign in to comment.