tdppFormEncode

fun tdppFormEncode(s: String, keepTilde: Boolean): String

Form-encode s for the TDPP signed message (UTF-8, space as '+', upper-case %XX escapes), the same way on every platform.

String.urlEncode() is java.net.URLEncoder on JVM and Android, but ktor's encodeURLParameter on iOS and the other native targets, and the two disagree on '' and '~' (URLEncoder gives "" and "%7E"; ktor, like Python's quote_plus, gives "%2A" and "~"). So a signed request with either character in a value verified on one platform and failed on the other. Signers and verifiers should use this instead of urlEncode() so every service builds the same message.

Parameters

keepTilde

true for the RFC 3986 form ('~' kept, '' escaped), false for the java.net.URLEncoder form ('' kept, '~' escaped)

Throws

if s is not valid UTF-16 (an unpaired surrogate), since JVM and Kotlin/Native would replace it with different bytes ('?' and U+FFFD)