Lindenii Project Forge
Login

hare-git

WIP Git library for Hare
Commit info
ID
4b6db3c5ff674bf78e46144eae1bae78008a411f
Author
Runxi Yu <me@runxiyu.org>
Author date
Sun, 14 Sep 2025 06:09:02 +0800
Committer
Runxi Yu <me@runxiyu.org>
Committer date
Sun, 14 Sep 2025 06:09:02 +0800
Actions
Size check for OID parsing
use crypto::sha256;
use encoding::hex;
use errors;
use io;

export type oid = [sha256::SZ]u8;

// Parses a hex-encoded string representation of an [[oid]].
export fn parse_oid(s: const str) (oid | nomem | errors::invalid) = {
	if (len(s) != sha256::SZ * 2) {
		return errors::invalid;
	};

	const d = hex::decodestr(s)?;
	defer free(d);

	let o: oid = [0...];
	o[..] = d[..];

	return o;
};

// Returns a hex-encoded string representation of the given [[oid]].
// The returned string is allocated on the heap and must be freed by the caller.
export fn oid_string(id: oid) (const str | nomem) = {
	return hex::encodestr(id)?;
};