Skip to content

Latest commit

 

History

History
46 lines (37 loc) · 3.08 KB

API.md

File metadata and controls

46 lines (37 loc) · 3.08 KB

API (use "hlib" from "hlib")

All fallible calls return option::Result<T, hlib_error::HlibError>; HlibError{code,message}. Codes: io, not_archive, missing_entry, checksum_mismatch, malformed_checksums, unsigned, bad_signature, bad_key, duplicate_path, unsafe_path, limit, manifest, tar, zstd, invalid_input, not_found.

Function Purpose
open(path) / open_with(path, limits) / open_bytes(buf, display, limits) read an archive (validates paths, types, limits)
default_limits() 1 GiB packed / 2 GiB unpacked / 1 GiB entry / 10 000 entries / 16 MiB manifest
read_manifest_json(path) / manifest_json(m) raw / rendered manifest
has_entry, entry_paths, entry_bytes inspect contents
verify_checksums(a) every CHECKSUMS line matches (compat rule)
verify_signature(a, pubkey_hex) Ed25519 over CHECKSUMS bytes; key from the caller
check(a, trusted_key_hex) Report{ok, signed, signature_valid, trusted, problems}
check_strict(a, trusted_key_hex) adds: payload fully covered, manifest == archive, signature fields consistent
extract_to_dir(a, dir) / extract_entry(a, path, dest) atomic writes, never outside dir
builder_new(name, version, language) then add_shared_object, add_ast, add_header, add_bytecode, add_extra, add_file assemble
build_bytes(b, signing_key_hex) / finish(b, out, signing_key_hex) deterministic output; "" = unsigned
generate_keypair(), public_key_hex(sk), sha256_hex(buf) crypto helpers
find(name, version, language, start_dir) / search_dirs(...) spec §8 lookup
version(), spec_version() 1.0.0, 1

Languages: hsharp, hackerlang, hackerscript. Set SOURCE_DATE_EPOCH for reproducible created.

Toolchain facade (1.0)

What the H# compiler and h# lib use, at the top level of the library (use "bit -> hlib" from "hlib"):

Function Purpose
add_static_lib(b, target, data, link_libs) add a prebuilt static archive (native/<target>/lib<name>.a, kind static_lib) with the system libraries it needs when linked
parse_exports_text(raw) parse a JSON array of exports (headers/<name>.iface.json)
parse_manifest_text(raw) parse manifest.json text
exports_json(exports) serialise exports
error_text(e) / error_message(e) "code: message" / message of a HlibError
quote_json(s) JSON string literal
buf_new, buf_from_str, buf_to_str, read_file, write_file, make_dirs, entry_index byte buffer and file helpers
empty_manifest(), empty_archive(), empty_builder() placeholder values

Manifest additions: Artifact.link_libs: [string] (JSON "link_libs"), Export.api / Export.owner (JSON "api", "owner", omitted when empty), artifact kind static_lib, ABI type cstr (NUL-terminated C string, string in H#).

Note: library types are named through their modules (hlib_archive::Archive, hlib_manifest::Export, …); a type X = … alias of a library type is not resolved when used from another crate, so none is exported.