0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd:Ⓜ️:event: Update the make_id() suite.

This commit is contained in:
Jason Volk 2019-07-10 02:04:08 -07:00
parent 6f4a4f351c
commit 329972ed01
3 changed files with 46 additions and 8 deletions

View file

@ -42,8 +42,8 @@ namespace ircd::m
bool check_id(const event &) noexcept;
bool check_id(const event &, const string_view &room_version) noexcept;
id::event make_id(const event &, id::event::buf &buf, const const_buffer &hash);
id::event make_id(const event &, id::event::buf &buf);
id::event make_id(const event &, const string_view &version, id::event::buf &buf, const const_buffer &hash);
id::event make_id(const event &, const string_view &version, id::event::buf &buf);
json::object hashes(const mutable_buffer &, const event &);
event signatures(const mutable_buffer &, const m::event &);

View file

@ -3695,21 +3695,59 @@ ircd::m::essential(m::event event,
ircd::m::id::event
ircd::m::make_id(const event &event,
const string_view &version,
id::event::buf &buf)
{
const crh::sha256::buf hash{event};
return make_id(event, buf, hash);
if(version == "1" || version == "2")
{
const crh::sha256::buf hash{event};
return make_id(event, version, buf, hash);
}
if(version == "3")
return event::id::v3
{
buf, event
};
return event::id::v4
{
buf, event
};
}
ircd::m::id::event
ircd::m::make_id(const event &event,
const string_view &version,
id::event::buf &buf,
const const_buffer &hash)
{
char readable[b58encode_size(sha256::digest_size)];
char readable[b64encode_size(sha256::digest_size)];
if(version == "1" || version == "2")
{
const id::event ret
{
buf, b64tob64url(readable, b64encode_unpadded(readable, hash)), my_host()
};
buf.assigned(ret);
return ret;
}
else if(version == "3")
{
const id::event ret
{
buf, b64encode_unpadded(readable, hash), string_view{}
};
buf.assigned(ret);
return ret;
}
const id::event ret
{
buf, b58encode(readable, hash), my_host()
buf, b64tob64url(readable, b64encode_unpadded(readable, hash)), string_view{}
};
buf.assigned(ret);

View file

@ -5886,7 +5886,7 @@ console_cmd__stage__final(opt &out, const string_view &line)
m::event::id::buf event_id_buf;
if(!has(opts, "no_event_id"))
json::get<"event_id"_>(event) = make_id(event, event_id_buf);
json::get<"event_id"_>(event) = make_id(event, "1", event_id_buf);
thread_local char hashes_buf[512];
if(!has(opts, "no_hashes"))
@ -5931,7 +5931,7 @@ console_cmd__stage__make_vector(opt &out, const string_view &line)
}
json::get<"depth"_>(event) = depth + 1;
json::get<"prev_events"_>(event) = json::array{st.completed()};
json::get<"event_id"_>(event) = make_id(event, prev_);
json::get<"event_id"_>(event) = make_id(event, "1", prev_);
json::get<"hashes"_>(event) = m::hashes(hb, event);
event = signatures(sb, event);
stage.at(i) = json::strung{event};