diff options
| author | Vicent Martà <vicent@github.com> | 2012-11-13 13:28:08 -0800 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2012-11-13 13:28:08 -0800 |
| commit | 3741a37f5ee80d7475cdfedcd4de7d8ea64cf1e8 (patch) | |
| tree | 8861ec34c51061c59ed2daf945d2b7cf77456fed /src/indexer.c | |
| parent | 70572ff80b071aae5d6b398572e1aa0be45f6844 (diff) | |
| parent | 2a612fe3c31f2c386236ccb1483741835a5db318 (diff) | |
| download | libgit2-3741a37f5ee80d7475cdfedcd4de7d8ea64cf1e8.tar.gz | |
Merge pull request #1055 from ethomson/sha1_win32
Win32 CryptoAPI and CNG support for SHA1
Diffstat (limited to 'src/indexer.c')
| -rw-r--r-- | src/indexer.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/indexer.c b/src/indexer.c index ec4ef7147..4a4ed325a 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -17,7 +17,6 @@ #include "posix.h" #include "pack.h" #include "filebuf.h" -#include "sha1.h" #define UINT31_MAX (0x7FFFFFFF) @@ -462,7 +461,10 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress * struct entry *entry; void *packfile_hash; git_oid file_hash; - SHA_CTX ctx; + git_hash_ctx ctx; + + if (git_hash_ctx_init(&ctx) < 0) + return -1; /* Test for this before resolve_deltas(), as it plays with idx->off */ if (idx->off < idx->pack->mwf.size - GIT_OID_RAWSZ) { @@ -502,12 +504,11 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress * } /* Write out the object names (SHA-1 hashes) */ - SHA1_Init(&ctx); git_vector_foreach(&idx->objects, i, entry) { git_filebuf_write(&idx->index_file, &entry->oid, sizeof(git_oid)); - SHA1_Update(&ctx, &entry->oid, GIT_OID_RAWSZ); + git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ); } - SHA1_Final(idx->hash.id, &ctx); + git_hash_final(&idx->hash, &ctx); /* Write out the CRC32 values */ git_vector_foreach(&idx->objects, i, entry) { @@ -582,6 +583,7 @@ on_error: p_close(idx->pack->mwf.fd); git_filebuf_cleanup(&idx->index_file); git_buf_free(&filename); + git_hash_ctx_cleanup(&ctx); return -1; } @@ -682,7 +684,10 @@ int git_indexer_write(git_indexer *idx) struct entry *entry; void *packfile_hash; git_oid file_hash; - SHA_CTX ctx; + git_hash_ctx ctx; + + if (git_hash_ctx_init(&ctx) < 0) + return -1; git_vector_sort(&idx->objects); @@ -712,14 +717,14 @@ int git_indexer_write(git_indexer *idx) } /* Write out the object names (SHA-1 hashes) */ - SHA1_Init(&ctx); git_vector_foreach(&idx->objects, i, entry) { - error = git_filebuf_write(&idx->file, &entry->oid, sizeof(git_oid)); - SHA1_Update(&ctx, &entry->oid, GIT_OID_RAWSZ); - if (error < 0) + if ((error = git_filebuf_write(&idx->file, &entry->oid, sizeof(git_oid))) < 0 || + (error = git_hash_update(&ctx, &entry->oid, GIT_OID_RAWSZ)) < 0) goto cleanup; } - SHA1_Final(idx->hash.id, &ctx); + + if ((error = git_hash_final(&idx->hash, &ctx)) < 0) + goto cleanup; /* Write out the CRC32 values */ git_vector_foreach(&idx->objects, i, entry) { @@ -797,6 +802,7 @@ cleanup: if (error < 0) git_filebuf_cleanup(&idx->file); git_buf_free(&filename); + git_hash_ctx_cleanup(&ctx); return error; } |
