milestone 18: collapse duplicated infrastructure into shared listener core, crud list helper, resource shells, transport race, name and line helpers, ui modules
This commit is contained in:
@@ -29,7 +29,10 @@
|
||||
|
||||
const std = @import("std");
|
||||
const parsers = @import("parsers");
|
||||
const smith_encode = @import("smith_encode.zig");
|
||||
|
||||
const sliceInput = smith_encode.sliceInput;
|
||||
const pairInput = smith_encode.pairInput;
|
||||
const wildcard = parsers.wildcard;
|
||||
const Smith = std.testing.Smith;
|
||||
|
||||
@@ -132,9 +135,8 @@ fn labelCount(text: []const u8) usize {
|
||||
// corpus
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// `Smith` does not consume a corpus entry as raw parser input. It reads a byte
|
||||
// stream in which a slice is a little-endian `u32` length followed by that many
|
||||
// bytes, so every entry below is length-prefixed. The five targets share one
|
||||
// `Smith` does not consume a corpus entry as raw parser input, so every entry
|
||||
// below goes through the `smith_encode.zig` encoders. The five targets share one
|
||||
// corpus: each starts with a slice, and the wildcard target reads a second one
|
||||
// that falls back to empty when an entry carries only the first.
|
||||
|
||||
@@ -156,31 +158,6 @@ const long_line = "a" ** 5000 ++ ".example.com";
|
||||
const element_hiding = "example.com##.ad-banner";
|
||||
const scheme_anchor = "|https://ads.example.com/track";
|
||||
|
||||
/// Encodes `bytes` as a single `Smith.slice` value.
|
||||
fn sliceInput(comptime bytes: []const u8) *const [4 + bytes.len]u8 {
|
||||
return &struct {
|
||||
const value: [4 + bytes.len]u8 = blk: {
|
||||
var buf: [4 + bytes.len]u8 = undefined;
|
||||
std.mem.writeInt(u32, buf[0..4], @intCast(bytes.len), .little);
|
||||
buf[4..].* = bytes[0..bytes.len].*;
|
||||
break :blk buf;
|
||||
};
|
||||
}.value;
|
||||
}
|
||||
|
||||
/// Encodes two `Smith.slice` values back to back, which is what the wildcard
|
||||
/// target reads.
|
||||
fn pairInput(comptime a: []const u8, comptime b: []const u8) *const [8 + a.len + b.len]u8 {
|
||||
return &struct {
|
||||
const value: [8 + a.len + b.len]u8 = blk: {
|
||||
var buf: [8 + a.len + b.len]u8 = undefined;
|
||||
buf[0 .. 4 + a.len].* = sliceInput(a).*;
|
||||
buf[4 + a.len ..].* = sliceInput(b).*;
|
||||
break :blk buf;
|
||||
};
|
||||
}.value;
|
||||
}
|
||||
|
||||
const corpus = [_][]const u8{
|
||||
sliceInput(hosts_line),
|
||||
sliceInput(abp_line),
|
||||
@@ -197,17 +174,3 @@ const corpus = [_][]const u8{
|
||||
pairInput("*.example.com", "example.com.evil.net"),
|
||||
pairInput("ad*.example.com", "ads.example.com"),
|
||||
};
|
||||
|
||||
test "a corpus entry carries its own length" {
|
||||
const encoded = sliceInput(abp_line);
|
||||
try std.testing.expectEqual(@as(u32, abp_line.len), std.mem.readInt(u32, encoded[0..4], .little));
|
||||
try std.testing.expectEqualSlices(u8, abp_line, encoded[4..]);
|
||||
}
|
||||
|
||||
test "a paired corpus entry carries both lengths" {
|
||||
const encoded = pairInput("*.a.b", "x.a.b");
|
||||
try std.testing.expectEqual(@as(u32, 5), std.mem.readInt(u32, encoded[0..4], .little));
|
||||
try std.testing.expectEqualSlices(u8, "*.a.b", encoded[4..9]);
|
||||
try std.testing.expectEqual(@as(u32, 5), std.mem.readInt(u32, encoded[9..13], .little));
|
||||
try std.testing.expectEqualSlices(u8, "x.a.b", encoded[13..]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user