mirror of
https://github.com/matrix-construct/construct
synced 2024-12-29 08:54:02 +01:00
ircd: Add some b64 size expression utils.
This commit is contained in:
parent
2557834a96
commit
3badab59a5
1 changed files with 42 additions and 0 deletions
|
@ -26,18 +26,60 @@ namespace ircd
|
||||||
std::string b58decode(const string_view &in);
|
std::string b58decode(const string_view &in);
|
||||||
|
|
||||||
// Binary -> Base64 conversion suite
|
// Binary -> Base64 conversion suite
|
||||||
|
constexpr size_t b64encode_size(const size_t &);
|
||||||
|
size_t b64encode_size(const const_buffer &in);
|
||||||
string_view b64encode(const mutable_buffer &out, const const_buffer &in);
|
string_view b64encode(const mutable_buffer &out, const const_buffer &in);
|
||||||
std::string b64encode(const const_buffer &in);
|
std::string b64encode(const const_buffer &in);
|
||||||
|
|
||||||
// Binary -> Base64 conversion without padding
|
// Binary -> Base64 conversion without padding
|
||||||
|
constexpr size_t b64encode_unpadded_size(const size_t &);
|
||||||
|
size_t b64encode_unpadded_size(const const_buffer &in);
|
||||||
string_view b64encode_unpadded(const mutable_buffer &out, const const_buffer &in);
|
string_view b64encode_unpadded(const mutable_buffer &out, const const_buffer &in);
|
||||||
std::string b64encode_unpadded(const const_buffer &in);
|
std::string b64encode_unpadded(const const_buffer &in);
|
||||||
|
|
||||||
// Base64 -> Binary conversion (padded or unpadded)
|
// Base64 -> Binary conversion (padded or unpadded)
|
||||||
|
constexpr size_t b64decode_size(const size_t &);
|
||||||
|
size_t b64decode_size(const string_view &in);
|
||||||
const_buffer b64decode(const mutable_buffer &out, const string_view &in);
|
const_buffer b64decode(const mutable_buffer &out, const string_view &in);
|
||||||
std::string b64decode(const string_view &in);
|
std::string b64decode(const string_view &in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t
|
||||||
|
ircd::b64decode_size(const string_view &in)
|
||||||
|
{
|
||||||
|
return b64decode_size(size(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t
|
||||||
|
ircd::b64decode_size(const size_t &in)
|
||||||
|
{
|
||||||
|
return ceil(in * 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t
|
||||||
|
ircd::b64encode_unpadded_size(const const_buffer &in)
|
||||||
|
{
|
||||||
|
return b64encode_unpadded_size(size(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t
|
||||||
|
ircd::b64encode_unpadded_size(const size_t &in)
|
||||||
|
{
|
||||||
|
return ceil(in * (4.0 / 3.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t
|
||||||
|
ircd::b64encode_size(const const_buffer &in)
|
||||||
|
{
|
||||||
|
return b64encode_size(size(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t
|
||||||
|
ircd::b64encode_size(const size_t &in)
|
||||||
|
{
|
||||||
|
return ceil(in * (4.0 / 3.0)) + (3 - in % 3) % 3;
|
||||||
|
}
|
||||||
|
|
||||||
inline size_t
|
inline size_t
|
||||||
ircd::b58decode_size(const string_view &in)
|
ircd::b58decode_size(const string_view &in)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue