╭ changed ──────────╮ │src/event/Grant.zig│ ╰───────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────────────────────────────────────────╮ │ 4 const hash = xit.hash; │ │ 5 │ │ 6 // what the grant gives access to, held in the same user repo │ │ 7 -target_id: []const u8, │ │ 7 +target_id: [evt.event_id_size * 2]u8, │ │ 8 // who it gives access to │ │ 9 -user_id: []const u8, │ │ 9 +user_id: [evt.event_id_size * 2]u8, │ │10 role: evt.Repo.Role, │ │11 │ │12 // what the db stores: the event's data plus the commit-derived fields│ ╰──────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │26 pub const target_to_grant_id_set_key = "target->grant-id-set"; │ │27 │ │28 // the id of the one grant a user can hold on a target │ │29 -pub fn idOf(target_id: []const u8, user_id: []const u8) [evt.event_id_size]u8 { │ │29 +pub fn idOf(target_id: *const [evt.event_id_size]u8, user_id: *const [evt.event_id_size]u8) [evt.event_id_size]u8 {│ │30 var hasher = std.crypto.hash.sha2.Sha256.init(.{}); │ │31 hasher.update(target_id); │ │32 hasher.update(user_id); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │38 // only what the event says about itself is checked. a grant naming a missing │ │39 // target or user is inert. │ │40 fn validate(event_id: *const [evt.event_id_size]u8, record: Record) !void { │ │41 - if (record.event.target_id.len != evt.event_id_size) return error.InvalidTargetId; │ │42 - if (record.event.user_id.len != evt.event_id_size) return error.InvalidUserId; │ │43 - if (!std.mem.eql(u8, event_id, &idOf(record.event.target_id, record.event.user_id))) return error.InvalidGrantId;│ │41 + const target_id = try evt.parseEventId(&record.event.target_id); │ │42 + const user_id = try evt.parseEventId(&record.event.user_id); │ │43 + if (!std.mem.eql(u8, event_id, &idOf(&target_id, &user_id))) return error.InvalidGrantId; │ │44 } │ │45 │ │46 pub fn consume( │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │84 } │ │85 │ │86 // the id fixes the target, so a grant never moves between sets │ │87 - const target_grants = try DB.SortedSet(.read_write).init(try by_target.putCursor(hash.hashInt(hash_kind, record.event.target_id)));│ │87 + const target_id = try evt.parseEventId(&record.event.target_id); │ │88 + const target_grants = try DB.SortedSet(.read_write).init(try by_target.putCursor(hash.hashInt(hash_kind, &target_id))); │ │89 if (record.removed) { │ │90 _ = try target_grants.remove(&order_key); │ │91 } else { │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 99 comptime hash_kind: hash.HashKind, │ │100 haxy_moment: DB.HashMap(.read_only), │ │101 arena: *std.heap.ArenaAllocator, │ │101 - target_id: []const u8, │ │102 - user_id: []const u8, │ │102 + target_id: *const [evt.event_id_size]u8, │ │103 + user_id: *const [evt.event_id_size]u8, │ │104 ) !?evt.Repo.Role { │ │105 const Granted = struct { event: struct { role: evt.Repo.Role }, removed: bool }; │ │106 const grant = (try evt.readRecordSubset(Self, Granted, DB, hash_kind, haxy_moment, arena, &idOf(target_id, user_id))) orelse return null;│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │113 comptime hash_kind: hash.HashKind, │ │114 haxy_moment: DB.HashMap(.read_only), │ │115 arena: *std.heap.ArenaAllocator, │ │115 - target_id: []const u8, │ │116 + target_id: *const [evt.event_id_size]u8, │ │117 ) ![]const Self { │ │118 var grants: std.ArrayList(Self) = .empty; │ │119 const by_target_cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, target_to_grant_id_set_key)) orelse return grants.items;│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯