diff --git a/include/ircd/base.h b/include/ircd/base.h index f3487272d..a6013774b 100644 --- a/include/ircd/base.h +++ b/include/ircd/base.h @@ -43,10 +43,12 @@ namespace ircd const_buffer b64decode(const mutable_buffer &out, const string_view &in); std::string b64decode(const string_view &in); - // Base64 <-> Base58 convenience conversions + // Base64 convenience conversions string_view b64tob58(const mutable_buffer &out, const string_view &in); string_view b58tob64(const mutable_buffer &out, const string_view &in); string_view b58tob64_unpadded(const mutable_buffer &out, const string_view &in); + string_view b64tob64url(const mutable_buffer &out, const string_view &in); + string_view b64urltob64(const mutable_buffer &out, const string_view &in); } inline size_t diff --git a/ircd/base.cc b/ircd/base.cc index abc72fcda..4f7da8ceb 100644 --- a/ircd/base.cc +++ b/ircd/base.cc @@ -12,6 +12,28 @@ #include #include +ircd::string_view +ircd::b64urltob64(const mutable_buffer &out, + const string_view &in) +{ + //TODO: optimize with single pass + string_view ret(in); + ret = replace(out, ret, '-', '+'); + ret = replace(out, ret, '_', '/'); + return ret; +} + +ircd::string_view +ircd::b64tob64url(const mutable_buffer &out, + const string_view &in) +{ + //TODO: optimize with single pass + string_view ret(in); + ret = replace(out, ret, '+', '-'); + ret = replace(out, ret, '/', '_'); + return ret; +} + ircd::string_view ircd::b58tob64_unpadded(const mutable_buffer &out, const string_view &in)