rugged 0.17.0.b7 → 0.18.0.b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/README.md +88 -32
- data/ext/rugged/extconf.rb +4 -2
- data/ext/rugged/rugged.c +72 -10
- data/ext/rugged/rugged.h +14 -10
- data/ext/rugged/rugged_blob.c +8 -10
- data/ext/rugged/rugged_branch.c +11 -14
- data/ext/rugged/rugged_commit.c +31 -24
- data/ext/rugged/rugged_config.c +2 -2
- data/ext/rugged/rugged_index.c +133 -198
- data/ext/rugged/rugged_note.c +372 -0
- data/ext/rugged/rugged_object.c +50 -22
- data/ext/rugged/rugged_reference.c +122 -130
- data/ext/rugged/rugged_remote.c +72 -29
- data/ext/rugged/rugged_repo.c +402 -20
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +110 -0
- data/ext/rugged/rugged_signature.c +23 -7
- data/ext/rugged/rugged_tag.c +32 -16
- data/ext/rugged/rugged_tree.c +44 -15
- data/lib/rugged.rb +1 -0
- data/lib/rugged/index.rb +8 -0
- data/lib/rugged/remote.rb +13 -0
- data/lib/rugged/repository.rb +3 -3
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +13 -15
- data/test/branch_test.rb +32 -67
- data/test/commit_test.rb +50 -12
- data/test/config_test.rb +12 -11
- data/test/coverage/HEAD.json +1 -1
- data/test/coverage/cover.rb +40 -21
- data/test/errors_test.rb +34 -0
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
- data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
- data/test/index_test.rb +65 -69
- data/test/lib_test.rb +76 -11
- data/test/note_test.rb +158 -0
- data/test/object_test.rb +8 -11
- data/test/reference_test.rb +77 -85
- data/test/remote_test.rb +86 -8
- data/test/repo_pack_test.rb +9 -7
- data/test/repo_reset_test.rb +80 -0
- data/test/repo_test.rb +176 -53
- data/test/tag_test.rb +44 -7
- data/test/test_helper.rb +63 -35
- data/test/tree_test.rb +34 -13
- data/test/walker_test.rb +14 -14
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
- data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
- data/vendor/libgit2/deps/regex/regcomp.c +7 -6
- data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
- data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
- data/vendor/libgit2/deps/regex/regexec.c +5 -5
- data/vendor/libgit2/include/git2.h +5 -1
- data/vendor/libgit2/include/git2/attr.h +4 -2
- data/vendor/libgit2/include/git2/blob.h +39 -12
- data/vendor/libgit2/include/git2/branch.h +123 -35
- data/vendor/libgit2/include/git2/checkout.h +206 -48
- data/vendor/libgit2/include/git2/clone.h +72 -27
- data/vendor/libgit2/include/git2/commit.h +20 -17
- data/vendor/libgit2/include/git2/common.h +67 -1
- data/vendor/libgit2/include/git2/config.h +81 -60
- data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
- data/vendor/libgit2/include/git2/diff.h +459 -150
- data/vendor/libgit2/include/git2/errors.h +9 -1
- data/vendor/libgit2/include/git2/graph.h +41 -0
- data/vendor/libgit2/include/git2/ignore.h +7 -6
- data/vendor/libgit2/include/git2/index.h +323 -97
- data/vendor/libgit2/include/git2/indexer.h +27 -59
- data/vendor/libgit2/include/git2/inttypes.h +4 -0
- data/vendor/libgit2/include/git2/merge.h +13 -3
- data/vendor/libgit2/include/git2/message.h +14 -8
- data/vendor/libgit2/include/git2/net.h +9 -7
- data/vendor/libgit2/include/git2/notes.h +88 -29
- data/vendor/libgit2/include/git2/object.h +16 -6
- data/vendor/libgit2/include/git2/odb.h +80 -17
- data/vendor/libgit2/include/git2/odb_backend.h +47 -11
- data/vendor/libgit2/include/git2/oid.h +26 -17
- data/vendor/libgit2/include/git2/pack.h +62 -8
- data/vendor/libgit2/include/git2/push.h +131 -0
- data/vendor/libgit2/include/git2/refdb.h +103 -0
- data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
- data/vendor/libgit2/include/git2/reflog.h +30 -21
- data/vendor/libgit2/include/git2/refs.h +215 -193
- data/vendor/libgit2/include/git2/refspec.h +22 -2
- data/vendor/libgit2/include/git2/remote.h +158 -37
- data/vendor/libgit2/include/git2/repository.h +150 -31
- data/vendor/libgit2/include/git2/reset.h +43 -9
- data/vendor/libgit2/include/git2/revparse.h +48 -4
- data/vendor/libgit2/include/git2/revwalk.h +25 -10
- data/vendor/libgit2/include/git2/signature.h +20 -12
- data/vendor/libgit2/include/git2/stash.h +121 -0
- data/vendor/libgit2/include/git2/status.h +122 -53
- data/vendor/libgit2/include/git2/strarray.h +17 -11
- data/vendor/libgit2/include/git2/submodule.h +42 -7
- data/vendor/libgit2/include/git2/tag.h +72 -59
- data/vendor/libgit2/include/git2/threads.h +4 -2
- data/vendor/libgit2/include/git2/trace.h +68 -0
- data/vendor/libgit2/include/git2/transport.h +328 -0
- data/vendor/libgit2/include/git2/tree.h +149 -120
- data/vendor/libgit2/include/git2/types.h +13 -12
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/src/amiga/map.c +2 -2
- data/vendor/libgit2/src/attr.c +58 -48
- data/vendor/libgit2/src/attr.h +4 -18
- data/vendor/libgit2/src/attr_file.c +30 -6
- data/vendor/libgit2/src/attr_file.h +6 -8
- data/vendor/libgit2/src/attrcache.h +24 -0
- data/vendor/libgit2/src/blob.c +30 -7
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +361 -68
- data/vendor/libgit2/src/branch.h +17 -0
- data/vendor/libgit2/src/bswap.h +1 -1
- data/vendor/libgit2/src/buf_text.c +291 -0
- data/vendor/libgit2/src/buf_text.h +122 -0
- data/vendor/libgit2/src/buffer.c +27 -101
- data/vendor/libgit2/src/buffer.h +54 -39
- data/vendor/libgit2/src/cache.c +15 -6
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +3 -1
- data/vendor/libgit2/src/checkout.c +1165 -222
- data/vendor/libgit2/src/checkout.h +24 -0
- data/vendor/libgit2/src/clone.c +171 -86
- data/vendor/libgit2/src/commit.c +44 -45
- data/vendor/libgit2/src/commit.h +3 -3
- data/vendor/libgit2/src/commit_list.c +194 -0
- data/vendor/libgit2/src/commit_list.h +49 -0
- data/vendor/libgit2/src/common.h +44 -10
- data/vendor/libgit2/src/compress.c +1 -1
- data/vendor/libgit2/src/compress.h +1 -1
- data/vendor/libgit2/src/config.c +211 -124
- data/vendor/libgit2/src/config.h +23 -4
- data/vendor/libgit2/src/config_cache.c +2 -2
- data/vendor/libgit2/src/config_file.c +129 -53
- data/vendor/libgit2/src/config_file.h +10 -8
- data/vendor/libgit2/src/crlf.c +66 -67
- data/vendor/libgit2/src/date.c +12 -12
- data/vendor/libgit2/src/delta-apply.c +14 -1
- data/vendor/libgit2/src/delta-apply.h +18 -1
- data/vendor/libgit2/src/delta.c +40 -107
- data/vendor/libgit2/src/delta.h +19 -17
- data/vendor/libgit2/src/diff.c +347 -496
- data/vendor/libgit2/src/diff.h +27 -1
- data/vendor/libgit2/src/diff_output.c +564 -249
- data/vendor/libgit2/src/diff_output.h +15 -8
- data/vendor/libgit2/src/diff_tform.c +687 -0
- data/vendor/libgit2/src/errors.c +27 -36
- data/vendor/libgit2/src/fetch.c +13 -351
- data/vendor/libgit2/src/fetch.h +13 -3
- data/vendor/libgit2/src/fetchhead.c +295 -0
- data/vendor/libgit2/src/fetchhead.h +34 -0
- data/vendor/libgit2/src/filebuf.c +42 -15
- data/vendor/libgit2/src/filebuf.h +4 -2
- data/vendor/libgit2/src/fileops.c +466 -113
- data/vendor/libgit2/src/fileops.h +154 -28
- data/vendor/libgit2/src/filter.c +3 -75
- data/vendor/libgit2/src/filter.h +1 -29
- data/vendor/libgit2/src/fnmatch.c +1 -1
- data/vendor/libgit2/src/fnmatch.h +1 -1
- data/vendor/libgit2/src/global.c +54 -10
- data/vendor/libgit2/src/global.h +10 -1
- data/vendor/libgit2/src/graph.c +178 -0
- data/vendor/libgit2/src/hash.c +25 -52
- data/vendor/libgit2/src/hash.h +21 -9
- data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
- data/vendor/libgit2/src/hash/hash_generic.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
- data/vendor/libgit2/src/hash/hash_win32.c +291 -0
- data/vendor/libgit2/src/hash/hash_win32.h +140 -0
- data/vendor/libgit2/src/hashsig.c +368 -0
- data/vendor/libgit2/src/hashsig.h +72 -0
- data/vendor/libgit2/src/ignore.c +22 -15
- data/vendor/libgit2/src/ignore.h +6 -1
- data/vendor/libgit2/src/index.c +770 -171
- data/vendor/libgit2/src/index.h +13 -5
- data/vendor/libgit2/src/indexer.c +286 -431
- data/vendor/libgit2/src/iterator.c +854 -466
- data/vendor/libgit2/src/iterator.h +134 -109
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +296 -0
- data/vendor/libgit2/src/merge.h +22 -0
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/message.h +1 -1
- data/vendor/libgit2/src/mwindow.c +35 -30
- data/vendor/libgit2/src/mwindow.h +2 -2
- data/vendor/libgit2/src/netops.c +162 -98
- data/vendor/libgit2/src/netops.h +50 -15
- data/vendor/libgit2/src/notes.c +109 -58
- data/vendor/libgit2/src/notes.h +2 -1
- data/vendor/libgit2/src/object.c +46 -57
- data/vendor/libgit2/src/object.h +1 -8
- data/vendor/libgit2/src/odb.c +151 -40
- data/vendor/libgit2/src/odb.h +5 -1
- data/vendor/libgit2/src/odb_loose.c +4 -5
- data/vendor/libgit2/src/odb_pack.c +122 -80
- data/vendor/libgit2/src/offmap.h +65 -0
- data/vendor/libgit2/src/oid.c +12 -4
- data/vendor/libgit2/src/oidmap.h +1 -1
- data/vendor/libgit2/src/pack-objects.c +88 -61
- data/vendor/libgit2/src/pack-objects.h +8 -8
- data/vendor/libgit2/src/pack.c +293 -28
- data/vendor/libgit2/src/pack.h +49 -4
- data/vendor/libgit2/src/path.c +103 -14
- data/vendor/libgit2/src/path.h +23 -7
- data/vendor/libgit2/src/pathspec.c +168 -0
- data/vendor/libgit2/src/pathspec.h +40 -0
- data/vendor/libgit2/src/pool.c +29 -4
- data/vendor/libgit2/src/pool.h +8 -1
- data/vendor/libgit2/src/posix.c +26 -27
- data/vendor/libgit2/src/posix.h +2 -3
- data/vendor/libgit2/src/pqueue.c +23 -1
- data/vendor/libgit2/src/pqueue.h +23 -1
- data/vendor/libgit2/src/push.c +653 -0
- data/vendor/libgit2/src/push.h +51 -0
- data/vendor/libgit2/src/refdb.c +185 -0
- data/vendor/libgit2/src/refdb.h +46 -0
- data/vendor/libgit2/src/refdb_fs.c +1024 -0
- data/vendor/libgit2/src/refdb_fs.h +15 -0
- data/vendor/libgit2/src/reflog.c +77 -45
- data/vendor/libgit2/src/reflog.h +1 -3
- data/vendor/libgit2/src/refs.c +366 -1326
- data/vendor/libgit2/src/refs.h +22 -13
- data/vendor/libgit2/src/refspec.c +46 -7
- data/vendor/libgit2/src/refspec.h +11 -1
- data/vendor/libgit2/src/remote.c +758 -120
- data/vendor/libgit2/src/remote.h +10 -5
- data/vendor/libgit2/src/repo_template.h +6 -6
- data/vendor/libgit2/src/repository.c +315 -96
- data/vendor/libgit2/src/repository.h +5 -3
- data/vendor/libgit2/src/reset.c +99 -81
- data/vendor/libgit2/src/revparse.c +157 -84
- data/vendor/libgit2/src/revwalk.c +68 -470
- data/vendor/libgit2/src/revwalk.h +44 -0
- data/vendor/libgit2/src/sha1_lookup.c +1 -1
- data/vendor/libgit2/src/sha1_lookup.h +1 -1
- data/vendor/libgit2/src/signature.c +68 -200
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/stash.c +663 -0
- data/vendor/libgit2/src/status.c +101 -79
- data/vendor/libgit2/src/strmap.h +1 -1
- data/vendor/libgit2/src/submodule.c +67 -51
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/tag.c +35 -29
- data/vendor/libgit2/src/tag.h +1 -1
- data/vendor/libgit2/src/thread-utils.c +1 -1
- data/vendor/libgit2/src/thread-utils.h +2 -2
- data/vendor/libgit2/src/trace.c +39 -0
- data/vendor/libgit2/src/trace.h +56 -0
- data/vendor/libgit2/src/transport.c +81 -34
- data/vendor/libgit2/src/transports/cred.c +60 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
- data/vendor/libgit2/src/transports/git.c +234 -127
- data/vendor/libgit2/src/transports/http.c +761 -433
- data/vendor/libgit2/src/transports/local.c +460 -64
- data/vendor/libgit2/src/transports/smart.c +345 -0
- data/vendor/libgit2/src/transports/smart.h +179 -0
- data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
- data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
- data/vendor/libgit2/src/transports/winhttp.c +1136 -0
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree-cache.h +1 -1
- data/vendor/libgit2/src/tree.c +239 -166
- data/vendor/libgit2/src/tree.h +11 -2
- data/vendor/libgit2/src/tsort.c +39 -23
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +12 -2
- data/vendor/libgit2/src/unix/realpath.c +30 -0
- data/vendor/libgit2/src/util.c +250 -13
- data/vendor/libgit2/src/util.h +71 -14
- data/vendor/libgit2/src/vector.c +123 -60
- data/vendor/libgit2/src/vector.h +24 -22
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/dir.h +1 -1
- data/vendor/libgit2/src/win32/error.c +77 -0
- data/vendor/libgit2/src/win32/error.h +13 -0
- data/vendor/libgit2/src/win32/findfile.c +143 -54
- data/vendor/libgit2/src/win32/findfile.h +10 -6
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
- data/vendor/libgit2/src/win32/posix.h +10 -1
- data/vendor/libgit2/src/win32/posix_w32.c +132 -63
- data/vendor/libgit2/src/win32/precompiled.c +1 -1
- data/vendor/libgit2/src/win32/pthread.c +1 -1
- data/vendor/libgit2/src/win32/pthread.h +1 -1
- data/vendor/libgit2/src/win32/utf-conv.c +5 -5
- data/vendor/libgit2/src/win32/utf-conv.h +3 -3
- data/vendor/libgit2/src/win32/version.h +20 -0
- metadata +308 -252
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb~ +0 -218
- data/vendor/libgit2/src/pkt.h +0 -91
- data/vendor/libgit2/src/ppc/sha1.c +0 -70
- data/vendor/libgit2/src/ppc/sha1.h +0 -26
- data/vendor/libgit2/src/protocol.c +0 -110
- data/vendor/libgit2/src/protocol.h +0 -21
- data/vendor/libgit2/src/sha1.h +0 -33
- data/vendor/libgit2/src/transport.h +0 -148
|
@@ -0,0 +1,45 @@
|
|
|
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_openssl_h__
|
|
9
|
+
#define INCLUDE_hash_openssl_h__
|
|
10
|
+
|
|
11
|
+
#include "hash.h"
|
|
12
|
+
|
|
13
|
+
#include <openssl/sha.h>
|
|
14
|
+
|
|
15
|
+
struct git_hash_ctx {
|
|
16
|
+
SHA_CTX c;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
#define git_hash_global_init() 0
|
|
20
|
+
#define git_hash_global_shutdown() /* noop */
|
|
21
|
+
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
|
|
22
|
+
#define git_hash_ctx_cleanup(ctx)
|
|
23
|
+
|
|
24
|
+
GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
|
|
25
|
+
{
|
|
26
|
+
assert(ctx);
|
|
27
|
+
SHA1_Init(&ctx->c);
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
|
|
32
|
+
{
|
|
33
|
+
assert(ctx);
|
|
34
|
+
SHA1_Update(&ctx->c, data, len);
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
|
|
39
|
+
{
|
|
40
|
+
assert(ctx);
|
|
41
|
+
SHA1_Final(out->id, &ctx->c);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#endif /* INCLUDE_hash_openssl_h__ */
|
|
@@ -0,0 +1,291 @@
|
|
|
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
|
+
#include "common.h"
|
|
9
|
+
#include "global.h"
|
|
10
|
+
#include "hash.h"
|
|
11
|
+
#include "hash/hash_win32.h"
|
|
12
|
+
|
|
13
|
+
#include <wincrypt.h>
|
|
14
|
+
#include <strsafe.h>
|
|
15
|
+
|
|
16
|
+
static struct git_hash_prov hash_prov = {0};
|
|
17
|
+
|
|
18
|
+
/* Hash initialization */
|
|
19
|
+
|
|
20
|
+
/* Initialize CNG, if available */
|
|
21
|
+
GIT_INLINE(int) hash_cng_prov_init(void)
|
|
22
|
+
{
|
|
23
|
+
OSVERSIONINFOEX version_test = {0};
|
|
24
|
+
DWORD version_test_mask;
|
|
25
|
+
DWORDLONG version_condition_mask = 0;
|
|
26
|
+
char dll_path[MAX_PATH];
|
|
27
|
+
DWORD dll_path_len, size_len;
|
|
28
|
+
|
|
29
|
+
return -1;
|
|
30
|
+
|
|
31
|
+
/* Only use CNG on Windows 2008 / Vista SP1 or better (Windows 6.0 SP1) */
|
|
32
|
+
version_test.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
33
|
+
version_test.dwMajorVersion = 6;
|
|
34
|
+
version_test.dwMinorVersion = 0;
|
|
35
|
+
version_test.wServicePackMajor = 1;
|
|
36
|
+
version_test.wServicePackMinor = 0;
|
|
37
|
+
|
|
38
|
+
version_test_mask = (VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR);
|
|
39
|
+
|
|
40
|
+
VER_SET_CONDITION(version_condition_mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
|
|
41
|
+
VER_SET_CONDITION(version_condition_mask, VER_MINORVERSION, VER_GREATER_EQUAL);
|
|
42
|
+
VER_SET_CONDITION(version_condition_mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
|
|
43
|
+
VER_SET_CONDITION(version_condition_mask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
|
|
44
|
+
|
|
45
|
+
if (!VerifyVersionInfo(&version_test, version_test_mask, version_condition_mask))
|
|
46
|
+
return -1;
|
|
47
|
+
|
|
48
|
+
/* Load bcrypt.dll explicitly from the system directory */
|
|
49
|
+
if ((dll_path_len = GetSystemDirectory(dll_path, MAX_PATH)) == 0 || dll_path_len > MAX_PATH ||
|
|
50
|
+
StringCchCat(dll_path, MAX_PATH, "\\") < 0 ||
|
|
51
|
+
StringCchCat(dll_path, MAX_PATH, GIT_HASH_CNG_DLL_NAME) < 0 ||
|
|
52
|
+
(hash_prov.prov.cng.dll = LoadLibrary(dll_path)) == NULL)
|
|
53
|
+
return -1;
|
|
54
|
+
|
|
55
|
+
/* Load the function addresses */
|
|
56
|
+
if ((hash_prov.prov.cng.open_algorithm_provider = (hash_win32_cng_open_algorithm_provider_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptOpenAlgorithmProvider")) == NULL ||
|
|
57
|
+
(hash_prov.prov.cng.get_property = (hash_win32_cng_get_property_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptGetProperty")) == NULL ||
|
|
58
|
+
(hash_prov.prov.cng.create_hash = (hash_win32_cng_create_hash_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptCreateHash")) == NULL ||
|
|
59
|
+
(hash_prov.prov.cng.finish_hash = (hash_win32_cng_finish_hash_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptFinishHash")) == NULL ||
|
|
60
|
+
(hash_prov.prov.cng.hash_data = (hash_win32_cng_hash_data_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptHashData")) == NULL ||
|
|
61
|
+
(hash_prov.prov.cng.destroy_hash = (hash_win32_cng_destroy_hash_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptDestroyHash")) == NULL ||
|
|
62
|
+
(hash_prov.prov.cng.close_algorithm_provider = (hash_win32_cng_close_algorithm_provider_fn)GetProcAddress(hash_prov.prov.cng.dll, "BCryptCloseAlgorithmProvider")) == NULL) {
|
|
63
|
+
FreeLibrary(hash_prov.prov.cng.dll);
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* Load the SHA1 algorithm */
|
|
68
|
+
if (hash_prov.prov.cng.open_algorithm_provider(&hash_prov.prov.cng.handle, GIT_HASH_CNG_HASH_TYPE, NULL, GIT_HASH_CNG_HASH_REUSABLE) < 0) {
|
|
69
|
+
FreeLibrary(hash_prov.prov.cng.dll);
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Get storage space for the hash object */
|
|
74
|
+
if (hash_prov.prov.cng.get_property(hash_prov.prov.cng.handle, GIT_HASH_CNG_HASH_OBJECT_LEN, (PBYTE)&hash_prov.prov.cng.hash_object_size, sizeof(DWORD), &size_len, 0) < 0) {
|
|
75
|
+
hash_prov.prov.cng.close_algorithm_provider(hash_prov.prov.cng.handle, 0);
|
|
76
|
+
FreeLibrary(hash_prov.prov.cng.dll);
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
hash_prov.type = CNG;
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
GIT_INLINE(void) hash_cng_prov_shutdown(void)
|
|
85
|
+
{
|
|
86
|
+
hash_prov.prov.cng.close_algorithm_provider(hash_prov.prov.cng.handle, 0);
|
|
87
|
+
FreeLibrary(hash_prov.prov.cng.dll);
|
|
88
|
+
|
|
89
|
+
hash_prov.type = INVALID;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Initialize CryptoAPI */
|
|
93
|
+
GIT_INLINE(int) hash_cryptoapi_prov_init()
|
|
94
|
+
{
|
|
95
|
+
if (!CryptAcquireContext(&hash_prov.prov.cryptoapi.handle, NULL, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
|
|
96
|
+
return -1;
|
|
97
|
+
|
|
98
|
+
hash_prov.type = CRYPTOAPI;
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
GIT_INLINE(void) hash_cryptoapi_prov_shutdown(void)
|
|
103
|
+
{
|
|
104
|
+
CryptReleaseContext(hash_prov.prov.cryptoapi.handle, 0);
|
|
105
|
+
|
|
106
|
+
hash_prov.type = INVALID;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
int git_hash_global_init()
|
|
110
|
+
{
|
|
111
|
+
int error = 0;
|
|
112
|
+
|
|
113
|
+
if (hash_prov.type != INVALID)
|
|
114
|
+
return 0;
|
|
115
|
+
|
|
116
|
+
if ((error = hash_cng_prov_init()) < 0)
|
|
117
|
+
error = hash_cryptoapi_prov_init();
|
|
118
|
+
|
|
119
|
+
return error;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void git_hash_global_shutdown()
|
|
123
|
+
{
|
|
124
|
+
if (hash_prov.type == CNG)
|
|
125
|
+
hash_cng_prov_shutdown();
|
|
126
|
+
else if(hash_prov.type == CRYPTOAPI)
|
|
127
|
+
hash_cryptoapi_prov_shutdown();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* CryptoAPI: available in Windows XP and newer */
|
|
131
|
+
|
|
132
|
+
GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)
|
|
133
|
+
{
|
|
134
|
+
ctx->type = CRYPTOAPI;
|
|
135
|
+
ctx->prov = &hash_prov;
|
|
136
|
+
|
|
137
|
+
return git_hash_init(ctx);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
GIT_INLINE(int) hash_cryptoapi_init(git_hash_ctx *ctx)
|
|
141
|
+
{
|
|
142
|
+
if (ctx->ctx.cryptoapi.valid)
|
|
143
|
+
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
|
|
144
|
+
|
|
145
|
+
if (!CryptCreateHash(ctx->prov->prov.cryptoapi.handle, CALG_SHA1, 0, 0, &ctx->ctx.cryptoapi.hash_handle)) {
|
|
146
|
+
ctx->ctx.cryptoapi.valid = 0;
|
|
147
|
+
return -1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
ctx->ctx.cryptoapi.valid = 1;
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
GIT_INLINE(int) hash_cryptoapi_update(git_hash_ctx *ctx, const void *data, size_t len)
|
|
155
|
+
{
|
|
156
|
+
assert(ctx->ctx.cryptoapi.valid);
|
|
157
|
+
|
|
158
|
+
if (!CryptHashData(ctx->ctx.cryptoapi.hash_handle, (const BYTE *)data, (DWORD)len, 0))
|
|
159
|
+
return -1;
|
|
160
|
+
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
GIT_INLINE(int) hash_cryptoapi_final(git_oid *out, git_hash_ctx *ctx)
|
|
165
|
+
{
|
|
166
|
+
DWORD len = 20;
|
|
167
|
+
int error = 0;
|
|
168
|
+
|
|
169
|
+
assert(ctx->ctx.cryptoapi.valid);
|
|
170
|
+
|
|
171
|
+
if (!CryptGetHashParam(ctx->ctx.cryptoapi.hash_handle, HP_HASHVAL, out->id, &len, 0))
|
|
172
|
+
error = -1;
|
|
173
|
+
|
|
174
|
+
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
|
|
175
|
+
ctx->ctx.cryptoapi.valid = 0;
|
|
176
|
+
|
|
177
|
+
return error;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
GIT_INLINE(void) hash_ctx_cryptoapi_cleanup(git_hash_ctx *ctx)
|
|
181
|
+
{
|
|
182
|
+
if (ctx->ctx.cryptoapi.valid)
|
|
183
|
+
CryptDestroyHash(ctx->ctx.cryptoapi.hash_handle);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* CNG: Available in Windows Server 2008 and newer */
|
|
187
|
+
|
|
188
|
+
GIT_INLINE(int) hash_ctx_cng_init(git_hash_ctx *ctx)
|
|
189
|
+
{
|
|
190
|
+
if ((ctx->ctx.cng.hash_object = git__malloc(hash_prov.prov.cng.hash_object_size)) == NULL)
|
|
191
|
+
return -1;
|
|
192
|
+
|
|
193
|
+
if (hash_prov.prov.cng.create_hash(hash_prov.prov.cng.handle, &ctx->ctx.cng.hash_handle, ctx->ctx.cng.hash_object, hash_prov.prov.cng.hash_object_size, NULL, 0, 0) < 0) {
|
|
194
|
+
git__free(ctx->ctx.cng.hash_object);
|
|
195
|
+
return -1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
ctx->type = CNG;
|
|
199
|
+
ctx->prov = &hash_prov;
|
|
200
|
+
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
GIT_INLINE(int) hash_cng_init(git_hash_ctx *ctx)
|
|
205
|
+
{
|
|
206
|
+
BYTE hash[GIT_OID_RAWSZ];
|
|
207
|
+
|
|
208
|
+
if (!ctx->ctx.cng.updated)
|
|
209
|
+
return 0;
|
|
210
|
+
|
|
211
|
+
/* CNG needs to be finished to restart */
|
|
212
|
+
if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, hash, GIT_OID_RAWSZ, 0) < 0)
|
|
213
|
+
return -1;
|
|
214
|
+
|
|
215
|
+
ctx->ctx.cng.updated = 0;
|
|
216
|
+
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
GIT_INLINE(int) hash_cng_update(git_hash_ctx *ctx, const void *data, size_t len)
|
|
221
|
+
{
|
|
222
|
+
if (ctx->prov->prov.cng.hash_data(ctx->ctx.cng.hash_handle, (PBYTE)data, (ULONG)len, 0) < 0)
|
|
223
|
+
return -1;
|
|
224
|
+
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
GIT_INLINE(int) hash_cng_final(git_oid *out, git_hash_ctx *ctx)
|
|
229
|
+
{
|
|
230
|
+
if (ctx->prov->prov.cng.finish_hash(ctx->ctx.cng.hash_handle, out->id, GIT_OID_RAWSZ, 0) < 0)
|
|
231
|
+
return -1;
|
|
232
|
+
|
|
233
|
+
ctx->ctx.cng.updated = 0;
|
|
234
|
+
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
GIT_INLINE(void) hash_ctx_cng_cleanup(git_hash_ctx *ctx)
|
|
239
|
+
{
|
|
240
|
+
ctx->prov->prov.cng.destroy_hash(ctx->ctx.cng.hash_handle);
|
|
241
|
+
git__free(ctx->ctx.cng.hash_object);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Indirection between CryptoAPI and CNG */
|
|
245
|
+
|
|
246
|
+
int git_hash_ctx_init(git_hash_ctx *ctx)
|
|
247
|
+
{
|
|
248
|
+
int error = 0;
|
|
249
|
+
|
|
250
|
+
assert(ctx);
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* When compiled with GIT_THREADS, the global hash_prov data is
|
|
254
|
+
* initialized with git_threads_init. Otherwise, it must be initialized
|
|
255
|
+
* at first use.
|
|
256
|
+
*/
|
|
257
|
+
if (hash_prov.type == INVALID && (error = git_hash_global_init()) < 0)
|
|
258
|
+
return error;
|
|
259
|
+
|
|
260
|
+
memset(ctx, 0x0, sizeof(git_hash_ctx));
|
|
261
|
+
|
|
262
|
+
return (hash_prov.type == CNG) ? hash_ctx_cng_init(ctx) : hash_ctx_cryptoapi_init(ctx);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
int git_hash_init(git_hash_ctx *ctx)
|
|
266
|
+
{
|
|
267
|
+
assert(ctx && ctx->type);
|
|
268
|
+
return (ctx->type == CNG) ? hash_cng_init(ctx) : hash_cryptoapi_init(ctx);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
int git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
|
|
272
|
+
{
|
|
273
|
+
assert(ctx && ctx->type);
|
|
274
|
+
return (ctx->type == CNG) ? hash_cng_update(ctx, data, len) : hash_cryptoapi_update(ctx, data, len);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
int git_hash_final(git_oid *out, git_hash_ctx *ctx)
|
|
278
|
+
{
|
|
279
|
+
assert(ctx && ctx->type);
|
|
280
|
+
return (ctx->type == CNG) ? hash_cng_final(out, ctx) : hash_cryptoapi_final(out, ctx);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
void git_hash_ctx_cleanup(git_hash_ctx *ctx)
|
|
284
|
+
{
|
|
285
|
+
assert(ctx);
|
|
286
|
+
|
|
287
|
+
if (ctx->type == CNG)
|
|
288
|
+
hash_ctx_cng_cleanup(ctx);
|
|
289
|
+
else if(ctx->type == CRYPTOAPI)
|
|
290
|
+
hash_ctx_cryptoapi_cleanup(ctx);
|
|
291
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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_win32_h__
|
|
9
|
+
#define INCLUDE_hash_win32_h__
|
|
10
|
+
|
|
11
|
+
#include "common.h"
|
|
12
|
+
#include "hash.h"
|
|
13
|
+
|
|
14
|
+
#include <wincrypt.h>
|
|
15
|
+
#include <strsafe.h>
|
|
16
|
+
|
|
17
|
+
enum hash_win32_prov_type {
|
|
18
|
+
INVALID = 0,
|
|
19
|
+
CRYPTOAPI,
|
|
20
|
+
CNG
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* CryptoAPI is available for hashing on Windows XP and newer.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
struct hash_cryptoapi_prov {
|
|
28
|
+
HCRYPTPROV handle;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* CNG (bcrypt.dll) is significantly more performant than CryptoAPI and is
|
|
33
|
+
* preferred, however it is only available on Windows 2008 and newer and
|
|
34
|
+
* must therefore be dynamically loaded, and we must inline constants that
|
|
35
|
+
* would not exist when building in pre-Windows 2008 environments.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#define GIT_HASH_CNG_DLL_NAME "bcrypt.dll"
|
|
39
|
+
|
|
40
|
+
/* BCRYPT_SHA1_ALGORITHM */
|
|
41
|
+
#define GIT_HASH_CNG_HASH_TYPE L"SHA1"
|
|
42
|
+
|
|
43
|
+
/* BCRYPT_OBJECT_LENGTH */
|
|
44
|
+
#define GIT_HASH_CNG_HASH_OBJECT_LEN L"ObjectLength"
|
|
45
|
+
|
|
46
|
+
/* BCRYPT_HASH_REUSEABLE_FLAGS */
|
|
47
|
+
#define GIT_HASH_CNG_HASH_REUSABLE 0x00000020
|
|
48
|
+
|
|
49
|
+
/* Function declarations for CNG */
|
|
50
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_open_algorithm_provider_fn)(
|
|
51
|
+
HANDLE /* BCRYPT_ALG_HANDLE */ *phAlgorithm,
|
|
52
|
+
LPCWSTR pszAlgId,
|
|
53
|
+
LPCWSTR pszImplementation,
|
|
54
|
+
DWORD dwFlags);
|
|
55
|
+
|
|
56
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_get_property_fn)(
|
|
57
|
+
HANDLE /* BCRYPT_HANDLE */ hObject,
|
|
58
|
+
LPCWSTR pszProperty,
|
|
59
|
+
PUCHAR pbOutput,
|
|
60
|
+
ULONG cbOutput,
|
|
61
|
+
ULONG *pcbResult,
|
|
62
|
+
ULONG dwFlags);
|
|
63
|
+
|
|
64
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_create_hash_fn)(
|
|
65
|
+
HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,
|
|
66
|
+
HANDLE /* BCRYPT_HASH_HANDLE */ *phHash,
|
|
67
|
+
PUCHAR pbHashObject, ULONG cbHashObject,
|
|
68
|
+
PUCHAR pbSecret,
|
|
69
|
+
ULONG cbSecret,
|
|
70
|
+
ULONG dwFlags);
|
|
71
|
+
|
|
72
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_finish_hash_fn)(
|
|
73
|
+
HANDLE /* BCRYPT_HASH_HANDLE */ hHash,
|
|
74
|
+
PUCHAR pbOutput,
|
|
75
|
+
ULONG cbOutput,
|
|
76
|
+
ULONG dwFlags);
|
|
77
|
+
|
|
78
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_hash_data_fn)(
|
|
79
|
+
HANDLE /* BCRYPT_HASH_HANDLE */ hHash,
|
|
80
|
+
PUCHAR pbInput,
|
|
81
|
+
ULONG cbInput,
|
|
82
|
+
ULONG dwFlags);
|
|
83
|
+
|
|
84
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_destroy_hash_fn)(
|
|
85
|
+
HANDLE /* BCRYPT_HASH_HANDLE */ hHash);
|
|
86
|
+
|
|
87
|
+
typedef NTSTATUS (WINAPI *hash_win32_cng_close_algorithm_provider_fn)(
|
|
88
|
+
HANDLE /* BCRYPT_ALG_HANDLE */ hAlgorithm,
|
|
89
|
+
ULONG dwFlags);
|
|
90
|
+
|
|
91
|
+
struct hash_cng_prov {
|
|
92
|
+
/* DLL for CNG */
|
|
93
|
+
HINSTANCE dll;
|
|
94
|
+
|
|
95
|
+
/* Function pointers for CNG */
|
|
96
|
+
hash_win32_cng_open_algorithm_provider_fn open_algorithm_provider;
|
|
97
|
+
hash_win32_cng_get_property_fn get_property;
|
|
98
|
+
hash_win32_cng_create_hash_fn create_hash;
|
|
99
|
+
hash_win32_cng_finish_hash_fn finish_hash;
|
|
100
|
+
hash_win32_cng_hash_data_fn hash_data;
|
|
101
|
+
hash_win32_cng_destroy_hash_fn destroy_hash;
|
|
102
|
+
hash_win32_cng_close_algorithm_provider_fn close_algorithm_provider;
|
|
103
|
+
|
|
104
|
+
HANDLE /* BCRYPT_ALG_HANDLE */ handle;
|
|
105
|
+
DWORD hash_object_size;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
struct git_hash_prov {
|
|
109
|
+
enum hash_win32_prov_type type;
|
|
110
|
+
|
|
111
|
+
union {
|
|
112
|
+
struct hash_cryptoapi_prov cryptoapi;
|
|
113
|
+
struct hash_cng_prov cng;
|
|
114
|
+
} prov;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/* Hash contexts */
|
|
118
|
+
|
|
119
|
+
struct hash_cryptoapi_ctx {
|
|
120
|
+
bool valid;
|
|
121
|
+
HCRYPTHASH hash_handle;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
struct hash_cng_ctx {
|
|
125
|
+
bool updated;
|
|
126
|
+
HANDLE /* BCRYPT_HASH_HANDLE */ hash_handle;
|
|
127
|
+
PBYTE hash_object;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
struct git_hash_ctx {
|
|
131
|
+
enum hash_win32_prov_type type;
|
|
132
|
+
git_hash_prov *prov;
|
|
133
|
+
|
|
134
|
+
union {
|
|
135
|
+
struct hash_cryptoapi_ctx cryptoapi;
|
|
136
|
+
struct hash_cng_ctx cng;
|
|
137
|
+
} ctx;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
#endif /* INCLUDE_hash_openssl_h__ */
|