]>
Commit | Line | Data |
---|---|---|
d6fb0924 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
d6fb0924 ET |
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 | ||
22a2d3d5 | 8 | #include "openssl.h" |
d6fb0924 | 9 | |
22a2d3d5 UG |
10 | int git_hash_sha1_global_init(void) |
11 | { | |
12 | return 0; | |
13 | } | |
d6fb0924 | 14 | |
22a2d3d5 UG |
15 | int git_hash_sha1_ctx_init(git_hash_sha1_ctx *ctx) |
16 | { | |
17 | return git_hash_sha1_init(ctx); | |
18 | } | |
d6fb0924 | 19 | |
22a2d3d5 | 20 | void git_hash_sha1_ctx_cleanup(git_hash_sha1_ctx *ctx) |
ac3d33df | 21 | { |
22a2d3d5 | 22 | GIT_UNUSED(ctx); |
ac3d33df JK |
23 | } |
24 | ||
22a2d3d5 | 25 | int git_hash_sha1_init(git_hash_sha1_ctx *ctx) |
d6fb0924 | 26 | { |
c25aa7cd | 27 | GIT_ASSERT_ARG(ctx); |
eae0bfdc PP |
28 | |
29 | if (SHA1_Init(&ctx->c) != 1) { | |
ac3d33df | 30 | git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to initialize hash context"); |
eae0bfdc PP |
31 | return -1; |
32 | } | |
33 | ||
d6fb0924 ET |
34 | return 0; |
35 | } | |
36 | ||
22a2d3d5 | 37 | int git_hash_sha1_update(git_hash_sha1_ctx *ctx, const void *data, size_t len) |
d6fb0924 | 38 | { |
c25aa7cd | 39 | GIT_ASSERT_ARG(ctx); |
eae0bfdc PP |
40 | |
41 | if (SHA1_Update(&ctx->c, data, len) != 1) { | |
ac3d33df | 42 | git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to update hash"); |
eae0bfdc PP |
43 | return -1; |
44 | } | |
45 | ||
d6fb0924 ET |
46 | return 0; |
47 | } | |
48 | ||
22a2d3d5 | 49 | int git_hash_sha1_final(git_oid *out, git_hash_sha1_ctx *ctx) |
d6fb0924 | 50 | { |
c25aa7cd | 51 | GIT_ASSERT_ARG(ctx); |
eae0bfdc PP |
52 | |
53 | if (SHA1_Final(out->id, &ctx->c) != 1) { | |
ac3d33df | 54 | git_error_set(GIT_ERROR_SHA1, "hash_openssl: failed to finalize hash"); |
eae0bfdc PP |
55 | return -1; |
56 | } | |
57 | ||
d6fb0924 ET |
58 | return 0; |
59 | } |