]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Introduce public digest getter API
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 27 Feb 2020 19:00:03 +0000 (19:00 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 13 Mar 2020 19:11:57 +0000 (19:11 +0000)
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 <emil.l.velikov@gmail.com>
libarchive/archive_entry.c
libarchive/archive_entry.h

index 6db1eef7e12af13846c3b51feb9b64be653f7ff0..5d713376b69f1933c6d08f192f2373c303e744e9 100644 (file)
@@ -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
index 90768256eff588421330b85b56fb45ecbe7a19f1..b312343ddefc185da4cccfc5d5d9364770e2eac6 100644 (file)
@@ -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: