Skip to content

Commit

Permalink
fix: create MessageDigest when needed (#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelAndalon authored Jan 3, 2024
1 parent 194328a commit ca81612
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import java.nio.charset.StandardCharsets
import java.security.MessageDigest

internal const val APQ_EXTENSION_KEY: String = "persistedQuery"
internal val MESSAGE_DIGEST: MessageDigest = MessageDigest.getInstance("SHA-256")

@Suppress("UNCHECKED_CAST")
fun ExecutionInput.getAutomaticPersistedQueriesExtension(): AutomaticPersistedQueriesExtension? =
Expand All @@ -34,13 +33,13 @@ fun ExecutionInput.getAutomaticPersistedQueriesExtension(): AutomaticPersistedQu
null
}

fun ExecutionInput.getQueryId(): String =
String.format(
fun ExecutionInput.getQueryId(): String {
val messageDigest = MessageDigest.getInstance("SHA-256")
return String.format(
"%064x",
BigInteger(1, MESSAGE_DIGEST.digest(this.query.toByteArray(StandardCharsets.UTF_8)))
).also {
MESSAGE_DIGEST.reset()
}
BigInteger(1, messageDigest.digest(this.query.toByteArray(StandardCharsets.UTF_8)))
)
}

fun ExecutionInput.isAutomaticPersistedQueriesExtensionInvalid(
extension: AutomaticPersistedQueriesExtension
Expand Down

0 comments on commit ca81612

Please sign in to comment.