Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Initial checksums API.
Vsevolod Stakhov committed 11 years ago
commit 59c150a0dc660077789a0c0029dd5efe9a645cb4
parent 2cf3320
3 files changed +73 -0
modified libpkg/Makefile.am
@@ -17,6 +17,7 @@ libpkg_la_SOURCES= pkg.c \
			pkg_add.c \
			pkg_attributes.c \
			pkg_audit.c \
+
			pkg_checksum.c \
			pkg_config.c \
			pkg_conflicts.c \
			pkg_cudf.c \
added libpkg/pkg_checksum.c
@@ -0,0 +1,57 @@
+
/* Copyright (c) 2014, Vsevolod Stakhov
+
 * All rights reserved.
+
 *
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions are met:
+
 *       * Redistributions of source code must retain the above copyright
+
 *         notice, this list of conditions and the following disclaimer.
+
 *       * Redistributions in binary form must reproduce the above copyright
+
 *         notice, this list of conditions and the following disclaimer in the
+
 *         documentation and/or other materials provided with the distribution.
+
 *
+
 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+
 * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
+
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <sys/types.h>
+
#include <sys/sbuf.h>
+

+
#include <assert.h>
+
#include <ctype.h>
+
#include <errno.h>
+
#include <stdbool.h>
+
#include <stdlib.h>
+
#include <string.h>
+
#include <ucl.h>
+

+
#include "pkg.h"
+
#include "private/pkg.h"
+
#include "private/utils.h"
+

+
int
+
pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
+
	pkg_checksum_type_t type)
+
{
+
	return (EPKG_OK);
+
}
+

+
bool
+
pkg_checksum_is_valid(const char *cksum, size_t clen)
+
{
+
	return (true);
+
}
+

+

+
pkg_checksum_type_t
+
pkg_checksum_get_type(const char *cksum, size_t clen)
+
{
+
	return (PKG_HASH_TYPE_UNKNOWN);
+
}
modified libpkg/private/pkg.h
@@ -538,4 +538,19 @@ bool ucl_object_emit_sbuf(const ucl_object_t *obj, enum ucl_emitter emit_type,
bool ucl_object_emit_file(const ucl_object_t *obj, enum ucl_emitter emit_type,
    FILE *);

+
typedef enum pkg_checksum_type_e {
+
	PKG_HASH_TYPE_SHA256_BASE32 = 0,
+
	PKG_HASH_TYPE_SHA256_HEX,
+
	PKG_HASH_TYPE_UNKNOWN
+
} pkg_checksum_type_t;
+

+
/* Hash is in format <typeid>:<hexhash> */
+
#define PKG_HASH_SHA256_LEN (SHA256_DIGEST_LENGTH * 2 + 3)
+

+
int pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
+
	pkg_checksum_type_t type);
+

+
bool pkg_checksum_is_valid(const char *cksum, size_t clen);
+
pkg_checksum_type_t pkg_checksum_get_type(const char *cksum, size_t clen);
+

#endif