diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-20 01:10:46 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-20 01:10:46 -0700 |
commit | d98b46f8d9a3daf965a39f8c0089c1401e0081ee (patch) | |
tree | 765ea3ef9d7d57d29a38d4c1d1ddc4be17554936 /sha1_file.c | |
parent | cb126d8d7906b3c15f313ca479259e567042840a (diff) | |
download | git-d98b46f8d9a3daf965a39f8c0089c1401e0081ee.tar.gz |
Do SHA1 hash _before_ compression.conversion
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.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sha1_file.c b/sha1_file.c index bb44a01746..40c00b77d0 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) |