Commit Diff


commit - 588a8092bc282294ee23585991e81586905a8fd4
commit + be288a59f42e0b5e203e2c5545bf3e042ff4b79f
blob - 079b3c530a2c1681a497b2d74a8c077a1528b18a
blob + 6f68586c640662cd888e740dc5acaa83e889d438
--- gotctl/Makefile
+++ gotctl/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		gotctl
 SRCS=		gotctl.c error.c imsg.c inflate.c object_parse.c path.c \
-		pollfd.c sha1.c
+		pollfd.c hash.c
 
 MAN =		${PROG}.8
 
blob - 9e2f3a3fe6ecbd861b2a0fecf13026d61c3d475b
blob + b7c896f3faf9b3cbecc58d07a2ad7f76b9226064
--- gotd/Makefile
+++ gotd/Makefile
@@ -14,7 +14,7 @@ SRCS=		gotd.c auth.c repo_read.c repo_write.c log.c pr
 		object.c object_cache.c object_create.c object_idset.c \
 		object_open_io.c object_parse.c opentemp.c pack.c path.c \
 		read_gitconfig.c read_gotconfig.c reference.c repository.c  \
-		sha1.c sigs.c pack_create_io.c pollfd.c reference_parse.c \
+		hash.c sigs.c pack_create_io.c pollfd.c reference_parse.c \
 		repo_imsg.c pack_index.c session.c
 
 MAN =		${PROG}.conf.5 ${PROG}.8
blob - add224699cba16029f54df09a6eb6251d2024151
blob + 86f2b6013f0c53e31f8adbc89cd954b062c2ee0b
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -51,7 +51,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_cache.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_gitproto.h"
 #include "got_lib_pack.h"
 #include "got_lib_repository.h"
blob - 72bc2318a2e2469d1d4a9457ed349c23d3702aea
blob + a4d19987c878bbc0be5a08026bc1ba88bf3a3f11
--- gotd/repo_imsg.c
+++ gotd/repo_imsg.c
@@ -31,7 +31,7 @@
 #include "got_error.h"
 #include "got_object.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #include "gotd.h"
 #include "log.h"
blob - 5c07746639cfa5d1c884730820173d58ce732e99
blob + fa9d0fe7c98493ac9d2d6fa32f34baa5310f2e37
--- gotd/repo_read.c
+++ gotd/repo_read.c
@@ -41,7 +41,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_pack.h"
 #include "got_lib_ratelimit.h"
 #include "got_lib_pack_create.h"
blob - 6d6724b362817fa71e5534b1f0d9211eaa8bb269
blob + c197d823d83784df03e500477acc95e08487eff0
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -52,7 +52,7 @@
 #include "got_lib_repository.h"
 #include "got_lib_poll.h"
 
-#include "got_lib_sha1.h" /* XXX temp include for debugging */
+#include "got_lib_hash.h" /* XXX temp include for debugging */
 
 #include "log.h"
 #include "gotd.h"
blob - 5bab9972301d215e1afe68a371dab2c35484b9bd
blob + 8f00f2699c2d87d84a815df4188c27ed9fcc45c0
--- gotd/session.c
+++ gotd/session.c
@@ -41,7 +41,7 @@
 #include "got_reference.h"
 #include "got_opentemp.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_cache.h"
blob - 8cce24717276094756bd1d95fbe9d738ab14a8da
blob + 3772cc684ff07adb2559919352418b7232dc14ec
--- gotsh/Makefile
+++ gotsh/Makefile
@@ -3,7 +3,7 @@
 .include "../got-version.mk"
 
 PROG=		gotsh
-SRCS=		gotsh.c error.c pkt.c sha1.c serve.c path.c gitproto.c \
+SRCS=		gotsh.c error.c pkt.c hash.c serve.c path.c gitproto.c \
 		imsg.c inflate.c object_parse.c pollfd.c reference_parse.c
 
 MAN =		${PROG}.1
blob - 58d428b99c43b2fba80028b6233bcd4ff6c7e4a4
blob + 05240d53214a844ee3d7b7d988783c9e4cfd7147
--- gotwebd/libexec/got-read-blob/Makefile
+++ gotwebd/libexec/got-read-blob/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-blob
 SRCS=		got-read-blob.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 669332cc8be5487a26cc868b873f782c7e351623
blob + 1165c222b775505baa64d377371c136878c607c8
--- gotwebd/libexec/got-read-commit/Makefile
+++ gotwebd/libexec/got-read-commit/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-commit
 SRCS=		got-read-commit.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - d81d4666fc3206a3008ddfc673992c5ec3265bd9
blob + e7bc462853862dcc5569354205b83cfa255442c1
--- gotwebd/libexec/got-read-gitconfig/Makefile
+++ gotwebd/libexec/got-read-gitconfig/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-gitconfig
 SRCS=		got-read-gitconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c gitconfig.c pollfd.c
+		path.c privsep.c hash.c gitconfig.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - abc9574b7efb93c971c76b3576970c8c19ba0e14
blob + dba200d19f6705b4dd9f5cd7a449af9a216da7f3
--- gotwebd/libexec/got-read-gotconfig/Makefile
+++ gotwebd/libexec/got-read-gotconfig/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-gotconfig
 SRCS=		got-read-gotconfig.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c parse.y pollfd.c
+		path.c privsep.c hash.c parse.y pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib \
 	-I${.CURDIR}/../../../libexec/got-read-gotconfig
blob - 1c3afaf56bad757cf3c8b9574bc12521adbda7bb
blob + 97907ead0bd33b477aa7c06d62d666b9c00564ab
--- gotwebd/libexec/got-read-object/Makefile
+++ gotwebd/libexec/got-read-object/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-object
 SRCS=		got-read-object.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 9c1bf08b6d1c6cea526cdb38361ef89dfce5bc32
blob + 12228b03188af547ebf7a86b8f434b966ed06b98
--- gotwebd/libexec/got-read-pack/Makefile
+++ gotwebd/libexec/got-read-pack/Makefile
@@ -4,7 +4,7 @@
 PROG=		got-read-pack
 SRCS=		got-read-pack.c delta.c error.c inflate.c object_cache.c \
 		object_idset.c object_parse.c opentemp.c pack.c path.c \
-		privsep.c sha1.c delta_cache.c pollfd.c
+		privsep.c hash.c delta_cache.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 450ee15c54e4904304143c4129f1adf9fd085073
blob + e3695245b3e0161a86859b3cb3e10a413f4d74bb
--- gotwebd/libexec/got-read-tag/Makefile
+++ gotwebd/libexec/got-read-tag/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-tag
 SRCS=		got-read-tag.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - 20c0a23b3bf5a858afe4cd8a8e2d57c5194dd074
blob + db849065b699533903ca1e34443e2612c1983ec8
--- gotwebd/libexec/got-read-tree/Makefile
+++ gotwebd/libexec/got-read-tree/Makefile
@@ -3,7 +3,7 @@
 
 PROG=		got-read-tree
 SRCS=		got-read-tree.c error.c inflate.c object_parse.c \
-		path.c privsep.c sha1.c pollfd.c
+		path.c privsep.c hash.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
 LDADD = -lutil -lz
blob - c01cc8837461eb7b1dfd30772793a0de45a6d5e1
blob + d1653d5ea01b5a705d217e11e377641ac005f81a
--- lib/fetch.c
+++ lib/fetch.c
@@ -54,7 +54,7 @@
 #include "got_lib_object_parse.h"
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_privsep.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
blob - /dev/null
blob + 141cb2590fa14834c63381929a0a7438ae3e4556 (mode 644)
--- /dev/null
+++ lib/got_lib_hash.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
+
+int got_parse_xdigit(uint8_t *, const char *);
+int got_parse_sha1_digest(uint8_t *, const char *);
+char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
blob - 141cb2590fa14834c63381929a0a7438ae3e4556 (mode 644)
blob + /dev/null
--- lib/got_lib_sha1.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
-
-int got_parse_xdigit(uint8_t *, const char *);
-int got_parse_sha1_digest(uint8_t *, const char *);
-char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
blob - /dev/null
blob + fb4d3a30adf9281507aea3424f4c2711b1d3a28c (mode 644)
--- /dev/null
+++ lib/hash.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sha1.h>
+#include <sha2.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "got_lib_hash.h"
+
+int
+got_parse_xdigit(uint8_t *val, const char *hex)
+{
+	char *ep;
+	long lval;
+
+	errno = 0;
+	lval = strtol(hex, &ep, 16);
+	if (hex[0] == '\0' || *ep != '\0')
+		return 0;
+	if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
+		return 0;
+
+	*val = (uint8_t)lval;
+	return 1;
+}
+
+int
+got_parse_sha1_digest(uint8_t *digest, const char *line)
+{
+	uint8_t b = 0;
+	char hex[3] = {'\0', '\0', '\0'};
+	int i, j;
+
+	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+		if (line[0] == '\0' || line[1] == '\0')
+			return 0;
+		for (j = 0; j < 2; j++) {
+			hex[j] = *line;
+			line++;
+		}
+		if (!got_parse_xdigit(&b, hex))
+			return 0;
+		digest[i] = b;
+	}
+
+	return 1;
+}
+
+char *
+got_sha1_digest_to_str(const uint8_t *digest, char *buf, size_t size)
+{
+	char *p = buf;
+	char hex[3];
+	int i;
+
+	if (size < SHA1_DIGEST_STRING_LENGTH)
+		return NULL;
+
+	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
+		p[0] = hex[0];
+		p[1] = hex[1];
+		p += 2;
+	}
+	p[0] = '\0';
+
+	return buf;
+}
blob - a546494da113e2d558fc2eb147d3141a079c7785
blob + 4ef56fa20be5663cfbadd88d65956dfc21e3bc16
--- lib/object.c
+++ lib/object.c
@@ -41,7 +41,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - be13c8d702b305317bd3e969900e57e10fc8ed19
blob + f6192a34743b0946a30d5bde0d040aaa50fcf565
--- lib/object_create.c
+++ lib/object_create.c
@@ -41,7 +41,7 @@
 #include "got_path.h"
 #include "got_sigs.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_deflate.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
blob - 9134c4d89a2ac85bc8f042fcac6c155eb388b42d
blob + d9f9ca9342e72dc31a186ed29f25340cc436e026
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -43,7 +43,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 88eac8e049e09940fdf4502093bb94a1dd401155
blob + 6fdb0cb7f7be57147a2d9afea57266b748de3ceb
--- lib/pack.c
+++ lib/pack.c
@@ -39,7 +39,7 @@
 #include "got_object.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_delta_cache.h"
 #include "got_lib_inflate.h"
blob - 109239b2d4894e2c87f0148253ee45502875815c
blob + d7107177f8056953e03aac01278c49f2aee6f81f
--- lib/pack_index.c
+++ lib/pack_index.c
@@ -44,7 +44,7 @@
 #include "got_error.h"
 #include "got_object.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 8bce7c79a63eb6eb98f5ff2c4da3480873214091
blob + 907dd4c008e199ac9a5aaea0988c4b560c5e48da
--- lib/patch.c
+++ lib/patch.c
@@ -52,7 +52,7 @@
 #include "got_lib_diff.h"
 #include "got_lib_object.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
blob - e59c5ab3dda64a73d6bd82c91cafb0cf8961e5ca
blob + 9db6a51ca622a95d1e726e3981ae8eae8ce36baa
--- lib/privsep.c
+++ lib/privsep.c
@@ -42,7 +42,7 @@
 #include "got_path.h"
 #include "got_repository.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - 240489c3fc887c1ce88a8c3855db26b5f2f3e9d0
blob + 8395bfeace67cdc2bb1963683124b6e736e2b829
--- lib/reference.c
+++ lib/reference.c
@@ -40,7 +40,7 @@
 #include "got_opentemp.h"
 #include "got_path.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_inflate.h"
 #include "got_lib_object.h"
blob - cb43902e3c3f12ec6557c016120b8f8eb3b84eed
blob + 3a7d41743859cdc6a9849f722ab1316fd01c3378
--- lib/repository.c
+++ lib/repository.c
@@ -57,7 +57,7 @@
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
 #include "got_lib_gotconfig.h"
blob - d7c8c157af446b252d5c468bf1973c70397fdff3
blob + 199a3f8e3e341c8bff1f5832c6940113a46aec4e
--- lib/repository_admin.c
+++ lib/repository_admin.c
@@ -51,7 +51,7 @@
 #include "got_lib_repository.h"
 #include "got_lib_ratelimit.h"
 #include "got_lib_pack_create.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_lockfile.h"
 
 #ifndef nitems
blob - 27ef7aeeeadad231b60c84628b00f78b01f736ef
blob + 8b67c7387e3758b68ca9a209fee1ec16d740c5f5
--- lib/send.c
+++ lib/send.c
@@ -57,7 +57,7 @@
 #include "got_lib_object_parse.h"
 #include "got_lib_object_create.h"
 #include "got_lib_pack.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_privsep.h"
 #include "got_lib_object_cache.h"
 #include "got_lib_repository.h"
blob - 60dd15ebfc8b426232f914b885a6eee42cb2d796
blob + 9ce8b57d42611e46e1bd5ae68821685cc61c22f4
--- lib/serve.c
+++ lib/serve.c
@@ -40,7 +40,7 @@
 #include "got_lib_pkt.h"
 #include "got_lib_dial.h"
 #include "got_lib_gitproto.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_poll.h"
 
 #include "gotd.h"
blob - d5f67b96e272e2e65f3e2ec69bf558f0d0aa56de (mode 644)
blob + /dev/null
--- lib/sha1.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sha1.h>
-#include <sha2.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#include "got_compat.h"
-
-#include "got_lib_sha1.h"
-
-int
-got_parse_xdigit(uint8_t *val, const char *hex)
-{
-	char *ep;
-	long lval;
-
-	errno = 0;
-	lval = strtol(hex, &ep, 16);
-	if (hex[0] == '\0' || *ep != '\0')
-		return 0;
-	if (errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN))
-		return 0;
-
-	*val = (uint8_t)lval;
-	return 1;
-}
-
-int
-got_parse_sha1_digest(uint8_t *digest, const char *line)
-{
-	uint8_t b = 0;
-	char hex[3] = {'\0', '\0', '\0'};
-	int i, j;
-
-	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-		if (line[0] == '\0' || line[1] == '\0')
-			return 0;
-		for (j = 0; j < 2; j++) {
-			hex[j] = *line;
-			line++;
-		}
-		if (!got_parse_xdigit(&b, hex))
-			return 0;
-		digest[i] = b;
-	}
-
-	return 1;
-}
-
-char *
-got_sha1_digest_to_str(const uint8_t *digest, char *buf, size_t size)
-{
-	char *p = buf;
-	char hex[3];
-	int i;
-
-	if (size < SHA1_DIGEST_STRING_LENGTH)
-		return NULL;
-
-	for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-		snprintf(hex, sizeof(hex), "%.2x", digest[i]);
-		p[0] = hex[0];
-		p[1] = hex[1];
-		p += 2;
-	}
-	p[0] = '\0';
-
-	return buf;
-}
blob - c6a90ed062ccd606964a33008ecc5f3041cd4842
blob + a424e3f1830c17a447d81ea2f6e292e5f083a99e
--- lib/worktree.c
+++ lib/worktree.c
@@ -46,7 +46,7 @@
 #include "got_diff.h"
 
 #include "got_lib_worktree.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_fileindex.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
blob - 87bcbeb9778d606478f97973c34c3545f89722ec
blob + 08cd48242d80bee13639c2b118d56b1ae63b12ea
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
@@ -44,7 +44,7 @@
 #include "got_fetch.h"
 #include "got_reference.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
blob - 13b6fb33b7a027a67fc0b3d26d0d406dc484cb42
blob + e3585b55aa62667c2d5cbed241aea748587cd81a
--- libexec/got-read-commit/got-read-commit.c
+++ libexec/got-read-commit/got-read-commit.c
@@ -40,7 +40,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - a450e945b50a92bc3875f7252f1fc8e3564f9646
blob + 7f1ce849f295d9e828390f937eb1592727c2740d
--- libexec/got-read-object/got-read-object.c
+++ libexec/got-read-object/got-read-object.c
@@ -40,7 +40,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 #ifndef nitems
 #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
blob - f6d3344da01fc58b0c5ff5c93250a5d9cc7004a3
blob + a2e4e1de5f50b7d195f309b051b448e82c5db505
--- libexec/got-read-patch/got-read-patch.c
+++ libexec/got-read-patch/got-read-patch.c
@@ -58,7 +58,7 @@
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 struct imsgbuf ibuf;
 
blob - 1922e7763282b5dc4ba25e0efde728f4041fc1f7
blob + 642e553b60969e0c04c5e0a504c693d0e4948800
--- libexec/got-read-tag/got-read-tag.c
+++ libexec/got-read-tag/got-read-tag.c
@@ -40,7 +40,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - 3086a3694e4d93b72cc881fd1cbb29f4e355269c
blob + 07813d96167a79b5b21e10dd4adf7d1f55f9b530
--- libexec/got-read-tree/got-read-tree.c
+++ libexec/got-read-tree/got-read-tree.c
@@ -41,7 +41,7 @@
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
 #include "got_lib_privsep.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 
 static volatile sig_atomic_t sigint_received;
 
blob - 4e6166391e21ab54e9b5db0fa8fb826ce8298bfa
blob + 902a0a8ab722ccfd8def0d5a6a32823394675f96
--- libexec/got-send-pack/got-send-pack.c
+++ libexec/got-send-pack/got-send-pack.c
@@ -43,7 +43,7 @@
 #include "got_fetch.h"
 #include "got_reference.h"
 
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
 #include "got_lib_object_parse.h"
blob - 7c1c0a3a874d31efc8dfdaaf62f35c2f29701ee5
blob + 475dd4289d617e4ccfde05e7dd965aadacae6aff
--- regress/delta/Makefile
+++ regress/delta/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = delta_test
-SRCS = delta.c error.c opentemp.c path.c inflate.c sha1.c delta_test.c \
+SRCS = delta.c error.c opentemp.c path.c inflate.c hash.c delta_test.c \
 	pollfd.c object_parse.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 31a968efd9dc6f1669b141bb1dfea69b5cc8abbb
blob + c89d76ee9c4539c7d7c3907089ab2b233a8744a2
--- regress/deltify/Makefile
+++ regress/deltify/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = deltify_test
-SRCS = deltify.c error.c opentemp.c sha1.c deltify_test.c murmurhash2.c \
+SRCS = deltify.c error.c opentemp.c hash.c deltify_test.c murmurhash2.c \
 	object_parse.c inflate.c path.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 70bf4f896a17b76140e11c227248938fe1c0ac7a
blob + 4c3c7abb0a9b0de487050e9bc9149cb0d46f9749
--- regress/fetch/Makefile
+++ regress/fetch/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = fetch_test
-SRCS = error.c privsep.c reference.c sha1.c object.c object_parse.c path.c \
+SRCS = error.c privsep.c reference.c hash.c object.c object_parse.c path.c \
 	opentemp.c repository.c lockfile.c object_cache.c pack.c inflate.c \
 	deflate.c delta.c delta_cache.c object_idset.c object_create.c \
 	fetch.c gotconfig.c dial.c fetch_test.c bloom.c murmurhash2.c sigs.c \
blob - e4defb763447ad087297a8dbd741450eb4563f04
blob + c024c69ae8a0fd18330ae5c8f6dc6b872026966e
--- regress/fetch/fetch_test.c
+++ regress/fetch/fetch_test.c
@@ -35,7 +35,7 @@
 #include "got_dial.h"
 
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
 
blob - f835e9f283dceca9d301438c5813505b06d0aa43
blob + 6b78a4717b9682af0793283e080f4458ab6a8b8e
--- regress/idset/Makefile
+++ regress/idset/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = idset_test
-SRCS = error.c sha1.c object_idset.c inflate.c path.c object_parse.c \
+SRCS = error.c hash.c object_idset.c inflate.c path.c object_parse.c \
 	idset_test.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 686196fc5aecb11d94216d1536ba42fd2acaaf77
blob + 511fd016b578a9308aede2f46618c2b7b6a353c2
--- regress/idset/idset_test.c
+++ regress/idset/idset_test.c
@@ -31,7 +31,7 @@
 #include "got_object.h"
 
 #include "got_lib_object_idset.h"
-#include "got_lib_sha1.h"
+#include "got_lib_hash.h"
 #include "got_lib_inflate.h"
 #include "got_lib_delta.h"
 #include "got_lib_object.h"
blob - 213cea213945e44b6aa28f0953faf6657f8c5a41
blob + 23a916db855dd46d0844a60ae1b609c2e9c37279
--- regress/path/Makefile
+++ regress/path/Makefile
@@ -1,7 +1,7 @@
 .PATH:${.CURDIR}/../../lib
 
 PROG = path_test
-SRCS = error.c path.c sha1.c path_test.c object_parse.c inflate.c pollfd.c
+SRCS = error.c path.c hash.c path_test.c object_parse.c inflate.c pollfd.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lutil -lz