[Debburn-changes] r806 - in cdrkit/trunk: . genisoimage
93sam at alioth.debian.org
93sam at alioth.debian.org
Sun May 25 20:46:18 UTC 2008
Author: 93sam
Date: 2008-05-25 20:46:17 +0000 (Sun, 25 May 2008)
New Revision: 806
Modified:
cdrkit/trunk/Changelog
cdrkit/trunk/genisoimage/checksum.c
cdrkit/trunk/genisoimage/checksum.h
cdrkit/trunk/genisoimage/jte.c
Log:
genisoimage/checksum.[ch]: Added test code; changed internal layout
slightly to make for easier debug.
Modified: cdrkit/trunk/Changelog
===================================================================
--- cdrkit/trunk/Changelog 2008-05-25 20:39:07 UTC (rev 805)
+++ cdrkit/trunk/Changelog 2008-05-25 20:46:17 UTC (rev 806)
@@ -7,6 +7,8 @@
-jigdo-template-compress
* genisoimage/sha1.h: Fix a type issue that broke sha1 support
on 64-bit arches.
+ * genisoimage/checksum.[ch]: Added test code; changed internal
+ layout slightly to make for easier debug.
-- Steve McIntyre <93sam at debian.org> Mon, 25 May 2008 21:22:26 +0100
Modified: cdrkit/trunk/genisoimage/checksum.c
===================================================================
--- cdrkit/trunk/genisoimage/checksum.c 2008-05-25 20:39:07 UTC (rev 805)
+++ cdrkit/trunk/genisoimage/checksum.c 2008-05-25 20:46:17 UTC (rev 806)
@@ -47,6 +47,7 @@
struct checksum_details
{
char *name;
+ char *prog;
int digest_size;
int context_size;
void (*init)(void *context);
@@ -58,6 +59,7 @@
{
{
"MD5",
+ "md5sum",
16,
sizeof(struct mk_MD5Context),
md5_init,
@@ -66,6 +68,7 @@
},
{
"SHA1",
+ "sha1sum",
20,
sizeof(struct sha1_ctx),
sha1_init,
@@ -74,40 +77,53 @@
}
};
-struct _checksum_context
+struct algo_context
{
void *context;
unsigned char *digest;
int enabled;
};
+struct _checksum_context
+{
+ char *owner;
+ struct algo_context algo[NUM_CHECKSUMS];
+};
+
struct checksum_info *checksum_information(enum checksum_types which)
{
return (struct checksum_info *)&algorithms[which];
}
-checksum_context_t *checksum_init_context(int checksums)
+checksum_context_t *checksum_init_context(int checksums, const char *owner)
{
int i = 0;
- struct _checksum_context *context = malloc(NUM_CHECKSUMS * sizeof(struct _checksum_context));
+ struct _checksum_context *context = malloc(sizeof(struct _checksum_context));
if (!context)
return NULL;
+ context->owner = strdup(owner);
+ if (!context->owner)
+ {
+ free(context);
+ return NULL;
+ }
+
for (i = 0; i < NUM_CHECKSUMS; i++)
{
if ( (1 << i) & checksums)
{
- context[i].context = malloc(algorithms[i].context_size);
- if (!context[i].context)
+ context->algo[i].context = malloc(algorithms[i].context_size);
+ if (!context->algo[i].context)
return NULL;
- context[i].digest = malloc(algorithms[i].digest_size);
- if (!context[i].digest)
+ context->algo[i].digest = malloc(algorithms[i].digest_size);
+ if (!context->algo[i].digest)
return NULL;
- algorithms[i].init(context[i].context);
- context[i].enabled = 1;
+ algorithms[i].init(context->algo[i].context);
+ context->algo[i].enabled = 1;
}
else
- context[i].enabled = 0;
+ context->algo[i].enabled = 0;
}
return context;
@@ -120,9 +136,10 @@
for (i = 0; i < NUM_CHECKSUMS; i++)
{
- free(c[i].context);
- free(c[i].digest);
+ free(c->algo[i].context);
+ free(c->algo[i].digest);
}
+ free(c->owner);
free(c);
}
@@ -134,8 +151,8 @@
for (i = 0; i < NUM_CHECKSUMS; i++)
{
- if (c[i].enabled)
- algorithms[i].update(c[i].context, buf, len);
+ if (c->algo[i].enabled)
+ algorithms[i].update(c->algo[i].context, buf, len);
}
}
@@ -146,8 +163,8 @@
for (i = 0; i < NUM_CHECKSUMS; i++)
{
- if (c[i].enabled)
- algorithms[i].final(c[i].digest, c[i].context);
+ if (c->algo[i].enabled)
+ algorithms[i].final(c->algo[i].digest, c->algo[i].context);
}
}
@@ -157,8 +174,90 @@
{
struct _checksum_context *c = context;
- if (c[which].enabled)
- memcpy(digest, c[which].digest, algorithms[which].digest_size);
+ if (c->algo[which].enabled)
+ memcpy(digest, c->algo[which].digest, algorithms[which].digest_size);
+ else
+ fprintf(stderr, "Asked for %s checksum, not enabled!\n",
+ algorithms[which].name);
}
+#ifdef CHECKSUM_SELF_TEST
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+int main(int argc, char **argv)
+{
+ char buf[1024];
+ int fd = -1;
+ char *filename;
+ int err = 0;
+ static checksum_context_t *test_context = NULL;
+ int i = 0;
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "Need a filename to act on!\n");
+ return 1;
+ }
+
+ filename = argv[1];
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ {
+ fprintf(stderr, "Unable to open file %s, errno %d\n", filename, errno);
+ return 1;
+ }
+
+ test_context = checksum_init_context(CHECK_ALL_USED, "test");
+ if (!test_context)
+ {
+ fprintf(stderr, "Unable to initialise checksum context\n");
+ return 1;
+ }
+
+ while(1)
+ {
+ err = read(fd, buf, sizeof(buf));
+ if (err < 0)
+ {
+ fprintf(stderr, "Failed to read from file, errno %d\n", errno);
+ return 1;
+ }
+
+ if (err == 0)
+ break; // EOF
+
+ /* else */
+ checksum_update(test_context, buf, err);
+ }
+ close(fd);
+ checksum_final(test_context);
+
+ for (i = 0; i < NUM_CHECKSUMS; i++)
+ {
+ struct checksum_info *info;
+ unsigned char r[64];
+ int j = 0;
+
+ info = checksum_information(i);
+ memset(r, 0, sizeof(r));
+
+ checksum_copy(test_context, i, r);
+
+ printf("OUR %s:\n", info->name);
+ for (j = 0; j < info->digest_size; j++)
+ printf("%2.2x", r[j]);
+ printf(" %s\n", filename);
+ printf("system checksum program (%s):\n", info->prog);
+ sprintf(buf, "%s %s", info->prog, filename);
+ system(buf);
+ printf("\n");
+ }
+ return 0;
+}
+#endif /* CHECKSUM_SELF_TEST */
+
Modified: cdrkit/trunk/genisoimage/checksum.h
===================================================================
--- cdrkit/trunk/genisoimage/checksum.h 2008-05-25 20:39:07 UTC (rev 805)
+++ cdrkit/trunk/genisoimage/checksum.h 2008-05-25 20:46:17 UTC (rev 806)
@@ -19,12 +19,14 @@
#define CHECK_MD5_USED (1 << CHECK_MD5)
#define CHECK_SHA1_USED (1 << CHECK_SHA1)
+#define CHECK_ALL_USED 0xFFFFFFFF
typedef void checksum_context_t;
struct checksum_info
{
char *name;
+ char *prog;
int digest_size;
};
@@ -35,7 +37,7 @@
/* Allocate / initialise a context for the chosen checksums. OR
* together the desired checksums as the parameter */
-checksum_context_t *checksum_init_context(int checksums);
+checksum_context_t *checksum_init_context(int checksums, const char *owner);
/* Cleanup and free a context when it's finished with */
void checksum_free_context(checksum_context_t *context);
Modified: cdrkit/trunk/genisoimage/jte.c
===================================================================
--- cdrkit/trunk/genisoimage/jte.c 2008-05-25 20:39:07 UTC (rev 805)
+++ cdrkit/trunk/genisoimage/jte.c 2008-05-25 20:46:17 UTC (rev 806)
@@ -445,7 +445,7 @@
memset(buf, 0, sizeof(buf));
- template_context = checksum_init_context(CHECK_MD5_USED);
+ template_context = checksum_init_context(CHECK_MD5_USED, "template");
if (!template_context)
{
#ifdef USE_LIBSCHILY
@@ -569,7 +569,7 @@
j_file = jigdo_file;
/* Start checksum work for the image */
- iso_context = checksum_init_context(CHECK_MD5_USED|CHECK_SHA1_USED);
+ iso_context = checksum_init_context(CHECK_MD5_USED|CHECK_SHA1_USED, "iso");
if (!iso_context)
{
#ifdef USE_LIBSCHILY
@@ -821,7 +821,6 @@
checksum_final(template_context);
checksum_copy(template_context, CHECK_MD5, &template_md5sum[0]);
-// mk_MD5Final(&template_md5sum[0], &template_context);
fprintf(j_file, "# JigsawDownload\n");
fprintf(j_file, "# See <http://atterer.net/jigdo/> for details about jigdo\n");
@@ -834,6 +833,7 @@
fprintf(j_file, "[Image]\n");
fprintf(j_file, "Filename=%s\n", file_base_name(outfile));
fprintf(j_file, "Template=http://localhost/%s\n", jtemplate_out);
+
fprintf(j_file, "Template-MD5Sum=%s \n",
base64_dump(&template_md5sum[0], sizeof(template_md5sum)));
fprintf(j_file, "# Template Hex MD5sum %s\n",
@@ -874,7 +874,6 @@
checksum_final(iso_context);
checksum_copy(iso_context, CHECK_MD5, &image_md5[0]);
checksum_copy(iso_context, CHECK_SHA1, &image_sha1[0]);
-// mk_MD5Final(&md5[0], &iso_context);
/* And calculate the image size */
image_size = (unsigned long long)SECTOR_SIZE * last_extent_written;
More information about the Debburn-changes
mailing list