summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-20 08:10:46 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-20 08:10:46 (GMT)
commitd98b46f8d9a3daf965a39f8c0089c1401e0081ee (patch)
tree765ea3ef9d7d57d29a38d4c1d1ddc4be17554936 /sha1_file.c
parentcb126d8d7906b3c15f313ca479259e567042840a (diff)
downloadgit-d98b46f8d9a3daf965a39f8c0089c1401e0081ee.zip
git-d98b46f8d9a3daf965a39f8c0089c1401e0081ee.tar.gz
git-d98b46f8d9a3daf965a39f8c0089c1401e0081ee.tar.bz2
Do SHA1 hash _before_ compression.
And add a "convert-cache" program to convert from old-style to new-style.
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sha1_file.c b/sha1_file.c
index bb44a01..40c00b7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -80,12 +80,14 @@ char *sha1_file_name(const unsigned char *sha1)
return base;
}
-int check_sha1_signature(unsigned char *sha1, void *map, unsigned long size)
+int check_sha1_signature(unsigned char *sha1, void *map, unsigned long size, const char *type)
{
+ char header[100];
unsigned char real_sha1[20];
SHA_CTX c;
SHA1_Init(&c);
+ SHA1_Update(&c, header, 1+sprintf(header, "%s %lu", type, size));
SHA1_Update(&c, map, size);
SHA1_Final(real_sha1, &c);
return memcmp(sha1, real_sha1, 20) ? -1 : 0;
@@ -172,6 +174,11 @@ int write_sha1_file(char *buf, unsigned len, unsigned char *returnsha1)
unsigned char sha1[20];
SHA_CTX c;
+ /* Sha1.. */
+ SHA1_Init(&c);
+ SHA1_Update(&c, buf, len);
+ SHA1_Final(sha1, &c);
+
/* Set it up */
memset(&stream, 0, sizeof(stream));
deflateInit(&stream, Z_BEST_COMPRESSION);
@@ -188,11 +195,6 @@ int write_sha1_file(char *buf, unsigned len, unsigned char *returnsha1)
deflateEnd(&stream);
size = stream.total_out;
- /* Sha1.. */
- SHA1_Init(&c);
- SHA1_Update(&c, compressed, size);
- SHA1_Final(sha1, &c);
-
if (write_sha1_buffer(sha1, compressed, size) < 0)
return -1;
if (returnsha1)