pidgin/pidgin

sha1hash: Remove in favor of GChecksum

2016-09-28, Mike Ruprecht
09e43b6fe996
Parents 2bf57fef601e
Children ba527fd5e93c
sha1hash: Remove in favor of GChecksum
--- a/doc/reference/libpurple/libpurple-docs.xml Wed Sep 28 15:48:12 2016 -0500
+++ b/doc/reference/libpurple/libpurple-docs.xml Wed Sep 28 15:49:23 2016 -0500
@@ -115,7 +115,6 @@
<xi:include href="xml/pbkdf2cipher.xml" />
<xi:include href="xml/rc4cipher.xml" />
<xi:include href="xml/md4hash.xml" />
- <xi:include href="xml/sha1hash.xml" />
<xi:include href="xml/sha256hash.xml" />
</chapter>
--- a/libpurple/Makefile.am Wed Sep 28 15:48:12 2016 -0500
+++ b/libpurple/Makefile.am Wed Sep 28 15:49:23 2016 -0500
@@ -47,7 +47,6 @@
ciphers/md4hash.c \
ciphers/pbkdf2cipher.c \
ciphers/rc4cipher.c \
- ciphers/sha1hash.c \
ciphers/sha256hash.c \
cipher.c \
circularbuffer.c \
@@ -248,7 +247,6 @@
md4hash.h \
pbkdf2cipher.h \
rc4cipher.h \
- sha1hash.h \
sha256hash.h
purple_builtheaders = purple.h version.h enums.h marshallers.h
--- a/libpurple/Makefile.mingw Wed Sep 28 15:48:12 2016 -0500
+++ b/libpurple/Makefile.mingw Wed Sep 28 15:49:23 2016 -0500
@@ -74,7 +74,6 @@
ciphers/md4hash.c \
ciphers/pbkdf2cipher.c \
ciphers/rc4cipher.c \
- ciphers/sha1hash.c \
ciphers/sha256hash.c \
cipher.c \
circularbuffer.c \
--- a/libpurple/ciphers/sha1hash.c Wed Sep 28 15:48:12 2016 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-/*
- * purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
- */
-#include "internal.h"
-#include "sha1hash.h"
-
-/*******************************************************************************
- * Structs
- ******************************************************************************/
-#define PURPLE_SHA1_HASH_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_SHA1_HASH, PurpleSHA1HashPrivate))
-
-typedef struct {
- GChecksum *checksum;
-} PurpleSHA1HashPrivate;
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-static GObjectClass *parent_class = NULL;
-
-/******************************************************************************
- * Hash Stuff
- *****************************************************************************/
-
-static void
-purple_sha1_hash_reset(PurpleHash *hash)
-{
- PurpleSHA1Hash *sha1_hash = PURPLE_SHA1_HASH(hash);
- PurpleSHA1HashPrivate *priv = PURPLE_SHA1_HASH_GET_PRIVATE(sha1_hash);
-
- g_return_if_fail(priv != NULL);
- g_return_if_fail(priv->checksum != NULL);
-
- g_checksum_reset(priv->checksum);
-}
-
-static void
-purple_sha1_hash_append(PurpleHash *hash, const guchar *data,
- gsize len)
-{
- PurpleSHA1Hash *sha1_hash = PURPLE_SHA1_HASH(hash);
- PurpleSHA1HashPrivate *priv = PURPLE_SHA1_HASH_GET_PRIVATE(sha1_hash);
-
- g_return_if_fail(priv != NULL);
- g_return_if_fail(priv->checksum != NULL);
-
- while (len >= G_MAXSSIZE) {
- g_checksum_update(priv->checksum, data, G_MAXSSIZE);
- len -= G_MAXSSIZE;
- data += G_MAXSSIZE;
- }
-
- if (len)
- g_checksum_update(priv->checksum, data, len);
-}
-
-static gboolean
-purple_sha1_hash_digest(PurpleHash *hash, guchar *digest, size_t buff_len)
-{
- PurpleSHA1Hash *sha1_hash = PURPLE_SHA1_HASH(hash);
- PurpleSHA1HashPrivate *priv = PURPLE_SHA1_HASH_GET_PRIVATE(sha1_hash);
-
- const gssize required_len = g_checksum_type_get_length(G_CHECKSUM_SHA1);
- gsize digest_len = buff_len;
-
- g_return_val_if_fail(priv != NULL, FALSE);
- g_return_val_if_fail(priv->checksum != NULL, FALSE);
-
- g_return_val_if_fail(required_len >= 0, FALSE);
- g_return_val_if_fail(buff_len >= (gsize)required_len, FALSE);
-
- g_checksum_get_digest(priv->checksum, digest, &digest_len);
-
- if (digest_len != (gsize)required_len)
- return FALSE;
-
- purple_sha1_hash_reset(hash);
-
- return TRUE;
-}
-
-static size_t
-purple_sha1_hash_get_block_size(PurpleHash *hash)
-{
- return 64;
-}
-
-static size_t
-purple_sha1_hash_get_digest_size(PurpleHash *hash)
-{
- return g_checksum_type_get_length(G_CHECKSUM_SHA1);
-}
-
-/******************************************************************************
- * Object Stuff
- *****************************************************************************/
-
-static void
-purple_sha1_hash_finalize(GObject *obj)
-{
- PurpleSHA1Hash *sha1_hash = PURPLE_SHA1_HASH(obj);
- PurpleSHA1HashPrivate *priv = PURPLE_SHA1_HASH_GET_PRIVATE(sha1_hash);
-
- if (priv->checksum)
- g_checksum_free(priv->checksum);
-
- parent_class->finalize(obj);
-}
-
-static void
-purple_sha1_hash_class_init(PurpleSHA1HashClass *klass) {
- GObjectClass *obj_class = G_OBJECT_CLASS(klass);
- PurpleHashClass *hash_class = PURPLE_HASH_CLASS(klass);
-
- parent_class = g_type_class_peek_parent(klass);
-
- obj_class->finalize = purple_sha1_hash_finalize;
-
- hash_class->reset = purple_sha1_hash_reset;
- hash_class->reset_state = purple_sha1_hash_reset;
- hash_class->append = purple_sha1_hash_append;
- hash_class->digest = purple_sha1_hash_digest;
- hash_class->get_digest_size = purple_sha1_hash_get_digest_size;
- hash_class->get_block_size = purple_sha1_hash_get_block_size;
-
- g_type_class_add_private(klass, sizeof(PurpleSHA1HashPrivate));
-}
-
-static void
-purple_sha1_hash_init(PurpleHash *hash)
-{
- PurpleSHA1Hash *sha1_hash = PURPLE_SHA1_HASH(hash);
- PurpleSHA1HashPrivate *priv = PURPLE_SHA1_HASH_GET_PRIVATE(sha1_hash);
-
- priv->checksum = g_checksum_new(G_CHECKSUM_SHA1);
-
- purple_sha1_hash_reset(hash);
-}
-
-/******************************************************************************
- * API
- *****************************************************************************/
-GType
-purple_sha1_hash_get_type(void) {
- static GType type = 0;
-
- if(type == 0) {
- static const GTypeInfo info = {
- sizeof(PurpleSHA1HashClass),
- NULL,
- NULL,
- (GClassInitFunc)purple_sha1_hash_class_init,
- NULL,
- NULL,
- sizeof(PurpleSHA1Hash),
- 0,
- (GInstanceInitFunc)purple_sha1_hash_init,
- NULL,
- };
-
- type = g_type_register_static(PURPLE_TYPE_HASH,
- "PurpleSHA1Hash",
- &info, 0);
- }
-
- return type;
-}
-
-PurpleHash *
-purple_sha1_hash_new(void) {
- return g_object_new(PURPLE_TYPE_SHA1_HASH, NULL);
-}
--- a/libpurple/ciphers/sha1hash.h Wed Sep 28 15:48:12 2016 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/* purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
- */
-
-#ifndef PURPLE_SHA1_HASH_H
-#define PURPLE_SHA1_HASH_H
-/**
- * SECTION:sha1hash
- * @section_id: libpurple-sha1hash
- * @short_description: <filename>ciphers/sha1hash.h</filename>
- * @title: SHA1 Hash
- */
-
-#include "cipher.h"
-
-#define PURPLE_TYPE_SHA1_HASH (purple_sha1_hash_get_type())
-#define PURPLE_SHA1_HASH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_SHA1_HASH, PurpleSHA1Hash))
-#define PURPLE_SHA1_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_SHA1_HASH, PurpleSHA1HashClass))
-#define PURPLE_IS_SHA1_HASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_SHA1_HASH))
-#define PURPLE_IS_SHA1_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_SHA1_HASH))
-#define PURPLE_SHA1_HASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_SHA1_HASH, PurpleSHA1HashClass))
-
-typedef struct _PurpleSHA1Hash PurpleSHA1Hash;
-typedef struct _PurpleSHA1HashClass PurpleSHA1HashClass;
-
-struct _PurpleSHA1Hash {
- PurpleHash gparent;
-};
-
-struct _PurpleSHA1HashClass {
- PurpleHashClass gparent;
-
- /*< private >*/
- void (*_purple_reserved1)(void);
- void (*_purple_reserved2)(void);
- void (*_purple_reserved3)(void);
- void (*_purple_reserved4)(void);
-};
-
-G_BEGIN_DECLS
-
-GType purple_sha1_hash_get_type(void);
-
-PurpleHash *purple_sha1_hash_new(void);
-
-G_END_DECLS
-
-#endif /* PURPLE_SHA1_HASH_H */
--- a/libpurple/tests/Makefile.am Wed Sep 28 15:48:12 2016 -0500
+++ b/libpurple/tests/Makefile.am Wed Sep 28 15:49:23 2016 -0500
@@ -9,7 +9,6 @@
test_des \
test_des3 \
test_md4 \
- test_sha1 \
test_sha256 \
test_trie \
test_util \
@@ -25,9 +24,6 @@
test_md4_SOURCES=test_md4.c
test_md4_LDADD=$(COMMON_LIBS)
-test_sha1_SOURCES=test_sha1.c
-test_sha1_LDADD=$(COMMON_LIBS)
-
test_sha256_SOURCES=test_sha256.c
test_sha256_LDADD=$(COMMON_LIBS)
--- a/libpurple/tests/test_sha1.c Wed Sep 28 15:48:12 2016 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-/*
- * purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
- *
- */
-#include <glib.h>
-
-#include <purple.h>
-
-#include "ciphers/sha1hash.h"
-
-static void
-test_sha1hash(gchar *data, gchar *digest) {
- PurpleHash *hash = NULL;
- gchar cdigest[41];
- gboolean ret = FALSE;
-
- hash = purple_sha1_hash_new();
-
- if(data) {
- purple_hash_append(hash, (guchar *)data, strlen(data));
- } else {
- gint j;
- guchar buff[1000];
-
- memset(buff, 'a', 1000);
-
- for(j = 0; j < 1000; j++)
- purple_hash_append(hash, buff, 1000);
- }
-
- ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest));
-
- g_assert(ret);
- g_assert_cmpstr(digest, ==, cdigest);
-}
-
-static void
-test_sha1hash_empty_string(void) {
- test_sha1hash("",
- "da39a3ee5e6b4b0d3255bfef95601890afd80709");
-}
-
-static void
-test_sha1hash_a(void) {
- test_sha1hash("a",
- "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
-}
-
-static void
-test_sha1hash_abc(void) {
- test_sha1hash("abc",
- "a9993e364706816aba3e25717850c26c9cd0d89d");
-}
-
-static void
-test_sha1hash_abcd_gibberish(void) {
- test_sha1hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
-}
-
-static void
-test_sha1hash_1000_as_1000_times(void) {
- test_sha1hash(NULL,
- "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
-}
-
-gint
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/hash/sha1/empty-string",
- test_sha1hash_empty_string);
- g_test_add_func("/hash/sha1/a",
- test_sha1hash_a);
- g_test_add_func("/hash/sha1/abc",
- test_sha1hash_abc);
- g_test_add_func("/hash/sha1/abcd_gibberish",
- test_sha1hash_abcd_gibberish);
- g_test_add_func("/hash/sha1/1000 a's 1000 times",
- test_sha1hash_1000_as_1000_times);
-
- return g_test_run();
-}