Thu, 22 Sep 2016 22:09:22 -0500
Add our license spiel to a bunch of files
|
38057
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
1 | /* |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
2 | * purple |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
3 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
6 | * source distribution. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
7 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
11 | * (at your option) any later version. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
12 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
16 | * GNU General Public License for more details. |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
17 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
21 | * |
|
41f47eb1aa19
Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents:
37597
diff
changeset
|
22 | */ |
| 37595 | 23 | #include <glib.h> |
| 24 | ||
| 25 | #include <purple.h> | |
| 26 | ||
| 27 | #include "ciphers/sha256hash.h" | |
| 28 | ||
| 29 | static void | |
| 30 | test_sha256hash(gchar *data, gchar *digest) { | |
| 31 | PurpleHash *hash = NULL; | |
| 32 | gchar cdigest[65]; | |
| 33 | gboolean ret = FALSE; | |
| 34 | ||
| 35 | hash = purple_sha256_hash_new(); | |
| 36 | ||
| 37 | if(data) { | |
| 38 | purple_hash_append(hash, (guchar *)data, strlen(data)); | |
| 39 | } else { | |
| 40 | gint j; | |
| 41 | guchar buff[1000]; | |
| 42 | ||
| 43 | memset(buff, 'a', 1000); | |
| 44 | ||
| 45 | for(j = 0; j < 1000; j++) | |
| 46 | purple_hash_append(hash, buff, 1000); | |
| 47 | } | |
| 48 | ||
| 49 | ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest)); | |
| 50 | ||
| 51 | g_assert(ret); | |
| 52 | g_assert_cmpstr(digest, ==, cdigest); | |
| 53 | } | |
| 54 | ||
| 55 | static void | |
| 56 | test_sha256hash_empty_string(void) { | |
| 57 | test_sha256hash("", | |
| 58 | "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); | |
| 59 | } | |
| 60 | ||
| 61 | static void | |
| 62 | test_sha256hash_a(void) { | |
| 63 | test_sha256hash("a", | |
| 64 | "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"); | |
| 65 | } | |
| 66 | ||
| 67 | static void | |
| 68 | test_sha256hash_abc(void) { | |
| 69 | test_sha256hash("abc", | |
| 70 | "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); | |
| 71 | } | |
| 72 | ||
| 73 | static void | |
| 74 | test_sha256hash_abcd_gibberish(void) { | |
| 75 | test_sha256hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
| 76 | "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); | |
| 77 | } | |
| 78 | ||
| 79 | static void | |
| 80 | test_sha256hash_1000_as_1000_times(void) { | |
| 81 | test_sha256hash(NULL, | |
| 82 | "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0"); | |
| 83 | } | |
| 84 | ||
| 85 | gint | |
| 86 | main(gint argc, gchar **argv) { | |
| 87 | g_test_init(&argc, &argv, NULL); | |
| 88 | ||
| 89 | g_test_add_func("/hash/sha256/empty-string", | |
| 90 | test_sha256hash_empty_string); | |
| 91 | g_test_add_func("/hash/sha256/a", | |
| 92 | test_sha256hash_a); | |
| 93 | g_test_add_func("/hash/sha256/abc", | |
| 94 | test_sha256hash_abc); | |
| 95 | g_test_add_func("/hash/sha256/abcd_gibberish", | |
| 96 | test_sha256hash_abcd_gibberish); | |
| 97 | g_test_add_func("/hash/sha256/1000 a's 1000 times", | |
| 98 | test_sha256hash_1000_as_1000_times); | |
| 99 | ||
| 100 | return g_test_run(); | |
| 101 | } |