Something went wrong. Try again.
SCRAM authentication in Zig — RFC 5802 and RFC 7677, with a CLI for computing PostgreSQL password verifiers.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("scram", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, });
// Unicode character data, used to implement the NFKC normalization step of // SASLprep. Only the four fields we actually read are built into the // generated tables; see src/nfkc.zig. const uucode = b.dependency("uucode", .{ .target = target, .optimize = optimize, .fields = @as([]const []const u8, &.{ "canonical_combining_class", "decomposition_type", "decomposition_mapping", "is_composition_exclusion", }), }); mod.addImport("uucode", uucode.module("uucode"));
// SCRAM as a SASL mechanism, in a module of its own so that `scram` // itself keeps no dependency on zig-sasl. Only something that wants to // hand SCRAM to a protocol library pays for it. const sasl = b.dependency("sasl", .{ .target = target, .optimize = optimize, }); const sasl_mod = b.addModule("scram-sasl", .{ .root_source_file = b.path("src/sasl.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "sasl", .module = sasl.module("sasl") }, .{ .name = "scram", .module = mod }, }, });
const exe = b.addExecutable(.{ .name = "scram-sha-256", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "scram", .module = mod }, }, }), }); b.installArtifact(exe);
// Shell completions, in the directories fish and bash-completion search // under a prefix. Installed alongside the binary so that `zig build // --prefix ~/.local` puts them somewhere both shells already look. b.installFile("completions/scram-sha-256.fish", "share/fish/vendor_completions.d/scram-sha-256.fish"); b.installFile("completions/scram-sha-256.bash", "share/bash-completion/completions/scram-sha-256");
const run_step = b.step("run", "Run the app"); const run_cmd = b.addRunArtifact(exe); run_step.dependOn(&run_cmd.step); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); }
const mod_tests = b.addTest(.{ .root_module = mod, }); const run_mod_tests = b.addRunArtifact(mod_tests);
const sasl_tests = b.addTest(.{ .root_module = sasl_mod, }); const run_sasl_tests = b.addRunArtifact(sasl_tests);
const exe_tests = b.addTest(.{ .root_module = exe.root_module, }); const run_exe_tests = b.addRunArtifact(exe_tests);
const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_mod_tests.step); test_step.dependOn(&run_sasl_tests.step); test_step.dependOn(&run_exe_tests.step);}