mirror of
https://github.com/matrix-construct/construct
synced 2024-10-31 19:08:59 +01:00
ircd: Add RFC4648 base64url conversion suite.
This commit is contained in:
parent
19b85ef908
commit
5500a897e9
2 changed files with 25 additions and 1 deletions
|
@ -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
|
||||
|
|
22
ircd/base.cc
22
ircd/base.cc
|
@ -12,6 +12,28 @@
|
|||
#include <boost/archive/iterators/binary_from_base64.hpp>
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue