Skip to content

Commit

Permalink
Replace deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Jul 22, 2024
1 parent ac78e2a commit a124011
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ object AliTranslator : AbstractTranslator(), DocumentationTranslator {
}

private fun signRequest(request: AliMTRequest) {
val requestPayloadHash = request.body.sha256().toLowerCase()
val requestPayloadHash = request.body.sha256().lowercase()
request.headers["x-acs-content-sha256"] = requestPayloadHash

val headers = request.headers
Expand All @@ -154,7 +154,7 @@ object AliTranslator : AbstractTranslator(), DocumentationTranslator {
key.equals("Host", true) ||
key.equals("Content-Type", true)
}
.map { (key, value) -> key.toLowerCase() to value }
.map { (key, value) -> key.lowercase() to value }
.sortedBy { (key) -> key }
val headerNames = headers.joinToString(";") { (key) -> key }
val headerContent = headers.joinToString("\n", postfix = "\n") { (key, value) -> "${key}:$value" }
Expand All @@ -171,12 +171,12 @@ object AliTranslator : AbstractTranslator(), DocumentationTranslator {
|$headerNames
|$requestPayloadHash
""".trimMargin("|")
val requestContentHash = requestContent.sha256().toLowerCase()
val requestContentHash = requestContent.sha256().lowercase()

val settings = Settings.getInstance().aliTranslateSettings
val signature = settings.getAppKey()
.takeIf { it.isNotEmpty() }
?.let { key -> "$SIGNATURE_ALGORITHM\n$requestContentHash".hmacSha256(key).toLowerCase() }
?.let { key -> "$SIGNATURE_ALGORITHM\n$requestContentHash".hmacSha256(key).lowercase() }
?: ""
val authorization =
"$SIGNATURE_ALGORITHM Credential=${settings.appId},SignedHeaders=$headerNames,Signature=$signature"
Expand Down

0 comments on commit a124011

Please sign in to comment.