Skip to content

Commit

Permalink
feat: expose chunked signing (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd authored Mar 7, 2022
1 parent 01972f5 commit 7408d64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/common/src/aws/sdk/kotlin/crt/auth/signing/AwsSigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public expect object AwsSigner {
public suspend fun signRequest(request: HttpRequest, config: AwsSigningConfig): HttpRequest

public suspend fun sign(request: HttpRequest, config: AwsSigningConfig): AwsSigningResult

public suspend fun signChunk(chunkBody: ByteArray, prevSignature: ByteArray, config: AwsSigningConfig): AwsSigningResult
}
20 changes: 19 additions & 1 deletion src/jvm/src/aws/sdk/kotlin/crt/auth/signing/AwsSignerJVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package aws.sdk.kotlin.crt.auth.signing

import aws.sdk.kotlin.crt.asyncCrtJniCall
import aws.sdk.kotlin.crt.auth.credentials.JniCredentialsProvider
import aws.sdk.kotlin.crt.http.HttpRequest
import aws.sdk.kotlin.crt.http.*
import aws.sdk.kotlin.crt.http.from
import aws.sdk.kotlin.crt.http.into
import kotlinx.coroutines.future.await
Expand Down Expand Up @@ -50,6 +50,24 @@ public actual object AwsSigner {
AwsSigningResult(signedRequest, jniResult.signature)
}
}

/**
* Signs a body chunk according to the supplied signing configuration
* @param chunkBody the chunk payload to sign
* @param prevSignature the signature of the previous component of the request (either the initial request itself
* for the first chunk or the previous chunk otherwise)
* @param config signing configuration
* @return signing result, which provides access to all signing-related result properties
*/
public actual suspend fun signChunk(chunkBody: ByteArray, prevSignature: ByteArray, config: AwsSigningConfig): AwsSigningResult {
val ktStream = HttpRequestBodyStream.fromByteArray(chunkBody)
val bodyStream = JniRequestBodyStream(ktStream)
return asyncCrtJniCall {
val signFuture = AwsSignerJni.sign(bodyStream, prevSignature, config.into())
val jniResult = signFuture.await()
AwsSigningResult(null, jniResult.signature)
}
}
}

private fun AwsSigningConfig.into(): AwsSigningConfigJni {
Expand Down

0 comments on commit 7408d64

Please sign in to comment.