0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 05:18:23 +02:00

ircd:Ⓜ️:vm: Add content requirement and redaction hint opts for non-conforming mask.

This commit is contained in:
Jason Volk 2020-07-06 08:48:21 -07:00
parent 41e13921c3
commit 91d57ea989
2 changed files with 43 additions and 2 deletions

View file

@ -230,6 +230,15 @@ struct ircd::m::vm::opts
/// done before eval.
event::conforms report;
/// True hints that the event is known to be redacted. False hints that
/// the event is not redacted. -1 is automatic, which may make a query.
int8_t redacted {-1};
/// When true, the event is expected to have its content; hash mismatch
/// is not permitted. When false, hash mismatch is permitted when the
/// event is known to be redacted (see above).
bool require_content {false};
/// Supply the room version; overrides/avoids any internal query.
string_view room_version;

View file

@ -134,11 +134,43 @@ ircd::m::vm::conform_report
if(!opts.conforming)
return;
const bool redacted
{
// redacted hint given in options
opts.redacted != -1?
bool(opts.redacted):
// assume unredacted when user requires content
opts.require_content?
false:
// assume redacted when hash mismatch already allowed
(opts.non_conform.has(event::conforms::MISMATCH_HASHES))?
true:
// assume no redaction for hash match
(!eval.report.has(event::conforms::MISMATCH_HASHES))?
false:
// make query
bool(m::redacted(event.event_id))
};
auto report
{
eval.report
};;
// Allow content hash to fail on redacted events.
if(redacted)
report.del(event::conforms::MISMATCH_HASHES);
// Otherwise this will kill the eval
if(!eval.report.clean())
if(!report.clean())
throw error
{
fault::INVALID, "Non-conforming event: %s", string(eval.report)
fault::INVALID, "Non-conforming event: %s",
string(report)
};
}
};