[evince] comics: Add API to detect whether an archive entry is encrypted



commit 4cc667c0fe808687d9a40a3d4ef45c1571694ffa
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Jul 18 11:37:34 2017 +0200

    comics: Add API to detect whether an archive entry is encrypted
    
    Only implemented and used by the libarchive backend unfortunately.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784963

 backend/comics/ev-archive.c |   23 +++++++++++++++++++++++
 backend/comics/ev-archive.h |    1 +
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/backend/comics/ev-archive.c b/backend/comics/ev-archive.c
index 7556a49..f32dc2c 100644
--- a/backend/comics/ev-archive.c
+++ b/backend/comics/ev-archive.c
@@ -261,6 +261,29 @@ ev_archive_get_entry_size (EvArchive *archive)
        return -1;
 }
 
+gboolean
+ev_archive_get_entry_is_encrypted (EvArchive *archive)
+{
+       g_return_val_if_fail (EV_IS_ARCHIVE (archive), FALSE);
+       g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, FALSE);
+
+       switch (archive->type) {
+       case EV_ARCHIVE_TYPE_RAR:
+               g_return_val_if_fail (archive->unarr != NULL, FALSE);
+               /* password-protected RAR is not even detected right now */
+               return FALSE;
+       case EV_ARCHIVE_TYPE_NONE:
+               g_assert_not_reached ();
+       case EV_ARCHIVE_TYPE_ZIP:
+       case EV_ARCHIVE_TYPE_7Z:
+       case EV_ARCHIVE_TYPE_TAR:
+               g_return_val_if_fail (archive->libar_entry != NULL, -1);
+               return archive_entry_is_encrypted (archive->libar_entry);
+       }
+
+       return FALSE;
+}
+
 gssize
 ev_archive_read_data (EvArchive *archive,
                      void      *buf,
diff --git a/backend/comics/ev-archive.h b/backend/comics/ev-archive.h
index cb52669..9f015f2 100644
--- a/backend/comics/ev-archive.h
+++ b/backend/comics/ev-archive.h
@@ -46,6 +46,7 @@ gboolean       ev_archive_read_next_header   (EvArchive     *archive,
                                              GError       **error);
 const char    *ev_archive_get_entry_pathname (EvArchive     *archive);
 gint64         ev_archive_get_entry_size     (EvArchive     *archive);
+gboolean       ev_archive_get_entry_is_encrypted (EvArchive *archive);
 gssize         ev_archive_read_data          (EvArchive     *archive,
                                              void          *buf,
                                              gsize          count,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]