-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
2 changed files
with
61 additions
and
7 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
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 |
---|---|---|
|
@@ -192,9 +192,11 @@ private fun AwsSigningConfig.toNativeSigningConfig(): CPointer<aws_signing_confi | |
service.initFromCursor(this@toNativeSigningConfig.service.toAwsString().asAwsByteCursor()) | ||
aws_date_time_init_epoch_millis(date.ptr, this@toNativeSigningConfig.date.toULong()) | ||
|
||
// FIXME Can't convert Kotlin config's shouldSignHeader to a C function without capturing the config variable, and staticCFunction cannot capture variables. | ||
// should_sign_header = [email protected]?.toNativeShouldSignHeaderFn() | ||
// should_sign_header_ud = | ||
this@toNativeSigningConfig.shouldSignHeader?.let { | ||
val shouldSignHeaderStableRef = StableRef.create(it) | ||
should_sign_header = staticCFunction(::nativeShouldSignHeaderFn) | ||
should_sign_header_ud = shouldSignHeaderStableRef.asCPointer() | ||
} | ||
|
||
flags.use_double_uri_encode = if (this@toNativeSigningConfig.useDoubleUriEncode) 1u else 0u | ||
flags.should_normalize_uri_path = if (this@toNativeSigningConfig.normalizeUriPath) 1u else 0u | ||
|
@@ -215,6 +217,16 @@ private fun AwsSigningConfig.toNativeSigningConfig(): CPointer<aws_signing_confi | |
return config.ptr | ||
} | ||
|
||
private typealias ShouldSignHeaderFunction = (String) -> Boolean | ||
private fun nativeShouldSignHeaderFn(headerName: CPointer<aws_byte_cursor>?, userData: COpaquePointer?): Boolean { | ||
checkNotNull(headerName) { "aws_should_sign_header_fn expected non-null header name" } | ||
if (userData == null) { return true } | ||
|
||
val kShouldSignHeaderFn = userData.asStableRef<ShouldSignHeaderFunction>().get() | ||
val kHeaderName = headerName.pointed.toKString() | ||
return kShouldSignHeaderFn(kHeaderName) | ||
} | ||
|
||
/** | ||
* Callback for standard request signing. Applies the given signing result to the HTTP message and then returns the | ||
* signature via callback channel. | ||
|