From: Emil Velikov Date: Thu, 27 Feb 2020 19:00:03 +0000 (+0000) Subject: Introduce public digest getter API X-Git-Tag: v3.5.0~29^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbe26331be8e42e1d0ae669bc90b341a6bd037f2;p=thirdparty%2Flibarchive.git Introduce public digest getter API Allow applications to query the digests stored in the MTREE. Which they can use at a later stage to perform integrity checks as needed. Note: no digests are wired yet. Signed-off-by: Emil Velikov --- diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 6db1eef7e..5d713376b 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -1429,6 +1429,28 @@ archive_entry_copy_mac_metadata(struct archive_entry *entry, } } +/* Digest handling */ +const unsigned char * +archive_entry_digest(struct archive_entry *entry, int type) +{ + switch (type) { + case ARCHIVE_ENTRY_DIGEST_MD5: + return entry->digest.md5; + case ARCHIVE_ENTRY_DIGEST_RMD160: + return entry->digest.rmd160; + case ARCHIVE_ENTRY_DIGEST_SHA1: + return entry->digest.sha1; + case ARCHIVE_ENTRY_DIGEST_SHA256: + return entry->digest.sha256; + case ARCHIVE_ENTRY_DIGEST_SHA384: + return entry->digest.sha384; + case ARCHIVE_ENTRY_DIGEST_SHA512: + return entry->digest.sha512; + default: + return NULL; + } +} + /* * ACL management. The following would, of course, be a lot simpler * if: 1) the last draft of POSIX.1e were a really thorough and diff --git a/libarchive/archive_entry.h b/libarchive/archive_entry.h index 90768256e..b312343dd 100644 --- a/libarchive/archive_entry.h +++ b/libarchive/archive_entry.h @@ -396,6 +396,19 @@ __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat __LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *); __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t); +/* + * Digest routine. This is used to query the raw hex digest for the + * given entry. The type of digest is provided as an argument. + */ +#define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001 +#define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002 +#define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003 +#define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004 +#define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005 +#define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006 + +__LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */); + /* * ACL routines. This used to simply store and return text-format ACL * strings, but that proved insufficient for a number of reasons: