Commit Diff


commit - 89720b41149f2c392d7641dcf30b1259d3f71af6
commit + 87a4b05fb8b2ad9ea533436eaf47108b48ba66cf
blob - faf9e8a717096264c717436f464e9b6cbf22d64e
blob + 5518a1cb6ab9c8c2bceae1e6f0032960bd410327
--- lib/got_lib_hash.h
+++ lib/got_lib_hash.h
@@ -24,3 +24,5 @@ char *got_sha1_digest_to_str(const uint8_t *, char *, 
 
 int got_parse_sha256_digest(uint8_t *, const char *);
 char *got_sha256_digest_to_str(const uint8_t *, char *, size_t);
+
+int got_parse_hash_digest(uint8_t *, const char *, int, size_t *);
blob - 64485ff6dfa3d6b53ae14ed4929b4464fff2160f
blob + 7e3535126160cf2e341e9c48a9d1381337189e85
--- lib/hash.c
+++ lib/hash.c
@@ -15,6 +15,8 @@
  */
 
 #include <sys/types.h>
+#include <sys/queue.h>
+
 #include <sha1.h>
 #include <sha2.h>
 #include <errno.h>
@@ -24,6 +26,8 @@
 
 #include "got_lib_hash.h"
 
+#include "got_object.h"
+
 int
 got_parse_xdigit(uint8_t *val, const char *hex)
 {
@@ -126,3 +130,19 @@ got_sha256_digest_to_str(const uint8_t *digest, char *
 
 	return buf;
 }
+
+int
+got_parse_hash_digest(uint8_t *digest, const char *line, int algo, size_t *len)
+{
+	if (algo == GOT_HASH_SHA256) {
+		if (len)
+			*len = SHA256_DIGEST_STRING_LENGTH;
+		return got_parse_sha256_digest(digest, line);
+	} else if (algo == GOT_HASH_SHA1) {
+		if (len)
+			*len = SHA1_DIGEST_STRING_LENGTH;
+		return got_parse_sha1_digest(digest, line);
+	}
+
+	return 0;
+}