]>
Commit | Line | Data |
---|---|---|
d9c0dbb0 CMN |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
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. | |
6 | */ | |
7 | ||
8 | #ifndef INCLUDE_hash_common_crypto_h__ | |
9 | #define INCLUDE_hash_common_crypto_h__ | |
10 | ||
11 | #include "hash.h" | |
12 | ||
13 | #include <CommonCrypto/CommonDigest.h> | |
14 | ||
15 | struct git_hash_ctx { | |
16 | CC_SHA1_CTX c; | |
17 | }; | |
18 | ||
19 | #define git_hash_global_init() 0 | |
20 | #define git_hash_ctx_init(ctx) git_hash_init(ctx) | |
21 | #define git_hash_ctx_cleanup(ctx) | |
22 | ||
23 | GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) | |
24 | { | |
25 | assert(ctx); | |
26 | CC_SHA1_Init(&ctx->c); | |
27 | return 0; | |
28 | } | |
29 | ||
30 | GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) | |
31 | { | |
32 | assert(ctx); | |
33 | CC_SHA1_Update(&ctx->c, data, len); | |
34 | return 0; | |
35 | } | |
36 | ||
37 | GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) | |
38 | { | |
39 | assert(ctx); | |
40 | CC_SHA1_Final(out->id, &ctx->c); | |
41 | return 0; | |
42 | } | |
43 | ||
44 | #endif /* INCLUDE_hash_common_crypto_h__ */ |