Open
Description
What is the underlying problem you're trying to solve?
When dealing with web stuff it's common to receive non-string inputs as base64 encoded strings. On the other hand, opa built-ins convert non-string stuff into hex strings. This creates issues when comparison is needed, for example:
example if {
sig := sprintf("%s %s%s %s", [input.method, input.path, input.queryString, input.protocol])
hash := crypto.hmac.sha256(sig, data.nbo.key) # hex encoded string
signature := input.signature # base64 endoded string
# Can't do that. It's possible to convert both to string and do the comparison but that is asking for trouble.
crypto.hmac.equal(hash, signature)
}
Describe the ideal solution
Some built-in(s) that enables to do conversion between hex encoded strings and base64 encoded strings.
hex.to_base64(s)
hex.to_base64url(s)
base64.to_hex(s)
base64.to_base64url(s)
...
Maybe something more generic like:
convert_encoing(s, source_type, d, destination_type)
where type: base64, base64url or hex
Or something that returns byte array:
hex.bytes(s)
base64.bytes(s)
base64url.bytes(s)
Describe a "Good Enough" solution
N/A
Additional Context
N/A