pidgin/pidgin

ba527fd5e93c
Parents 09e43b6fe996
Children cb3f85d86752
sha256hash: Remove in favor of GChecksum
--- a/doc/reference/libpurple/libpurple-docs.xml Wed Sep 28 15:49:23 2016 -0500
+++ b/doc/reference/libpurple/libpurple-docs.xml Wed Sep 28 15:49:55 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/sha256hash.xml" />
</chapter>
<chapter id="smiley">
--- a/libpurple/Makefile.am Wed Sep 28 15:49:23 2016 -0500
+++ b/libpurple/Makefile.am Wed Sep 28 15:49:55 2016 -0500
@@ -47,7 +47,6 @@
ciphers/md4hash.c \
ciphers/pbkdf2cipher.c \
ciphers/rc4cipher.c \
- ciphers/sha256hash.c \
cipher.c \
circularbuffer.c \
cmds.c \
@@ -246,8 +245,7 @@
des3cipher.h \
md4hash.h \
pbkdf2cipher.h \
- rc4cipher.h \
- sha256hash.h
+ rc4cipher.h
purple_builtheaders = purple.h version.h enums.h marshallers.h
--- a/libpurple/Makefile.mingw Wed Sep 28 15:49:23 2016 -0500
+++ b/libpurple/Makefile.mingw Wed Sep 28 15:49:55 2016 -0500
@@ -74,7 +74,6 @@
ciphers/md4hash.c \
ciphers/pbkdf2cipher.c \
ciphers/rc4cipher.c \
- ciphers/sha256hash.c \
cipher.c \
circularbuffer.c \
cmds.c \
--- a/libpurple/ciphers/sha256hash.c Wed Sep 28 15:49:23 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 "sha256hash.h"
-
-/*******************************************************************************
- * Structs
- ******************************************************************************/
-#define PURPLE_SHA256_HASH_GET_PRIVATE(obj) \
- (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_SHA256_HASH, PurpleSHA256HashPrivate))
-
-typedef struct {
- GChecksum *checksum;
-} PurpleSHA256HashPrivate;
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-static GObjectClass *parent_class = NULL;
-
-/******************************************************************************
- * Hash Stuff
- *****************************************************************************/
-
-static void
-purple_sha256_hash_reset(PurpleHash *hash)
-{
- PurpleSHA256Hash *sha256_hash = PURPLE_SHA256_HASH(hash);
- PurpleSHA256HashPrivate *priv = PURPLE_SHA256_HASH_GET_PRIVATE(sha256_hash);
-
- g_return_if_fail(priv != NULL);
- g_return_if_fail(priv->checksum != NULL);
-
- g_checksum_reset(priv->checksum);
-}
-
-static void
-purple_sha256_hash_append(PurpleHash *hash, const guchar *data,
- gsize len)
-{
- PurpleSHA256Hash *sha256_hash = PURPLE_SHA256_HASH(hash);
- PurpleSHA256HashPrivate *priv = PURPLE_SHA256_HASH_GET_PRIVATE(sha256_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_sha256_hash_digest(PurpleHash *hash, guchar *digest, size_t buff_len)
-{
- PurpleSHA256Hash *sha256_hash = PURPLE_SHA256_HASH(hash);
- PurpleSHA256HashPrivate *priv = PURPLE_SHA256_HASH_GET_PRIVATE(sha256_hash);
-
- const gssize required_len = g_checksum_type_get_length(G_CHECKSUM_SHA256);
- 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_sha256_hash_reset(hash);
-
- return TRUE;
-}
-
-static size_t
-purple_sha256_hash_get_block_size(PurpleHash *hash)
-{
- return 64;
-}
-
-static size_t
-purple_sha256_hash_get_digest_size(PurpleHash *hash)
-{
- return g_checksum_type_get_length(G_CHECKSUM_SHA256);
-}
-
-/******************************************************************************
- * Object Stuff
- *****************************************************************************/
-
-static void
-purple_sha256_hash_finalize(GObject *obj)
-{
- PurpleSHA256Hash *sha256_hash = PURPLE_SHA256_HASH(obj);
- PurpleSHA256HashPrivate *priv = PURPLE_SHA256_HASH_GET_PRIVATE(sha256_hash);
-
- if (priv->checksum)
- g_checksum_free(priv->checksum);
-
- parent_class->finalize(obj);
-}
-
-static void
-purple_sha256_hash_class_init(PurpleSHA256HashClass *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_sha256_hash_finalize;
-
- hash_class->reset = purple_sha256_hash_reset;
- hash_class->reset_state = purple_sha256_hash_reset;
- hash_class->append = purple_sha256_hash_append;
- hash_class->digest = purple_sha256_hash_digest;
- hash_class->get_digest_size = purple_sha256_hash_get_digest_size;
- hash_class->get_block_size = purple_sha256_hash_get_block_size;
-
- g_type_class_add_private(klass, sizeof(PurpleSHA256HashPrivate));
-}
-
-static void
-purple_sha256_hash_init(PurpleHash *hash)
-{
- PurpleSHA256Hash *sha256_hash = PURPLE_SHA256_HASH(hash);
- PurpleSHA256HashPrivate *priv = PURPLE_SHA256_HASH_GET_PRIVATE(sha256_hash);
-
- priv->checksum = g_checksum_new(G_CHECKSUM_SHA256);
-
- purple_sha256_hash_reset(hash);
-}
-
-/******************************************************************************
- * API
- *****************************************************************************/
-GType
-purple_sha256_hash_get_type(void) {
- static GType type = 0;
-
- if(type == 0) {
- static const GTypeInfo info = {
- sizeof(PurpleSHA256HashClass),
- NULL,
- NULL,
- (GClassInitFunc)purple_sha256_hash_class_init,
- NULL,
- NULL,
- sizeof(PurpleSHA256Hash),
- 0,
- (GInstanceInitFunc)purple_sha256_hash_init,
- NULL,
- };
-
- type = g_type_register_static(PURPLE_TYPE_HASH,
- "PurpleSHA256Hash",
- &info, 0);
- }
-
- return type;
-}
-
-PurpleHash *
-purple_sha256_hash_new(void) {
- return g_object_new(PURPLE_TYPE_SHA256_HASH, NULL);
-}
--- a/libpurple/ciphers/sha256hash.h Wed Sep 28 15:49:23 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_SHA256_HASH_H
-#define PURPLE_SHA256_HASH_H
-/**
- * SECTION:sha256hash
- * @section_id: libpurple-sha256hash
- * @short_description: <filename>ciphers/sha256hash.h</filename>
- * @title: SHA256 Hash
- */
-
-#include "cipher.h"
-
-#define PURPLE_TYPE_SHA256_HASH (purple_sha256_hash_get_type())
-#define PURPLE_SHA256_HASH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_SHA256_HASH, PurpleSHA256Hash))
-#define PURPLE_SHA256_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_SHA256_HASH, PurpleSHA256HashClass))
-#define PURPLE_IS_SHA256_HASH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_SHA256_HASH))
-#define PURPLE_IS_SHA256_HASH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), PURPLE_TYPE_SHA256_HASH))
-#define PURPLE_SHA256_HASH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_SHA256_HASH, PurpleSHA256HashClass))
-
-typedef struct _PurpleSHA256Hash PurpleSHA256Hash;
-typedef struct _PurpleSHA256HashClass PurpleSHA256HashClass;
-
-struct _PurpleSHA256Hash {
- PurpleHash gparent;
-};
-
-struct _PurpleSHA256HashClass {
- PurpleHashClass gparent;
-
- /*< private >*/
- void (*_purple_reserved1)(void);
- void (*_purple_reserved2)(void);
- void (*_purple_reserved3)(void);
- void (*_purple_reserved4)(void);
-};
-
-G_BEGIN_DECLS
-
-GType purple_sha256_hash_get_type(void);
-
-PurpleHash *purple_sha256_hash_new(void);
-
-G_END_DECLS
-
-#endif /* PURPLE_SHA256_HASH_H */
--- a/libpurple/tests/Makefile.am Wed Sep 28 15:49:23 2016 -0500
+++ b/libpurple/tests/Makefile.am Wed Sep 28 15:49:55 2016 -0500
@@ -9,7 +9,6 @@
test_des \
test_des3 \
test_md4 \
- test_sha256 \
test_trie \
test_util \
test_xmlnode
@@ -24,9 +23,6 @@
test_md4_SOURCES=test_md4.c
test_md4_LDADD=$(COMMON_LIBS)
-test_sha256_SOURCES=test_sha256.c
-test_sha256_LDADD=$(COMMON_LIBS)
-
test_trie_SOURCES=test_trie.c
test_trie_LDADD=$(COMMON_LIBS)
--- a/libpurple/tests/test_sha256.c Wed Sep 28 15:49:23 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/sha256hash.h"
-
-static void
-test_sha256hash(gchar *data, gchar *digest) {
- PurpleHash *hash = NULL;
- gchar cdigest[65];
- gboolean ret = FALSE;
-
- hash = purple_sha256_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_sha256hash_empty_string(void) {
- test_sha256hash("",
- "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
-}
-
-static void
-test_sha256hash_a(void) {
- test_sha256hash("a",
- "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
-}
-
-static void
-test_sha256hash_abc(void) {
- test_sha256hash("abc",
- "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
-}
-
-static void
-test_sha256hash_abcd_gibberish(void) {
- test_sha256hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
-}
-
-static void
-test_sha256hash_1000_as_1000_times(void) {
- test_sha256hash(NULL,
- "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
-}
-
-gint
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
-
- g_test_add_func("/hash/sha256/empty-string",
- test_sha256hash_empty_string);
- g_test_add_func("/hash/sha256/a",
- test_sha256hash_a);
- g_test_add_func("/hash/sha256/abc",
- test_sha256hash_abc);
- g_test_add_func("/hash/sha256/abcd_gibberish",
- test_sha256hash_abcd_gibberish);
- g_test_add_func("/hash/sha256/1000 a's 1000 times",
- test_sha256hash_1000_as_1000_times);
-
- return g_test_run();
-}