commit 8bc02fb59874be372520e06cbf2c887efc59fba6
Author: Christophe Fergeau <cferg...@mandriva.com>
Date:   Mon Oct 26 23:20:55 2009 +0100

    move itdb_device_write_hash58 to itdb_hash58.c

 src/Makefile.am    |    1 -
 src/itdb_device.c  |   55 +----------------------------------------
 src/itdb_hash58.c  |   70 +++++++++++++++++++++++++++++++++++++++++++++++----
 src/itdb_hash58.h  |   37 ---------------------------
 src/itdb_private.h |    4 +++
 5 files changed, 69 insertions(+), 98 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f3e426b..4537fb4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,6 @@ noinst_HEADERS =              \
        itdb_endianness.h       \
        itdb_plist.h            \
        itdb_private.h          \
-       itdb_hash58.h           \
        itdb_sqlite_queries.h   \
        itdb_sysinfo_extended_parser.h \
        itdb_thumb.h            \
diff --git a/src/itdb_device.c b/src/itdb_device.c
index 86ad2ca..66eaf3b 100644
--- a/src/itdb_device.c
+++ b/src/itdb_device.c
@@ -34,7 +34,6 @@
 #include "db-itunes-parser.h"
 #include "itdb_device.h"
 #include "itdb_private.h"
-#include "itdb_hash58.h"
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -1782,58 +1781,6 @@ ItdbChecksumType itdb_device_get_checksum_type (const 
Itdb_Device *device)
     return ITDB_CHECKSUM_NONE;
 }
 
-static gboolean itdb_device_write_hash58 (Itdb_Device *device, 
-                                         unsigned char *itdb_data, 
-                                         gsize itdb_len,
-                                         GError **error)
-{
-    guint64 fwid;
-    guchar backup18[8];
-    guchar backup32[20];
-    unsigned char *checksum;
-    gsize len;
-    MhbdHeader *header;
-   
-    g_assert (itdb_device_get_checksum_type (device) == ITDB_CHECKSUM_HASH58);
-
-    fwid = itdb_device_get_firewire_id (device);
-    if (fwid == 0) {
-       g_set_error (error, 0, -1, "Couldn't find the iPod firewire ID");
-       return FALSE;
-    }
-
-    if (itdb_len < 0x6c) {
-       g_set_error (error, 0, -1, "iTunesDB file too small to write checksum");
-       return FALSE;
-    }
-
-    header = (MhbdHeader *)itdb_data;
-    g_assert (strncmp (header->header_id, "mhbd", strlen ("mhbd")) == 0);
-    memcpy (backup18, &header->db_id, sizeof (backup18));
-    memcpy (backup32, &header->unknown6, sizeof (backup32));
-
-    /* Those fields must be zero'ed out for the sha1 calculation */
-    memset(&header->db_id, 0, sizeof (header->db_id));
-    memset(&header->unknown6, 0, sizeof (header->unknown6));
-    memset(&header->hash58, 0, sizeof (header->hash58));
-
-    header->hashing_scheme = GUINT16_FROM_LE (ITDB_CHECKSUM_HASH58);
-
-    checksum = itdb_compute_hash (fwid, itdb_data, itdb_len, &len);
-    if (checksum == NULL) {
-       g_set_error (error, 0, -1, "Failed to compute checksum");
-       return FALSE;
-    }
-    g_assert (len <= sizeof (header->hash58));
-    memcpy (&header->hash58, checksum, len);
-    g_free (checksum);
-
-    memcpy (&header->db_id, backup18, sizeof (backup18));
-    memcpy (&header->unknown6, backup32, sizeof (backup32));
-
-    return TRUE;
-}
-
 G_GNUC_INTERNAL gboolean itdb_device_write_checksum (Itdb_Device *device, 
                                                     unsigned char *itdb_data, 
                                                     gsize itdb_len,
@@ -1843,7 +1790,7 @@ G_GNUC_INTERNAL gboolean itdb_device_write_checksum 
(Itdb_Device *device,
        case ITDB_CHECKSUM_NONE:
            return TRUE;
        case ITDB_CHECKSUM_HASH58:
-           return itdb_device_write_hash58 (device, itdb_data, itdb_len, 
error);
+           return itdb_hash58_write_hash (device, itdb_data, itdb_len, error);
        case ITDB_CHECKSUM_HASH72:
            return itdb_hash72_write_hash (device, itdb_data, itdb_len, error);
        case ITDB_CHECKSUM_UNKNOWN:
diff --git a/src/itdb_hash58.c b/src/itdb_hash58.c
index 88a1235..43c975b 100644
--- a/src/itdb_hash58.c
+++ b/src/itdb_hash58.c
@@ -33,9 +33,14 @@
 |
 |  This product is not supported/written/published by Apple!
 */
-
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <glib.h>
-#include "itdb_hash58.h"
+#include <string.h>
+#include "itdb.h"
+#include "db-itunes-parser.h"
+#include "itdb_private.h"
 #include "sha1.h"
 
 static const unsigned char table1[256] = {
@@ -169,10 +174,10 @@ static unsigned char *generate_key (guint64 fwid)
     return key;
 }
 
-unsigned char *itdb_compute_hash (guint64 firewire_id,
-                                  const unsigned char *itdb,
-                                  unsigned long size, 
-                                 gsize *len)
+static unsigned char *itdb_compute_hash (guint64 firewire_id,
+                                        const unsigned char *itdb,
+                                        unsigned long size, 
+                                        gsize *len)
 {
     unsigned char *key;
     unsigned char *hash;
@@ -211,3 +216,56 @@ unsigned char *itdb_compute_hash (guint64 firewire_id,
 
     return hash;
 }
+
+gboolean itdb_hash58_write_hash (Itdb_Device *device, 
+                                unsigned char *itdb_data, 
+                                gsize itdb_len,
+                                GError **error)
+{
+    guint64 fwid;
+    guchar backup18[8];
+    guchar backup32[20];
+    unsigned char *checksum;
+    gsize len;
+    MhbdHeader *header;
+   
+    g_assert (itdb_device_get_checksum_type (device) == ITDB_CHECKSUM_HASH58);
+
+    fwid = itdb_device_get_firewire_id (device);
+    if (fwid == 0) {
+       g_set_error (error, 0, -1, "Couldn't find the iPod firewire ID");
+       return FALSE;
+    }
+
+    if (itdb_len < 0x6c) {
+       g_set_error (error, 0, -1, "iTunesDB file too small to write checksum");
+       return FALSE;
+    }
+
+    header = (MhbdHeader *)itdb_data;
+    g_assert (strncmp (header->header_id, "mhbd", strlen ("mhbd")) == 0);
+    memcpy (backup18, &header->db_id, sizeof (backup18));
+    memcpy (backup32, &header->unknown6, sizeof (backup32));
+
+    /* Those fields must be zero'ed out for the sha1 calculation */
+    memset(&header->db_id, 0, sizeof (header->db_id));
+    memset(&header->unknown6, 0, sizeof (header->unknown6));
+    memset(&header->hash58, 0, sizeof (header->hash58));
+
+    header->hashing_scheme = GUINT16_FROM_LE (ITDB_CHECKSUM_HASH58);
+
+    checksum = itdb_compute_hash (fwid, itdb_data, itdb_len, &len);
+    if (checksum == NULL) {
+       g_set_error (error, 0, -1, "Failed to compute checksum");
+       return FALSE;
+    }
+    g_assert (len <= sizeof (header->hash58));
+    memcpy (&header->hash58, checksum, len);
+    g_free (checksum);
+
+    memcpy (&header->db_id, backup18, sizeof (backup18));
+    memcpy (&header->unknown6, backup32, sizeof (backup32));
+
+    return TRUE;
+}
+
diff --git a/src/itdb_private.h b/src/itdb_private.h
index 8793bf8..ee1f229 100644
--- a/src/itdb_private.h
+++ b/src/itdb_private.h
@@ -207,6 +207,10 @@ G_GNUC_INTERNAL gboolean itdb_hash72_write_hash (const 
Itdb_Device *device,
                                                 unsigned char *itdb_data, 
                                                 gsize itdb_len,
                                                 GError **error);
+G_GNUC_INTERNAL gboolean itdb_hash58_write_hash (Itdb_Device *device, 
+                                                unsigned char *itdb_data, 
+                                                gsize itdb_len,
+                                                GError **error);
 G_GNUC_INTERNAL gboolean itdb_hash72_compute_hash_for_sha1 (const Itdb_Device 
*device, 
                                                            const guchar 
sha1[20],
                                                            guchar 
signature[46]);

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to