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.
Zig › std/ › crypto/ › Certificate/ › Bundle/ › macos.zig › scanReader
scanReader
macos.scanReader
fn scanReader (cb : *Bundle , gpa : Allocator , reader : *Io .Reader , now_sec : i64 ) !void
File
Code
fn scanReader (cb : *Bundle , gpa : Allocator , reader : *Io .Reader , now_sec : i64 ) !void {
const db_header = try reader .takeStruct (ApplDbHeader , .big );
assert (mem .eql (u8 , &db_header .signature , "kych" ));
reader .seek = db_header .schema_offset ;
const db_schema = try reader .takeStruct (ApplDbSchema , .big );
var table_list = try gpa .alloc (u32 , db_schema .table_count );
defer gpa .free (table_list );
var table_idx : u32 = 0 ;
while (table_idx < table_list .len ) : (table_idx += 1 ) {
table_list [table_idx ] = try reader .takeInt (u32 , .big );
}
for (table_list ) |table_offset | {
reader .seek = db_header .schema_offset + table_offset ;
const table_header = try reader .takeStruct (TableHeader , .big );
if (@as (std .c .DB_RECORDTYPE , @fromBackingInt (@intCast (table_header .table_id ))) != .X509_CERTIFICATE ) {
continue ;
}
var record_list = try gpa .alloc (u32 , table_header .record_count );
defer gpa .free (record_list );
var record_idx : u32 = 0 ;
while (record_idx < record_list .len ) : (record_idx += 1 ) {
record_list [record_idx ] = try reader .takeInt (u32 , .big );
}
for (record_list ) |record_offset | {
// An offset that is not 4-byte-aligned is invalid.
if (record_offset == 0 or record_offset % 4 != 0 ) continue ;
reader .seek = db_header .schema_offset + table_offset + record_offset ;
const cert_header = try reader .takeStruct (X509CertHeader , .big );
if (cert_header .cert_size == 0 ) continue ;
const cert_start : u32 = @intCast (cb .bytes .items .len );
const dest_buf = try cb .bytes .addManyAsSlice (gpa , cert_header .cert_size );
try reader .readSliceAll (dest_buf );
try cb .parseCert (gpa , cert_start , now_sec );
}
}
}