Commit 36df49c26d93f4d5cc14db48a40316b29945bcd4

Edward Thomson 2021-12-12T14:29:11

sha: GIT_ERROR_SHA1 is deprecated in favor of GIT_ERROR_SHA The more generic GIT_ERROR_SHA allows for SHA256 errors as well as SHA1.

diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index f73d7da..c32abee 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -436,6 +436,8 @@ GIT_EXTERN(int) git_diff_format_email_options_init(
 #define GITERR_WORKTREE GIT_ERROR_WORKTREE
 #define GITERR_SHA1 GIT_ERROR_SHA1
 
+#define GIT_ERROR_SHA1 GIT_ERROR_SHA
+
 /**
  * Return the last `git_error` object that was generated for the
  * current thread.  This is an alias of `git_error_last` and is
diff --git a/include/git2/errors.h b/include/git2/errors.h
index 62f3635..aba6d75 100644
--- a/include/git2/errors.h
+++ b/include/git2/errors.h
@@ -106,7 +106,7 @@ typedef enum {
 	GIT_ERROR_FILESYSTEM,
 	GIT_ERROR_PATCH,
 	GIT_ERROR_WORKTREE,
-	GIT_ERROR_SHA1,
+	GIT_ERROR_SHA,
 	GIT_ERROR_HTTP,
 	GIT_ERROR_INTERNAL
 } git_error_t;
diff --git a/src/util/hash/collisiondetect.c b/src/util/hash/collisiondetect.c
index ec7059c..c51a402 100644
--- a/src/util/hash/collisiondetect.c
+++ b/src/util/hash/collisiondetect.c
@@ -40,7 +40,7 @@ int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 {
 	GIT_ASSERT_ARG(ctx);
 	if (SHA1DCFinal(out, &ctx->c)) {
-		git_error_set(GIT_ERROR_SHA1, "SHA1 collision attack detected");
+		git_error_set(GIT_ERROR_SHA, "SHA1 collision attack detected");
 		return -1;
 	}
 
diff --git a/src/util/hash/openssl.c b/src/util/hash/openssl.c
index 64bf99b..2011edf 100644
--- a/src/util/hash/openssl.c
+++ b/src/util/hash/openssl.c
@@ -27,7 +27,7 @@ int git_hash_sha1_init(git_hash_sha1_ctx *ctx)
 	GIT_ASSERT_ARG(ctx);
 
 	if (SHA1_Init(&ctx->c) != 1) {
-		git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to initialize hash context");
+		git_error_set(GIT_ERROR_SHA, "hash_openssl: failed to initialize hash context");
 		return -1;
 	}
 
@@ -39,7 +39,7 @@ int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len)
 	GIT_ASSERT_ARG(ctx);
 
 	if (SHA1_Update(&ctx->c, data, len) != 1) {
-		git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to update hash");
+		git_error_set(GIT_ERROR_SHA, "hash_openssl: failed to update hash");
 		return -1;
 	}
 
@@ -51,7 +51,7 @@ int git_hash_sha1_final(unsigned char *out, git_hash_sha1_ctx *ctx)
 	GIT_ASSERT_ARG(ctx);
 
 	if (SHA1_Final(out, &ctx->c) != 1) {
-		git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash");
+		git_error_set(GIT_ERROR_SHA, "hash_openssl: failed to finalize hash");
 		return -1;
 	}
 
diff --git a/src/util/hash/win32.c b/src/util/hash/win32.c
index b89dfba..0e93593 100644
--- a/src/util/hash/win32.c
+++ b/src/util/hash/win32.c
@@ -35,7 +35,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
 
 	/* Only use CNG on Windows 2008 / Vista SP1  or better (Windows 6.0 SP1) */
 	if (!git_has_win32_version(6, 0, 1)) {
-		git_error_set(GIT_ERROR_SHA1, "CryptoNG is not supported on this platform");
+		git_error_set(GIT_ERROR_SHA, "CryptoNG is not supported on this platform");
 		return -1;
 	}
 
@@ -45,7 +45,7 @@ GIT_INLINE(int) hash_cng_prov_init(void)
 		StringCchCat(dll_path, MAX_PATH, "\\") < 0 ||
 		StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 ||
 		(hash_prov.prov.cng.dll = LoadLibrary(dll_path)) == NULL) {
-		git_error_set(GIT_ERROR_SHA1, "CryptoNG library could not be loaded");
+		git_error_set(GIT_ERROR_SHA, "CryptoNG library could not be loaded");
 		return -1;
 	}