Revision: 1702
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1702&view=rev
Author:   teuf
Date:     2007-09-27 10:55:21 -0700 (Thu, 27 Sep 2007)

Log Message:
-----------
* src/itdb_itunesdb.c: (calculate_db_checksum),
(itdb_write_checksum):
* src/itdb_sha1.c: (itdb_compute_hash):
* src/itdb_sha1.h: propagate the calculated checksum length as an out
parameter to the checksumming functions, fixes a bug where a partial 
checksum would be written if it contained a \0
* tests/test-checksum.c: (calculate_db_checksum): update test program
to that API change

Modified Paths:
--------------
    libgpod/trunk/ChangeLog
    libgpod/trunk/src/itdb_itunesdb.c
    libgpod/trunk/src/itdb_sha1.c
    libgpod/trunk/src/itdb_sha1.h
    libgpod/trunk/tests/test-checksum.c

Modified: libgpod/trunk/ChangeLog
===================================================================
--- libgpod/trunk/ChangeLog     2007-09-26 13:18:37 UTC (rev 1701)
+++ libgpod/trunk/ChangeLog     2007-09-27 17:55:21 UTC (rev 1702)
@@ -1,3 +1,14 @@
+2007-09-27  Christophe,,,  <[EMAIL PROTECTED]>
+
+       * src/itdb_itunesdb.c: (calculate_db_checksum),
+       (itdb_write_checksum):
+       * src/itdb_sha1.c: (itdb_compute_hash):
+       * src/itdb_sha1.h: propagate the calculated checksum length as an out
+       parameter to the checksumming functions, fixes a bug where a partial 
+       checksum would be written if it contained a \0
+       * tests/test-checksum.c: (calculate_db_checksum): update test program
+       to that API change
+
 2007-09-26 Jorg Schuler <jcsjcs at users.sourceforge.net>
 
        * src/itdb_device.c: remove "read only" notice on Nano Video

Modified: libgpod/trunk/src/itdb_itunesdb.c
===================================================================
--- libgpod/trunk/src/itdb_itunesdb.c   2007-09-26 13:18:37 UTC (rev 1701)
+++ libgpod/trunk/src/itdb_itunesdb.c   2007-09-27 17:55:21 UTC (rev 1702)
@@ -4944,7 +4944,7 @@
 }
 
 static unsigned char *
-calculate_db_checksum (const char *itdb_path, guint64 fwid)
+calculate_db_checksum (const char *itdb_path, guint64 fwid, gsize *len)
 {
     int fd;
     struct stat stat_buf;
@@ -4985,7 +4985,7 @@
     memset(itdb_data+0x32, 0, 20);
     memset(itdb_data+0x58, 0, 20);
 
-    checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size);
+    checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size, len);
 
     munmap (itdb_data, stat_buf.st_size);
     close (fd);
@@ -5023,6 +5023,7 @@
     guint64 fwid;
     char *itdb_path;
     unsigned char *checksum;
+    gsize len;
     gboolean result;
 
     if (db->device == NULL) {
@@ -5035,15 +5036,14 @@
     }
 
     itdb_path = itdb_get_itunesdb_path (itdb_get_mountpoint (db));
-    checksum = calculate_db_checksum (itdb_path, fwid);
+    checksum = calculate_db_checksum (itdb_path, fwid, &len);
 
     if (checksum == NULL) {
        g_free (itdb_path);
        return FALSE;
     }
 
-    result = itdb_write_checksum_to_file (itdb_path, checksum, 
-                                         strlen ((char *)checksum));
+    result = itdb_write_checksum_to_file (itdb_path, checksum, len);
     g_free (itdb_path);
 
     {

Modified: libgpod/trunk/src/itdb_sha1.c
===================================================================
--- libgpod/trunk/src/itdb_sha1.c       2007-09-26 13:18:37 UTC (rev 1701)
+++ libgpod/trunk/src/itdb_sha1.c       2007-09-27 17:55:21 UTC (rev 1702)
@@ -211,13 +211,15 @@
 
 unsigned char *itdb_compute_hash (guint64 firewire_id,
                                   const unsigned char *itdb,
-                                  unsigned long size)
+                                  unsigned long size, 
+                                 gsize *len)
 {
     unsigned char *key;
     unsigned char *hash;
     SHA_INFO context;
     int i;
-
+    const gsize CHECKSUM_LEN = 20;
+    
     key = generate_key(firewire_id);
 
     /* hmac sha1 */
@@ -227,7 +229,7 @@
     }
 
     /* 20 bytes for the checksum, and 1 trailing \0 */
-    hash = g_new0 (unsigned char, 21);
+    hash = g_new0 (unsigned char, CHECKSUM_LEN + 1);
     sha_init(&context);
     sha_update(&context, key, 64);
     sha_update(&context, itdb, size);
@@ -238,10 +240,14 @@
 
     sha_init(&context);
     sha_update(&context, key, 64);
-    sha_update(&context, hash, 20);
+    sha_update(&context, hash, CHECKSUM_LEN);
     sha_final(hash, &context);
 
     g_free (key);
 
+    if (len != NULL) {
+       *len = CHECKSUM_LEN;
+    }
+
     return hash;
 }

Modified: libgpod/trunk/src/itdb_sha1.h
===================================================================
--- libgpod/trunk/src/itdb_sha1.h       2007-09-26 13:18:37 UTC (rev 1701)
+++ libgpod/trunk/src/itdb_sha1.h       2007-09-27 17:55:21 UTC (rev 1702)
@@ -33,5 +33,5 @@
 
 unsigned char *itdb_compute_hash (guint64 firewire_id,
                                   const unsigned char *itdb,
-                                  unsigned long size);
+                                  unsigned long size, gsize *len);
 #endif

Modified: libgpod/trunk/tests/test-checksum.c
===================================================================
--- libgpod/trunk/tests/test-checksum.c 2007-09-26 13:18:37 UTC (rev 1701)
+++ libgpod/trunk/tests/test-checksum.c 2007-09-27 17:55:21 UTC (rev 1702)
@@ -93,7 +93,7 @@
     memset(itdb_data+0x32, 0, 20);
     memset(itdb_data+0x58, 0, 20);
 
-    checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size);
+    checksum = itdb_compute_hash (fwid, itdb_data, stat_buf.st_size, NULL);
 
     munmap (itdb_data, stat_buf.st_size);
     close (fd);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to