]>
git.proxmox.com Git - libgit2.git/blob - src/hash.c
2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
10 int git_hash_global_init(void)
12 return git_hash_sha1_global_init();
15 int git_hash_ctx_init(git_hash_ctx
*ctx
)
19 if ((error
= git_hash_sha1_ctx_init(&ctx
->ctx
.sha1
)) < 0)
22 ctx
->algo
= GIT_HASH_ALGO_SHA1
;
27 void git_hash_ctx_cleanup(git_hash_ctx
*ctx
)
30 case GIT_HASH_ALGO_SHA1
:
31 git_hash_sha1_ctx_cleanup(&ctx
->ctx
.sha1
);
38 int git_hash_init(git_hash_ctx
*ctx
)
41 case GIT_HASH_ALGO_SHA1
:
42 return git_hash_sha1_init(&ctx
->ctx
.sha1
);
50 int git_hash_update(git_hash_ctx
*ctx
, const void *data
, size_t len
)
53 case GIT_HASH_ALGO_SHA1
:
54 return git_hash_sha1_update(&ctx
->ctx
.sha1
, data
, len
);
62 int git_hash_final(git_oid
*out
, git_hash_ctx
*ctx
)
65 case GIT_HASH_ALGO_SHA1
:
66 return git_hash_sha1_final(out
, &ctx
->ctx
.sha1
);
74 int git_hash_buf(git_oid
*out
, const void *data
, size_t len
)
79 if (git_hash_ctx_init(&ctx
) < 0)
82 if ((error
= git_hash_update(&ctx
, data
, len
)) >= 0)
83 error
= git_hash_final(out
, &ctx
);
85 git_hash_ctx_cleanup(&ctx
);
90 int git_hash_vec(git_oid
*out
, git_buf_vec
*vec
, size_t n
)
96 if (git_hash_ctx_init(&ctx
) < 0)
99 for (i
= 0; i
< n
; i
++) {
100 if ((error
= git_hash_update(&ctx
, vec
[i
].data
, vec
[i
].len
)) < 0)
104 error
= git_hash_final(out
, &ctx
);
107 git_hash_ctx_cleanup(&ctx
);