From 3b2c0c0f9cdbc37578236c931c652d1dd221e88d Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Tue, 08 Apr 2025 11:14:41 +0800 Subject: [PATCH] oid: Use errors::invalid for hash issues --- git/oid.ha | 16 ++++++++++------ diff --git a/git/oid.ha b/git/oid.ha index ae81198758a4674798778a5714f88755314ae2fb..08010430266a3a8e0e5b36f095216df6f1a05ef9 100644 --- a/git/oid.ha +++ b/git/oid.ha @@ -1,17 +1,21 @@ use crypto::sha1; use crypto::sha256; use encoding::hex; +use errors; use io; - -// Invalid hash length -export type hashlen = !void; export type oid = (oid_sha1 | oid_sha256); export type oid_sha1 = [sha1::SZ]u8; export type oid_sha256 = [sha256::SZ]u8; -export fn oid_from_str(s: const str) (oid | io::error | hashlen) = { - const d = hex::decodestr(s)?; +// oid_from_str converts a hex string to an oid. +export fn oid_from_str(s: const str) (oid | nomem | errors::invalid) = { + const d = match (hex::decodestr(s)) { + case let u: []u8 => yield u; + case nomem => return nomem; + case errors::invalid => return errors::invalid; + case => abort("unreachable"); + }; defer free(d); let o: oid = switch (len(s)) { @@ -24,7 +28,7 @@ let p: oid_sha256 = [0...]; p[..] = d[..]; yield p; case => - return hashlen; + return errors::invalid; }; return o; -- 2.48.1