mirror of
https://github.com/matrix-construct/construct
synced 2024-06-01 01:28:54 +02:00
ircd: Add b64 <-> b58 convenience conversion suite.
This commit is contained in:
parent
3badab59a5
commit
a3bcd2dbf3
|
@ -42,6 +42,11 @@ namespace ircd
|
|||
size_t b64decode_size(const string_view &in);
|
||||
const_buffer b64decode(const mutable_buffer &out, const string_view &in);
|
||||
std::string b64decode(const string_view &in);
|
||||
|
||||
// Base64 <-> Base58 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);
|
||||
}
|
||||
|
||||
inline size_t
|
||||
|
|
42
ircd/base.cc
42
ircd/base.cc
|
@ -12,6 +12,48 @@
|
|||
#include <boost/archive/iterators/binary_from_base64.hpp>
|
||||
#include <boost/archive/iterators/transform_width.hpp>
|
||||
|
||||
ircd::string_view
|
||||
ircd::b58tob64_unpadded(const mutable_buffer &out,
|
||||
const string_view &in)
|
||||
{
|
||||
thread_local char tmp[64_KiB];
|
||||
if(unlikely(b58decode_size(in) > size(tmp)))
|
||||
throw error
|
||||
{
|
||||
"String too large for conversion at this time."
|
||||
};
|
||||
|
||||
return b64encode_unpadded(out, b58decode(tmp, in));
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::b58tob64(const mutable_buffer &out,
|
||||
const string_view &in)
|
||||
{
|
||||
thread_local char tmp[64_KiB];
|
||||
if(unlikely(b58decode_size(in) > size(tmp)))
|
||||
throw error
|
||||
{
|
||||
"String too large for conversion at this time."
|
||||
};
|
||||
|
||||
return b64encode(out, b58decode(tmp, in));
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::b64tob58(const mutable_buffer &out,
|
||||
const string_view &in)
|
||||
{
|
||||
thread_local char tmp[64_KiB];
|
||||
if(unlikely(b64decode_size(in) > size(tmp)))
|
||||
throw error
|
||||
{
|
||||
"String too large for conversion at this time."
|
||||
};
|
||||
|
||||
return b58encode(out, b64decode(tmp, in));
|
||||
}
|
||||
|
||||
namespace ircd
|
||||
{
|
||||
const char _b64_pad_
|
||||
|
|
Loading…
Reference in a new issue