AWS Signature Version 4 request signing in Zig: the canonical request, the string to sign, and the HMAC-SHA256 signing key, with no I/O.
Every request to an AWS API carries a signature over its method, path, headers, and body hash. The algorithm is fixed and small. The failures are in the strings: a header list that sorts case-folded and joins its duplicates, a query that sorts by its encoded bytes, a path escaped a second time for every service except S3, and a scope date that has to agree with the timestamp.
This package builds those strings and the chain. It writes the Authorization
field value, or a presigned query, into a buffer you own. There is no
allocator, no clock, no credentials store, and no HTTP client: the timestamp is
a string you supply.
const value = try sigv4.signing.writeAuthorization(&field, &creq, request, credentials);The AWS signing test suite is vendored unmodified, and just test runs every
case through the same code: the canonical request, the string to sign, the
signature, and the field value, for both the header and the query form.
- The request:
canonical.Requestis the signature's view of a request, with a wirepathand aPathModeof.service,.unnormalized, or.s3. - The canonical request:
writeRequestwrites the six parts and sorts the caller's header and query slices in place; the parts are public on their own. - The string to sign:
Scope.inittakes the date from the timestamp so the two cannot disagree, andwriteStringToSigncovers the canonical request's hash. - The signing key:
signingKeyis the four-round HMAC chain, and it zeroes the intermediate keys before it returns. - The Authorization field:
writeAuthorizationchecks the timestamp, merges a session token, and refuses an S3 request it knows AWS will reject. - Presigning:
presignbuilds theX-Amz-*query and the signature for a URL that carries its own credentials. - Limits: no clock, no HTTP, no SigV4a, no streaming chunk signatures.
Not implemented:
- SigV4a:
sigv4.algorithmisAWS4-HMAC-SHA256, and theAWS4-ECDSA-P256-SHA256chain needs a signing curve and a different key format. - Streaming signatures: nothing writes
STREAMING-AWS4-HMAC-SHA256-PAYLOADor the chunk chain below it. A streaming hash arrives as a string inRequest.payload_hash. - A credentials store: no profile file, no IMDS, no STS call, and no refresh.
Credentialsholds strings. - An HTTP client: no request type and no header parsing. A folded header line is the parser's job.
zig fetch --save https://baskingspot.dev/sigv4/v0.1.0.tar.gzAdd the module in build.zig:
const sigv4 = b.dependency("sigv4", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("sigv4", sigv4.module("sigv4"));sigv4 builds with Zig 0.17.
- The guide covers the request, the canonical form, the key chain, the field, presigning, and the limits, with examples that compile.
- The API reference documents every public symbol.
docs/examples/is the code the guide shows, compiled byjust test.test/fixtures/is the vendored AWS signing test suite and the botocore-signed vectors;THIRD_PARTY.mdrecords where they came from.AGENTS.mdhas the working notes for the repository.
just cinix develop provides the toolchain and the site tools. just lists the
recipes, and just ci runs what CI runs: the tests, lint, and the site build.
just guide serves the guide with live reload, and just doc builds the whole
site into zig-out/site/sigv4/.
MIT. See LICENSE. The AWS signing test suite in
test/fixtures/aws-signing-suite/ is Apache-2.0, and its LICENSE and
NOTICE travel with it. See THIRD_PARTY.md. The logo
files in docs/static/ are baskingspot marks and are not covered by the
license; see docs/static/LICENSE.
Built with LLM assistance. How, in detail.