]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Store encryption info in single char of entry
authorKonrad Kleine <konrad.wilhelm.kleine@gmail.com>
Wed, 18 Sep 2013 08:27:21 +0000 (10:27 +0200)
committerKonrad Kleine <konrad.wilhelm.kleine@gmail.com>
Wed, 18 Sep 2013 08:27:24 +0000 (10:27 +0200)
Instead of two chars the information about encryption is now stored in
one single char inside of an archive_entry struct.

libarchive/archive_entry.c
libarchive/archive_entry_private.h

index 101e61f1e6d461101573557f595ba1ebca1a68ad..27f79ecae05765cc587b0da8341e49f508b2afbd 100644 (file)
@@ -202,8 +202,7 @@ archive_entry_clone(struct archive_entry *entry)
        archive_mstring_copy(&entry2->ae_uname, &entry->ae_uname);
 
        /* Copy encryption status */
-       entry2->is_data_encrypted = entry->is_data_encrypted;
-       entry2->is_metadata_encrypted = entry->is_metadata_encrypted;
+       entry2->encryption = entry->encryption;
        
        /* Copy ACL data over. */
        archive_acl_copy(&entry2->acl, &entry->acl);
@@ -702,20 +701,19 @@ _archive_entry_uname_l(struct archive_entry *entry,
 int
 archive_entry_is_data_encrypted(struct archive_entry *entry)
 {
-       return (entry && entry->is_data_encrypted);
+       return (entry && (entry->encryption & AE_ENCRYPTION_DATA) == AE_ENCRYPTION_DATA);
 }
 
 int
 archive_entry_is_metadata_encrypted(struct archive_entry *entry)
 {
-       return (entry && entry->is_metadata_encrypted);
+       return (entry && (entry->encryption & AE_ENCRYPTION_METADATA) == AE_ENCRYPTION_METADATA);
 }
 
 int
 archive_entry_is_encrypted(struct archive_entry *entry)
 {
-       return (entry && (entry->is_data_encrypted 
-                                       || entry->is_metadata_encrypted));
+       return (entry && entry->encryption & (AE_ENCRYPTION_DATA|AE_ENCRYPTION_METADATA));
 }
 
 /*
@@ -1240,18 +1238,26 @@ archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name)
 }
 
 void
-archive_entry_set_is_data_encrypted(struct archive_entry *entry, char encrypted)
+archive_entry_set_is_data_encrypted(struct archive_entry *entry, char is_encrypted)
 {
     if (entry) {
-        entry->is_data_encrypted = encrypted;
+               if (is_encrypted) {
+                       entry->encryption |= AE_ENCRYPTION_DATA;
+               } else {
+                       entry->encryption &= ~AE_ENCRYPTION_DATA;
+               }
     }
 }
 
 void
-archive_entry_set_is_metadata_encrypted(struct archive_entry *entry, char encrypted)
+archive_entry_set_is_metadata_encrypted(struct archive_entry *entry, char is_encrypted)
 {
-    if (entry) {
-        entry->is_metadata_encrypted = encrypted;
+       if (entry) {
+               if (is_encrypted) {
+                       entry->encryption |= AE_ENCRYPTION_METADATA;
+               } else {
+                       entry->encryption &= ~AE_ENCRYPTION_METADATA;
+               }
     }
 }
 
index 74b50da6bd1accd1fa1dc4a344aae3c748306059..c69233e68bd3336a195872ee137f4539ab79081e 100644 (file)
@@ -154,8 +154,10 @@ struct archive_entry {
        /* Not used within libarchive; useful for some clients. */
        struct archive_mstring ae_sourcepath;   /* Path this entry is sourced from. */
 
-       char is_data_encrypted;
-       char is_metadata_encrypted;
+#define AE_ENCRYPTION_NONE 0
+#define AE_ENCRYPTION_DATA 1
+#define AE_ENCRYPTION_METADATA 2
+       char encryption;
        
        void *mac_metadata;
        size_t mac_metadata_size;