ircd::b64: De-template dictionary argument; simplify.

This commit is contained in:
Jason Volk 2023-03-03 22:20:27 -08:00
parent 4371380fe9
commit 2d10ac2c78
6 changed files with 23 additions and 33 deletions

View File

@ -37,13 +37,9 @@ namespace ircd::b64
size_t encode_size(const const_buffer &in) noexcept;
size_t encode_unpadded_size(const const_buffer &in) noexcept;
const_buffer decode(const mutable_buffer &out, const string_view &in);
template<const dictionary & = dict_rfc1421>
string_view encode(const mutable_buffer &out, const const_buffer &in) noexcept;
template<const dictionary & = dict_rfc1421>
string_view encode_unpadded(const mutable_buffer &out, const const_buffer &in) noexcept;
const_buffer decode(const mutable_buffer out, const string_view in);
string_view encode_unpadded(const mutable_buffer out, const const_buffer in, const dictionary & = dict_rfc1421) noexcept;
string_view encode(const mutable_buffer out, const const_buffer in, const dictionary & = dict_rfc1421) noexcept;
}
inline size_t

View File

@ -25,10 +25,8 @@ namespace ircd::b64
extern const i32
decode_tab[256];
static u8x64 decode_block(const u8x64 block, i64x8 &err) noexcept;
template<const dictionary &>
static u8x64 encode_block(const u8x64 block) noexcept;
static u8x64 decode_block(const u8x64 block, i64x8 &__restrict__ err) noexcept;
static u8x64 encode_block(const u8x64 block, const dictionary &) noexcept;
}
#pragma GCC visibility pop
@ -153,10 +151,10 @@ alignas(64)
/// Encoding in to base64 at out. Out must be 1.33+ larger than in
/// padding is not present in the returned view.
template<const ircd::b64::dictionary &dict>
ircd::string_view
ircd::b64::encode(const mutable_buffer &out,
const const_buffer &in)
ircd::b64::encode(const mutable_buffer out,
const const_buffer in,
const dictionary &dict)
noexcept
{
const auto pads
@ -166,7 +164,7 @@ noexcept
const auto encoded
{
encode_unpadded<dict>(out, in)
encode_unpadded(out, in, dict)
};
const char _pad[2]
@ -187,14 +185,12 @@ noexcept
data(out), len
};
}
template ircd::string_view ircd::b64::encode<ircd::b64::standard>(const mutable_buffer &, const const_buffer &) noexcept;
template ircd::string_view ircd::b64::encode<ircd::b64::urlsafe>(const mutable_buffer &, const const_buffer &) noexcept;
/// Encoding in to base64 at out. Out must be 1.33+ larger than in.
template<const ircd::b64::dictionary &dict>
ircd::string_view
ircd::b64::encode_unpadded(const mutable_buffer &out,
const const_buffer &in)
ircd::b64::encode_unpadded(const mutable_buffer out,
const const_buffer in,
const dictionary &dict)
noexcept
{
char *const __restrict__ dst
@ -234,7 +230,7 @@ noexcept
};
block = *si;
block = encode_block<dict>(block);
block = encode_block(block, dict);
*di = block;
}
@ -246,7 +242,7 @@ noexcept
for(j = 0; j < 48 && i * 48 + j < size(in); ++j)
block[j] = src[i * 48 + j];
block = encode_block<dict>(block);
block = encode_block(block, dict);
for(j = 0; j < 64 && i * 64 + j < out_len; ++j)
dst[i * 64 + j] = block[j];
}
@ -256,8 +252,6 @@ noexcept
data(out), out_len
};
}
template ircd::string_view ircd::b64::encode_unpadded<ircd::b64::dict_rfc1421>(const mutable_buffer &, const const_buffer &) noexcept;
template ircd::string_view ircd::b64::encode_unpadded<ircd::b64::dict_rfc4648>(const mutable_buffer &, const const_buffer &) noexcept;
/// Returns 64 base64-encoded characters from 48 input characters. For any
/// inputs less than 48 characters trail with null characters; caller computes
@ -270,9 +264,9 @@ template ircd::string_view ircd::b64::encode_unpadded<ircd::b64::dict_rfc4648>(c
/// Based on https://arxiv.org/pdf/1910.05109 (and earlier work). No specific
/// intrinsics are used here; instead we recite a kotodama divination known
/// as "vector extensions" which by chance is visible to humans as C syntax.
template<const ircd::b64::dictionary &dict>
ircd::u8x64
ircd::b64::encode_block(const u8x64 in)
ircd::b64::encode_block(const u8x64 in,
const dictionary &dict)
noexcept
{
size_t i, j, k;
@ -318,8 +312,8 @@ noexcept
/// Decode base64 from in to the buffer at out; out can be 75% of the size
/// of in.
ircd::const_buffer
ircd::b64::decode(const mutable_buffer &out,
const string_view &in)
ircd::b64::decode(const mutable_buffer out,
const string_view in)
{
char *const __restrict__ dst
{

View File

@ -118,7 +118,7 @@ ircd::m::make_id(const event &event,
{
const id::event ret
{
buf, b64::encode_unpadded<b64::urlsafe>(readable, hash), at<"origin"_>(event)
buf, b64::encode_unpadded(readable, hash, b64::urlsafe), at<"origin"_>(event)
};
buf.assigned(ret);
@ -137,7 +137,7 @@ ircd::m::make_id(const event &event,
const id::event ret
{
buf, b64::encode_unpadded<b64::urlsafe>(readable, hash), string_view{}
buf, b64::encode_unpadded(readable, hash, b64::urlsafe), string_view{}
};
buf.assigned(ret);

View File

@ -927,7 +927,7 @@ ircd::m::id::event::v4::v4(const mutable_buffer &out,
out[0] = '$';
const string_view hashb64
{
b64::encode_unpadded<b64::urlsafe>(out + 1, hash)
b64::encode_unpadded(out + 1, hash, b64::urlsafe)
};
return string_view

View File

@ -468,7 +468,7 @@ ircd::m::media::file::room_id(room::id::buf &out,
out =
{
b64::encode_unpadded<b64::urlsafe>(buf, hash), my_host()
b64::encode_unpadded(buf, hash, b64::urlsafe), my_host()
};
return out;

View File

@ -33,7 +33,7 @@ ircd::m::user::filter::set(const mutable_buffer &idbuf,
const string_view filter_id
{
b64::encode_unpadded<b64::urlsafe>(idbuf, hash)
b64::encode_unpadded(idbuf, hash, b64::urlsafe)
};
//TODO: ABA