summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-02-17 21:27:52 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-02-17 21:27:52 (GMT)
commit3ba750662837541a5df510046c0a3fc521cca785 (patch)
tree711f412439e4b0d154207bbcbceeafce5f1b0864 /src/glibext
parent5c6680287b4b6ba38cc04e6d7cb80c87cb9e256d (diff)
Defined, computed and stored the checksum in the binary content manager.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@474 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/gbincontent.c52
-rw-r--r--src/glibext/gbincontent.h2
2 files changed, 54 insertions, 0 deletions
diff --git a/src/glibext/gbincontent.c b/src/glibext/gbincontent.c
index e0c64d4..a9fe907 100644
--- a/src/glibext/gbincontent.c
+++ b/src/glibext/gbincontent.c
@@ -55,6 +55,9 @@ struct _GBinContent
binary_part *parts; /* Parties prises en compte */
size_t count; /* Nombre de ces parties */
+ GChecksum *checksum; /* Calcul de l'empreinte */
+ bool cs_computed; /* Calcul effectué ? */
+
};
/* Content de données binaires quelconques (classe) */
@@ -125,6 +128,10 @@ static void g_binary_content_class_init(GBinContentClass *klass)
static void g_binary_content_init(GBinContent *content)
{
+ content->checksum = g_checksum_new(G_CHECKSUM_SHA256);
+ assert(content->checksum != NULL);
+
+ content->cs_computed = false;
}
@@ -143,6 +150,8 @@ static void g_binary_content_init(GBinContent *content)
static void g_binary_content_dispose(GBinContent *content)
{
+ g_checksum_free(content->checksum);
+
G_OBJECT_CLASS(g_binary_content_parent_class)->dispose(G_OBJECT(content));
}
@@ -248,6 +257,49 @@ GBinContent *g_binary_content_new_from_file(const char *filename)
/******************************************************************************
* *
+* Paramètres : binary = contenu binaire à consulter. *
+* *
+* Description : Fournit une empreinte unique (SHA256) pour les données. *
+* *
+* Retour : Chaîne représentant l'empreinte du contenu binaire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const gchar *g_binary_content_get_cheksum(GBinContent *content)
+{
+ size_t i; /* Boucle de parcours */
+ binary_part *part; /* Bloc parcouru pour analyse */
+
+ if (!content->cs_computed)
+ {
+ g_checksum_reset(content->checksum);
+
+ for (i = 0; i < content->count; i++)
+ {
+ part = &content->parts[i];
+ g_checksum_update(content->checksum, part->data, get_mrange_length(&part->range));
+ }
+
+ content->cs_computed = true;
+
+ }
+
+ return g_checksum_get_string(content->checksum);
+
+}
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
* Paramètres : content = contenu binaire à venir lire. *
* addr = position de la tête de lecture globale demandée. *
* start = position de la tête de lecture dans la zone. [OUT] *
diff --git a/src/glibext/gbincontent.h b/src/glibext/gbincontent.h
index e2f5933..246d626 100644
--- a/src/glibext/gbincontent.h
+++ b/src/glibext/gbincontent.h
@@ -56,6 +56,8 @@ GType g_binary_content_get_type(void);
/* Charge en mémoire le contenu d'un fichier donné. */
GBinContent *g_binary_content_new_from_file(const char *);
+/* Fournit une empreinte unique (SHA256) pour les données. */
+const gchar *g_binary_content_get_cheksum(GBinContent *);
/* Fournit une portion des données représentées. */