Zig 0.17.0-dev (Split by item)

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.

update

Sha1.update
pub fn update(d: *Sha1, b: []const u8) void

File

lib/std/crypto/Sha1.zig:39

Code

pub fn update(d: *Sha1, b: []const u8) void {
    var off: usize = 0;

    // Partial buffer exists from previous update. Copy into buffer then hash.
    if (d.buf_len != 0 and d.buf_len + b.len >= 64) {
        off += 64 - d.buf_len;
        @memcpy(d.buf[d.buf_len..][0..off], b[0..off]);

        d.round(d.buf[0..]);
        d.buf_len = 0;
    }

    // Full middle blocks.
    while (off + 64 <= b.len) : (off += 64) {
        d.round(b[off..][0..64]);
    }

    // Copy any remainder for next pass.
    @memcpy(d.buf[d.buf_len..][0 .. b.len - off], b[off..]);
    d.buf_len += @as(u8, @intCast(b[off..].len));

    d.total_len += b.len;
}