Blame src/hash/hash_openssl.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
#ifndef INCLUDE_hash_openssl_h__
Packit Service 20376f
#define INCLUDE_hash_openssl_h__
Packit Service 20376f
Packit Service 20376f
#include "hash.h"
Packit Service 20376f
Packit Service 20376f
#include <openssl/sha.h>
Packit Service 20376f
Packit Service 20376f
struct git_hash_ctx {
Packit Service 20376f
	SHA_CTX c;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define git_hash_global_init() 0
Packit Service 20376f
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
Packit Service 20376f
#define git_hash_ctx_cleanup(ctx)
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
Packit Service 20376f
	if (SHA1_Init(&ctx->c) != 1) {
Packit Service 20376f
		giterr_set(GITERR_SHA1, "hash_openssl: failed to initialize hash context");
Packit Service 20376f
		return -1;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
Packit Service 20376f
	if (SHA1_Update(&ctx->c, data, len) != 1) {
Packit Service 20376f
		giterr_set(GITERR_SHA1, "hash_openssl: failed to update hash");
Packit Service 20376f
		return -1;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx)
Packit Service 20376f
{
Packit Service 20376f
	assert(ctx);
Packit Service 20376f
Packit Service 20376f
	if (SHA1_Final(out->id, &ctx->c) != 1) {
Packit Service 20376f
		giterr_set(GITERR_SHA1, "hash_openssl: failed to finalize hash");
Packit Service 20376f
		return -1;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#endif /* INCLUDE_hash_openssl_h__ */