Blame src/hash.c

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
#include "common.h"
Packit Service 20376f
#include "hash.h"
Packit Service 20376f
Packit Service 20376f
int git_hash_buf(git_oid *out, const void *data, size_t len)
Packit Service 20376f
{
Packit Service 20376f
	git_hash_ctx ctx;
Packit Service 20376f
	int error = 0;
Packit Service 20376f
Packit Service 20376f
	if (git_hash_ctx_init(&ctx) < 0)
Packit Service 20376f
		return -1;
Packit Service 20376f
Packit Service 20376f
	if ((error = git_hash_update(&ctx, data, len)) >= 0)
Packit Service 20376f
		error = git_hash_final(out, &ctx;;
Packit Service 20376f
Packit Service 20376f
	git_hash_ctx_cleanup(&ctx;;
Packit Service 20376f
	
Packit Service 20376f
	return error;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n)
Packit Service 20376f
{
Packit Service 20376f
	git_hash_ctx ctx;
Packit Service 20376f
	size_t i;
Packit Service 20376f
	int error = 0;
Packit Service 20376f
Packit Service 20376f
	if (git_hash_ctx_init(&ctx) < 0)
Packit Service 20376f
		return -1;
Packit Service 20376f
Packit Service 20376f
	for (i = 0; i < n; i++) {
Packit Service 20376f
		if ((error = git_hash_update(&ctx, vec[i].data, vec[i].len)) < 0)
Packit Service 20376f
			goto done;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	error = git_hash_final(out, &ctx;;
Packit Service 20376f
Packit Service 20376f
done:
Packit Service 20376f
	git_hash_ctx_cleanup(&ctx;;
Packit Service 20376f
Packit Service 20376f
	return error;
Packit Service 20376f
}