Lindenii Project Forge
Warning: Due to various recent migrations, viewing non-HEAD refs may be broken.
/git/oid.ha (raw)
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)?;
};