This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.
CShakeLike
sha3.CShakeLike
fnCShakeLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5, comptimefname: ?[]constu8) type
fnCShakeLike(comptimesecurity_level: u11, comptimedefault_delim: u8, comptimerounds: u5, comptimefname: ?[]constu8) type {
returnstruct {
constShaker = ShakeLike(security_level, default_delim, rounds);
shaker: Shaker,
/// The recommended output length, in bytes.pubconstdigest_length = Shaker.digest_length;
/// The block length, or rate, in bytes.pubconstblock_length = Shaker.block_length;
/// cSHAKE options can include a context string.pubconstOptions = struct { context: ?[]constu8 = null };
constSelf = @This();
/// Initialize a SHAKE extensible hash function.pubfninit(options: Options) Self {
if (fname == nullandoptions.context == null) {
returnSelf{ .shaker = Shaker.init(.{ .delim = 0x1f }) };
}
varshaker = Shaker.init(.{});
comptimeassert(Shaker.block_length % 8 == 0);
constencoded_rate_len = NistLengthEncoding.encode(.left, block_length / 8);
shaker.update(encoded_rate_len.slice());
constencoded_zero = comptimeNistLengthEncoding.encode(.left, 0);
if (fname) |name| {
constencoded_fname_len = comptimeNistLengthEncoding.encode(.left, name.len);
constencoded_fname = comptimeencoded_fname_len.slice() ++ name;
shaker.update(encoded_fname);
} else {
shaker.update(encoded_zero.slice());
}
if (options.context) |context| {
constencoded_context_len = NistLengthEncoding.encode(.left, context.len);
shaker.update(encoded_context_len.slice());
shaker.update(context);
} else {
shaker.update(encoded_zero.slice());
}
shaker.st.fillBlock();
returnSelf{ .shaker = shaker };
}
/// Hash a slice of bytes./// `out` can be any length.pubfnhash(bytes: []constu8, out: []u8, options: Options) void {
varst = Self.init(options);
st.update(bytes);
st.squeeze(out);
}
/// Absorb a slice of bytes into the state.pubfnupdate(self: *Self, bytes: []constu8) void {
self.shaker.update(bytes);
}
/// Squeeze a slice of bytes from the state./// `out` can be any length, and the function can be called multiple times.pubfnsqueeze(self: *Self, out: []u8) void {
self.shaker.squeeze(out);
}
/// Return the hash of the absorbed bytes./// `out` can be of any length, but the function must not be called multiple times (use `squeeze` for that purpose instead).pubfnfinal(self: *Self, out: []u8) void {
self.shaker.final(out);
}
/// Align the input to a block boundary.pubfnfillBlock(self: *Self) void {
self.shaker.fillBlock();
}
};
}