]>
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
->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
->sha1
);
38 int git_hash_init(git_hash_ctx
*ctx
)
41 case GIT_HASH_ALGO_SHA1
:
42 return git_hash_sha1_init(&ctx
->sha1
);
49 int git_hash_update(git_hash_ctx
*ctx
, const void *data
, size_t len
)
52 case GIT_HASH_ALGO_SHA1
:
53 return git_hash_sha1_update(&ctx
->sha1
, data
, len
);
60 int git_hash_final(git_oid
*out
, git_hash_ctx
*ctx
)
63 case GIT_HASH_ALGO_SHA1
:
64 return git_hash_sha1_final(out
, &ctx
->sha1
);
71 int git_hash_buf(git_oid
*out
, const void *data
, size_t len
)
76 if (git_hash_ctx_init(&ctx
) < 0)
79 if ((error
= git_hash_update(&ctx
, data
, len
)) >= 0)
80 error
= git_hash_final(out
, &ctx
);
82 git_hash_ctx_cleanup(&ctx
);
87 int git_hash_vec(git_oid
*out
, git_buf_vec
*vec
, size_t n
)
93 if (git_hash_ctx_init(&ctx
) < 0)
96 for (i
= 0; i
< n
; i
++) {
97 if ((error
= git_hash_update(&ctx
, vec
[i
].data
, vec
[i
].len
)) < 0)
101 error
= git_hash_final(out
, &ctx
);
104 git_hash_ctx_cleanup(&ctx
);