aboutsummaryrefslogtreecommitdiff
path: root/libbutl/base64.hxx
diff options
context:
space:
mode:
authorFrancois Kritzinger <francois@codesynthesis.com>2024-02-06 10:52:18 +0200
committerFrancois Kritzinger <francois@codesynthesis.com>2024-02-09 13:47:53 +0200
commit47767f72b47c9914deaf0de0908f816edfcc9709 (patch)
treed1ecc399ff223215801f106435db80d482e61b27 /libbutl/base64.hxx
parentd249dff880edd1520a979279934afc0a6370bd67 (diff)
Add base64url_encode()
Diffstat (limited to 'libbutl/base64.hxx')
-rw-r--r--libbutl/base64.hxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/libbutl/base64.hxx b/libbutl/base64.hxx
index f38e62f..6f8ef02 100644
--- a/libbutl/base64.hxx
+++ b/libbutl/base64.hxx
@@ -27,6 +27,25 @@ namespace butl
LIBBUTL_SYMEXPORT std::string
base64_encode (const std::vector<char>&);
+ // Encode a stream or a buffer using base64url (RFC 4648), a base64 variant
+ // with different 62nd and 63rd alphabet characters (- and _ instead of ~
+ // and .) to make it filesystem safe, and optional padding because the
+ // padding character `=` would have to be percent-encoded to be safe in
+ // URLs. This implementation does not output any padding, newlines or any
+ // other whitespace in order to conform to RFC7519: JSON Web Token (JWT) and
+ // RFC7515: JSON Web Signature (JWS).
+ //
+ // Note that base64url decoding has not yet been implemented.
+ //
+ LIBBUTL_SYMEXPORT void
+ base64url_encode (std::ostream&, std::istream&);
+
+ LIBBUTL_SYMEXPORT std::string
+ base64url_encode (std::istream&);
+
+ LIBBUTL_SYMEXPORT std::string
+ base64url_encode (const std::vector<char>&);
+
// Base64-decode a stream or a string. Throw invalid_argument if the input
// is not a valid base64 representation. If reading from a stream, check if
// it has badbit, failbit, or eofbit set and throw invalid_argument if