Something went wrong. Try again.
DMARC (RFC 7489) for Zig: the record grammar, identifier alignment, and policy discovery by DNS tree walk rather than a public suffix list.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A `Resolver` over a table of records.//!//! Policy discovery is a walk up the namespace, and a walk is only//! interesting when there is a namespace to walk: a table says where the//! records are and where they are not, which is exactly what the//! interesting cases turn on.
const std = @import("std");const Io = std.Io;const Resolver = @import("Resolver.zig");
const Zone = @This();
/// `_dmarc.<name>` TXT records, and anything else published beside them.entries: []const Entry = &.{},/// Names that exist in the DNS — have an A, AAAA or MX record — which is/// the question `np` turns on. A name absent from this list does not/// exist.existing: []const []const u8 = &.{},/// Names that answer with a temporary failure whatever is asked.failing: []const []const u8 = &.{},
pub const Entry = struct { name: []const u8, txt: []const u8,};
pub fn resolver(zone: *const Zone) Resolver { return .{ .context = @constCast(zone), .vtable = &.{ .txt = txt, .exists = exists, } };}
fn sameName(a: []const u8, b: []const u8) bool { return std.ascii.eqlIgnoreCase( std.mem.trimEnd(u8, a, "."), std.mem.trimEnd(u8, b, "."), );}
fn txt(context: ?*anyopaque, io: Io, name: []const u8, out: *Resolver.Strings) Resolver.Error!void { _ = io; const zone: *const Zone = @ptrCast(@alignCast(context.?)); for (zone.failing) |failing| { if (sameName(failing, name)) return error.Temporary; } var found = false; for (zone.entries) |entry| { if (!sameName(entry.name, name)) continue; found = true; try out.append(entry.txt); } if (!found) return error.NotFound;}
fn exists(context: ?*anyopaque, io: Io, name: []const u8) Resolver.Error!bool { _ = io; const zone: *const Zone = @ptrCast(@alignCast(context.?)); for (zone.existing) |existing| { if (sameName(existing, name)) return true; } return false;}