From dcc249a616d9efe48d56a1ad5f86d178e824f6c1 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 4 Sep 2018 13:19:23 +0200 Subject: Use libstrophe sha1 functions Using libstrophes sha1 functions in p_sha1_hash() to get rid of the p_sha1.c dependency. Relates to https://github.com/boothj5/profanity/issues/882 --- src/common.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/common.c b/src/common.c index 164523a2..a4120e9b 100644 --- a/src/common.c +++ b/src/common.c @@ -55,7 +55,7 @@ #include "log.h" #include "common.h" -#include "tools/p_sha1.h" +#include struct curl_data_t { @@ -333,17 +333,16 @@ release_is_new(char *found_version) char* p_sha1_hash(char *str) { - P_SHA1_CTX ctx; - uint8_t digest[20]; - uint8_t *input = (uint8_t*)malloc(strlen(str) + 1); - memcpy(input, str, strlen(str) + 1); + unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE); + assert(digest != NULL); - P_SHA1_Init(&ctx); - P_SHA1_Update(&ctx, input, strlen(str)); - P_SHA1_Final(&ctx, digest); + xmpp_sha1_digest((unsigned char*)str, strlen(str), digest); - free(input); - return g_base64_encode(digest, sizeof(digest)); + char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE); + assert(b64 != NULL); + free(digest); + + return b64; } static size_t -- cgit 1.4.1-2-gfad0 From 9e021d5c8f1fbbac05ff989eca1d2bf766d8c935 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 5 Sep 2018 11:45:31 +0200 Subject: Remove p_sha1 source files And delete from Makefile.am --- Makefile.am | 2 - src/tools/p_sha1.c | 403 ----------------------------------------------------- src/tools/p_sha1.h | 31 ----- 3 files changed, 436 deletions(-) delete mode 100644 src/tools/p_sha1.c delete mode 100644 src/tools/p_sha1.h (limited to 'src') diff --git a/Makefile.am b/Makefile.am index fd278140..c83e1e00 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,6 @@ core_sources = \ src/tools/parser.h \ src/tools/http_upload.c \ src/tools/http_upload.h \ - src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ src/config/files.c src/config/files.h \ @@ -75,7 +74,6 @@ unittest_sources = \ src/command/cmd_ac.h src/command/cmd_ac.c \ src/tools/parser.c \ src/tools/parser.h \ - src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ src/config/accounts.h \ diff --git a/src/tools/p_sha1.c b/src/tools/p_sha1.c deleted file mode 100644 index 11adede3..00000000 --- a/src/tools/p_sha1.c +++ /dev/null @@ -1,403 +0,0 @@ -/** @file - * SHA-1 hash. - */ - -/* -SHA-1 in C -By Steve Reid -100% Public Domain - ------------------ -Modified 7/98 -By James H. Brown -Still 100% Public Domain - -Corrected a problem which generated improper hash values on 16 bit machines -Routine SHA1Update changed from - void SHA1Update(P_SHA1_CTX* context, unsigned char* data, unsigned int -len) -to - void SHA1Update(P_SHA1_CTX* context, unsigned char* data, unsigned -long len) - -The 'len' parameter was declared an int which works fine on 32 bit machines. -However, on 16 bit machines an int is too small for the shifts being done -against -it. This caused the hash function to generate incorrect values if len was -greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update(). - -Since the file IO in main() reads 16K at a time, any file 8K or larger would -be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million -"a"s). - -I also changed the declaration of variables i & j in SHA1Update to -unsigned long from unsigned int for the same reason. - -These changes should make no difference to any 32 bit implementations since -an -int and a long are the same size in those environments. - --- -I also corrected a few compiler warnings generated by Borland C. -1. Added #include for exit() prototype -2. Removed unused variable 'j' in SHA1Final -3. Changed exit(0) to return(0) at end of main. - -ALL changes I made can be located by searching for comments containing 'JHB' ------------------ -Modified 8/98 -By Steve Reid -Still 100% public domain - -1- Removed #include and used return() instead of exit() -2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall) -3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net - ------------------ -Modified 4/01 -By Saul Kravitz -Still 100% PD -Modified to run on Compaq Alpha hardware. - ------------------ -Modified 07/2002 -By Ralph Giles -Still 100% public domain -modified for use with stdint types, autoconf -code cleanup, removed attribution comments -switched SHA1Final() argument order for consistency -use SHA1_ prefix for public api -move public api to sha1.h -*/ - -/* -Test Vectors (from FIPS PUB 180-1) -"abc" - A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D -"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 -A million repetitions of "a" - 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F -*/ - -/* #define SHA1HANDSOFF */ - -#include -#include - -/* make sure the stdint.h types are available */ -#if defined(_MSC_VER) /* Microsoft Visual C++ */ - typedef signed char int8_t; - typedef short int int16_t; - typedef int int32_t; - typedef __int64 int64_t; - typedef unsigned char uint8_t; - typedef unsigned short int uint16_t; - typedef unsigned int uint32_t; - /* no uint64_t */ -#else -#include -#endif - -#include "p_sha1.h" - -static uint32_t host_to_be(uint32_t i); -void P_SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]); - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) - -/* blk0() and blk() perform the initial expand. */ -/* I got the idea of expanding during the round function from SSLeay */ -#define blk0(i) (block->l[i] = host_to_be(block->l[i])) -#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ - ^block->l[(i+2)&15]^block->l[i&15],1)) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); -#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); -#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); - - -#ifdef VERBOSE /* SAK */ -void SHAPrintContext(P_P_SHA1_CTX *context, char *msg){ - printf("%s (%d,%d) %x %x %x %x %x\n", - msg, - context->count[0], context->count[1], - context->state[0], - context->state[1], - context->state[2], - context->state[3], - context->state[4]); -} -#endif /* VERBOSE */ - -static uint32_t host_to_be(uint32_t i) -{ -#define le_to_be(i) ((rol((i),24) & 0xFF00FF00) | (rol((i),8) & 0x00FF00FF)) -#if defined(__BIG_ENDIAN__) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - return i; -#elif defined(__LITTLE_ENDIAN__) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - return le_to_be(i); -#else /* fallback to run-time check */ - static const union { - uint32_t u; - unsigned char c; - } check = {1}; - - return check.c ? le_to_be(i) : i; -#endif -} - -/* Hash a single 512-bit block. This is the core of the algorithm. */ -void P_SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]) -{ - uint32_t a, b, c, d, e; - typedef union { - uint8_t c[64]; - uint32_t l[16]; - } CHAR64LONG16; - CHAR64LONG16* block; - -#ifdef SHA1HANDSOFF - static uint8_t workspace[64]; - block = (CHAR64LONG16*)workspace; - memcpy(block, buffer, 64); -#else - block = (CHAR64LONG16*)buffer; -#endif - - /* Copy context->state[] to working vars */ - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - - /* Add the working vars back into context.state[] */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - /* Wipe variables */ - a = b = c = d = e = 0; -} - - -/* SHA1Init - Initialize new context */ -void P_SHA1_Init(P_SHA1_CTX* context) -{ - /* SHA1 initialization constants */ - context->state[0] = 0x67452301; - context->state[1] = 0xEFCDAB89; - context->state[2] = 0x98BADCFE; - context->state[3] = 0x10325476; - context->state[4] = 0xC3D2E1F0; - context->count[0] = context->count[1] = 0; -} - - -/* Run your data through this. */ -void P_SHA1_Update(P_SHA1_CTX* context, const uint8_t* data, const size_t len) -{ - size_t i, j; - -#ifdef VERBOSE - SHAPrintContext(context, "before"); -#endif - - j = (context->count[0] >> 3) & 63; - if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; - context->count[1] += (len >> 29); - if ((j + len) > 63) { - memcpy(&context->buffer[j], data, (i = 64-j)); - P_SHA1_Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) { - P_SHA1_Transform(context->state, data + i); - } - j = 0; - } - else i = 0; - memcpy(&context->buffer[j], &data[i], len - i); - -#ifdef VERBOSE - SHAPrintContext(context, "after "); -#endif -} - - -/* Add padding and return the message digest. */ -void P_SHA1_Final(P_SHA1_CTX* context, uint8_t digest[P_SHA1_DIGEST_SIZE]) -{ - uint32_t i; - uint8_t finalcount[8]; - - for (i = 0; i < 8; i++) { - finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] - >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ - } - P_SHA1_Update(context, (uint8_t *)"\200", 1); - while ((context->count[0] & 504) != 448) { - P_SHA1_Update(context, (uint8_t *)"\0", 1); - } - P_SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */ - for (i = 0; i < P_SHA1_DIGEST_SIZE; i++) { - digest[i] = (uint8_t) - ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); - } - - /* Wipe variables */ - i = 0; - memset(context->buffer, 0, 64); - memset(context->state, 0, 20); - memset(context->count, 0, 8); - memset(finalcount, 0, 8); /* SWR */ - -#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ - P_SHA1_Transform(context->state, context->buffer); -#endif -} - -/*************************************************************/ - -#if 0 -int main(int argc, char** argv) -{ -int i, j; -P_SHA1_CTX context; -unsigned char digest[P_SHA1_DIGEST_SIZE], buffer[16384]; -FILE* file; - - if (argc > 2) { - puts("Public domain SHA-1 implementation - by Steve Reid "); - puts("Modified for 16 bit environments 7/98 - by James H. Brown "); /* JHB */ - puts("Produces the SHA-1 hash of a file, or stdin if no file is specified."); - return(0); - } - if (argc < 2) { - file = stdin; - } - else { - if (!(file = fopen(argv[1], "rb"))) { - fputs("Unable to open file.", stderr); - return(-1); - } - } - SHA1_Init(&context); - while (!feof(file)) { /* note: what if ferror(file) */ - i = fread(buffer, 1, 16384, file); - SHA1_Update(&context, buffer, i); - } - SHA1_Final(&context, digest); - fclose(file); - for (i = 0; i < P_SHA1_DIGEST_SIZE/4; i++) { - for (j = 0; j < 4; j++) { - printf("%02X", digest[i*4+j]); - } - putchar(' '); - } - putchar('\n'); - return(0); /* JHB */ -} -#endif - -/* self test */ - -#ifdef TEST - -static char *test_data[] = { - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "A million repetitions of 'a'"}; -static char *test_results[] = { - "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D", - "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1", - "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F"}; - -void digest_to_hex(const uint8_t digest[P_SHA1_DIGEST_SIZE], char *output) -{ - int i,j; - char *c = output; - - for (i = 0; i < P_SHA1_DIGEST_SIZE/4; i++) { - for (j = 0; j < 4; j++) { - sprintf(c,"%02X", digest[i*4+j]); - c += 2; - } - sprintf(c, " "); - c += 1; - } - *(c - 1) = '\0'; -} - -int main(int argc, char** argv) -{ - int k; - P_SHA1_CTX context; - uint8_t digest[20]; - char output[80]; - - fprintf(stdout, "verifying SHA-1 implementation... "); - - for (k = 0; k < 2; k++){ - P_SHA1_Init(&context); - P_SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k])); - P_SHA1_Final(&context, digest); - digest_to_hex(digest, output); - - if (strcmp(output, test_results[k])) { - fprintf(stdout, "FAIL\n"); - fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[k]); - fprintf(stderr,"\t%s returned\n", output); - fprintf(stderr,"\t%s is correct\n", test_results[k]); - return (1); - } - } - /* million 'a' vector we feed separately */ - P_SHA1_Init(&context); - for (k = 0; k < 1000000; k++) - P_SHA1_Update(&context, (uint8_t*)"a", 1); - P_SHA1_Final(&context, digest); - digest_to_hex(digest, output); - if (strcmp(output, test_results[2])) { - fprintf(stdout, "FAIL\n"); - fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]); - fprintf(stderr,"\t%s returned\n", output); - fprintf(stderr,"\t%s is correct\n", test_results[2]); - return (1); - } - - /* success */ - fprintf(stdout, "ok\n"); - return(0); -} -#endif /* TEST */ diff --git a/src/tools/p_sha1.h b/src/tools/p_sha1.h deleted file mode 100644 index 75443b01..00000000 --- a/src/tools/p_sha1.h +++ /dev/null @@ -1,31 +0,0 @@ -/* public api for steve reid's public domain SHA-1 implementation */ -/* this file is in the public domain */ - -/** @file - * SHA-1 hash API. - */ - -#ifndef __P_SHA1_H -#define __P_SHA1_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - uint32_t state[5]; - uint32_t count[2]; - uint8_t buffer[64]; -} P_SHA1_CTX; - -#define P_SHA1_DIGEST_SIZE 20 - -void P_SHA1_Init(P_SHA1_CTX* context); -void P_SHA1_Update(P_SHA1_CTX* context, const uint8_t* data, const size_t len); -void P_SHA1_Final(P_SHA1_CTX* context, uint8_t digest[P_SHA1_DIGEST_SIZE]); - -#ifdef __cplusplus -} -#endif - -#endif /* __P_SHA1_H */ -- cgit 1.4.1-2-gfad0 From 82f8083b857358c5dd54700fd51254ca745c30a1 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 6 Sep 2018 20:32:08 +0200 Subject: Move p_sha1_hash() to stanza.c Move `p_sha1_hash()` from `common.c` to `xmpp/stanza.c` as it is only used in this file and now depends on libstrophe so xmpp is a better namespace folder. Renaming it as `_stanza_create_sha1_hash()`. And making static since only used here. The function cannot be tested in the unit tests anymore. Once functional tests are working again we should write a test for the sha1 functionality. --- src/common.c | 16 ------------- src/common.h | 2 -- src/xmpp/stanza.c | 19 ++++++++++++++- tests/unittests/test_common.c | 56 ------------------------------------------- tests/unittests/test_common.h | 8 ------- tests/unittests/unittests.c | 7 ------ 6 files changed, 18 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/common.c b/src/common.c index a4120e9b..27482d80 100644 --- a/src/common.c +++ b/src/common.c @@ -55,7 +55,6 @@ #include "log.h" #include "common.h" -#include struct curl_data_t { @@ -330,21 +329,6 @@ release_is_new(char *found_version) } } -char* -p_sha1_hash(char *str) -{ - unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE); - assert(digest != NULL); - - xmpp_sha1_digest((unsigned char*)str, strlen(str), digest); - - char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE); - assert(b64 != NULL); - free(digest); - - return b64; -} - static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data) { diff --git a/src/common.h b/src/common.h index b2c36c3f..328f7f5a 100644 --- a/src/common.h +++ b/src/common.h @@ -92,8 +92,6 @@ char* file_getline(FILE *stream); char* release_get_latest(void); gboolean release_is_new(char *found_version); -char* p_sha1_hash(char *str); - char* get_file_or_linked(char *loc, char *basedir); char* strip_arg_quotes(const char *const input); gboolean is_notify_enabled(void); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 82189ddd..ed13b976 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -66,6 +67,7 @@ #include "xmpp/muc.h" static void _stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix); +static char* _stanza_create_sha1_hash(char *str); #if 0 xmpp_stanza_t* @@ -1143,7 +1145,7 @@ stanza_create_caps_sha1_from_query(xmpp_stanza_t *const query) curr = g_slist_next(curr); } - char *result = p_sha1_hash(s->str); + char *result = _stanza_create_sha1_hash(s->str); g_string_free(s, TRUE); g_slist_free_full(identities, g_free); @@ -2045,3 +2047,18 @@ _stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix) xmpp_stanza_set_id(stanza, id); free(id); } + +static char* +_stanza_create_sha1_hash(char *str) +{ + unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE); + assert(digest != NULL); + + xmpp_sha1_digest((unsigned char*)str, strlen(str), digest); + + char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE); + assert(b64 != NULL); + free(digest); + + return b64; +} diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index 75eed6e2..4849a4a7 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -212,62 +212,6 @@ void test_blah_is_not_valid_resource_presence_string(void **state) assert_false(valid_resource_presence_string("blah")); } -void test_p_sha1_hash1(void **state) -{ - char *inp = "some message\nanother element\n"; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "ZJLLzkYc51Lug3fZ7MJJzK95Ikg="); -} - -void test_p_sha1_hash2(void **state) -{ - char *inp = ""; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "2jmj7l5rSw0yVb/vlWAYkK/YBwk="); -} - -void test_p_sha1_hash3(void **state) -{ - char *inp = "m"; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "aw0xwNVjIjAk2kVpFYRkOseMlug="); -} - -void test_p_sha1_hash4(void **state) -{ - char *inp = "\n"; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "xcgld4ZfXvU0P7+cW3WFLUuE3C8="); -} - -void test_p_sha1_hash5(void **state) -{ - char *inp = " "; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "CZYAoQqUQRSqxAbRNrYl+0Ft13k="); -} - -void test_p_sha1_hash6(void **state) -{ - char *inp = " sdf \n "; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "zjtm8dKlTj1KhYDlM2z8FsmAhSQ="); -} - -void test_p_sha1_hash7(void **state) -{ - char *inp = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum si."; - char *result = p_sha1_hash(inp); - - assert_string_equal(result, "bNfKVfqEOGmzlH8M+e8FYTB46SU="); -} - void utf8_display_len_null_str(void **state) { int result = utf8_display_len(NULL); diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h index 6da87a68..bcef3367 100644 --- a/tests/unittests/test_common.h +++ b/tests/unittests/test_common.h @@ -19,14 +19,6 @@ void test_dnd_is_valid_resource_presence_string(void **state); void test_available_is_not_valid_resource_presence_string(void **state); void test_unavailable_is_not_valid_resource_presence_string(void **state); void test_blah_is_not_valid_resource_presence_string(void **state); -void test_p_sha1_hash1(void **state); -void test_p_sha1_hash2(void **state); -void test_p_sha1_hash3(void **state); -void test_p_sha1_hash4(void **state); -void test_p_sha1_hash5(void **state); -void test_p_sha1_hash6(void **state); -void test_p_sha1_hash6(void **state); -void test_p_sha1_hash7(void **state); void utf8_display_len_null_str(void **state); void utf8_display_len_1_non_wide(void **state); void utf8_display_len_1_wide(void **state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 4e3e149e..8fad2e51 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -78,13 +78,6 @@ int main(int argc, char* argv[]) { unit_test(test_available_is_not_valid_resource_presence_string), unit_test(test_unavailable_is_not_valid_resource_presence_string), unit_test(test_blah_is_not_valid_resource_presence_string), - unit_test(test_p_sha1_hash1), - unit_test(test_p_sha1_hash2), - unit_test(test_p_sha1_hash3), - unit_test(test_p_sha1_hash4), - unit_test(test_p_sha1_hash5), - unit_test(test_p_sha1_hash6), - unit_test(test_p_sha1_hash7), unit_test(utf8_display_len_null_str), unit_test(utf8_display_len_1_non_wide), unit_test(utf8_display_len_1_wide), -- cgit 1.4.1-2-gfad0