Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNineteen committed Jan 15, 2025
1 parent 442815d commit f5ff30d
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/gossip/prune.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,34 @@ pub const PruneData = struct {
}

pub fn signWithoutPrefix(self: *PruneData, keypair: *const KeyPair) !void {
var slice: [PACKET_DATA_SIZE]u8 = undefined;
const signable_data = PruneSignableData{
.pubkey = self.pubkey,
.prunes = self.prunes,
.destination = self.destination,
.wallclock = self.wallclock,
};
const out = try bincode.writeToSlice(&slice, signable_data, bincode.Params{});
var signature = try keypair.sign(out, null);

// serialize
var d: [PACKET_DATA_SIZE]u8 = undefined;
const data = try bincode.writeToSlice(&d, signable_data, .{});
// sign
var signature = try keypair.sign(data, null);
self.signature.data = signature.toBytes();
}

pub fn signWithPrefix(self: *PruneData, keypair: *const KeyPair) !void {
var slice: [PACKET_DATA_SIZE]u8 = undefined;
const signable_data = PruneSignableDataWithPrefix{
.pubkey = self.pubkey,
.prunes = self.prunes,
.destination = self.destination,
.wallclock = self.wallclock,
};
const out = try bincode.writeToSlice(&slice, signable_data, bincode.Params{});
var signature = try keypair.sign(out, null);

// serialize
var d: [PACKET_DATA_SIZE]u8 = undefined;
const data = try bincode.writeToSlice(&d, signable_data, .{});
// sign
var signature = try keypair.sign(data, null);
self.signature.data = signature.toBytes();
}

Expand All @@ -108,31 +114,35 @@ pub const PruneData = struct {
}

pub fn verifyWithoutPrefix(self: *const PruneData) !void {
var slice: [PACKET_DATA_SIZE]u8 = undefined;
const signable_data = PruneSignableData{
.pubkey = self.pubkey,
.prunes = self.prunes,
.destination = self.destination,
.wallclock = self.wallclock,
};
const out = try bincode.writeToSlice(&slice, signable_data, bincode.Params{});
if (!try self.signature.verify(self.pubkey, out)) {

// serialize
var d: [PACKET_DATA_SIZE]u8 = undefined;
const data = try bincode.writeToSlice(&d, signable_data, .{});
// verify
if (!try self.signature.verify(self.pubkey, data))
return error.InvalidSignature;
}
}

pub fn verifyWithPrefix(self: *const PruneData) !void {
var slice: [PACKET_DATA_SIZE]u8 = undefined;
const signable_data = PruneSignableDataWithPrefix{
.pubkey = self.pubkey,
.prunes = self.prunes,
.destination = self.destination,
.wallclock = self.wallclock,
};
const out = try bincode.writeToSlice(&slice, signable_data, bincode.Params{});
if (!try self.signature.verify(self.pubkey, out)) {

// serialize
var d: [PACKET_DATA_SIZE]u8 = undefined;
const data = try bincode.writeToSlice(&d, signable_data, .{});
// verify
if (!try self.signature.verify(self.pubkey, data))
return error.InvalidSignature;
}
}
};

Expand Down

0 comments on commit f5ff30d

Please sign in to comment.