71b6403f90f9f221004a07cbd4e5aecedd9f6438 galt Mon Apr 24 12:41:27 2017 -0700 Refs #17538. Adds ability for user to paste a custom BED region into the multi-region dialog box instead of having to provide a URL to an on-line server. It still supports the URL through UDC however, which is more efficient for large custom region lists and also provides backwards compatibility. Uses sha1 instead of md5 for faster speed now. diff --git src/lib/tests/sha1Test.c src/lib/tests/sha1Test.c index a2ba48e..7495c9d 100644 --- src/lib/tests/sha1Test.c +++ src/lib/tests/sha1Test.c @@ -1,20 +1,18 @@ #include #include #include -#include -#include #include "common.h" #include "errAbort.h" #include "obscure.h" #include "portable.h" #include "sha1.h" 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"}; @@ -23,33 +21,33 @@ void manual_way(char *filename, unsigned char hash[20]) /* generate sha1 manually the hard way. */ { FILE *fp = fopen (filename, "r"); if (!fp) { printf("missing file %s\n", filename); exit(1); } #define BS 4096 /* match coreutils */ SHA1_CTX ctx; SHA1_Init(&ctx); size_t nr; -char buf[BS]; +unsigned char buf[BS]; while ((nr=fread(buf, 1, sizeof(buf), fp))) - SHA1_Update(&ctx, (const uint8_t*)buf, nr); + SHA1_Update(&ctx, buf, nr); SHA1_Final(&ctx, hash); } char *string_way(char *filename) /* generate sha1 via lib on single long string. */ { char *buf = NULL; size_t bufSize; readInGulp(filename, &buf, &bufSize); return sha1HexForBuf(buf, bufSize); } char *git_way(char *filename) /* generate sha1 using git blob prefix. @@ -75,102 +73,102 @@ /* generate sha1 manually with git blob prefix the hard way. */ { FILE *fp = fopen (filename, "r"); if (!fp) errAbort("missing file %s", filename); #define BS 4096 /* match coreutils */ unsigned char hash[20]; off_t fs = fileSize(filename); char prefix[1024]; safef(prefix, sizeof prefix, "blob %llu", (unsigned long long)fs); SHA1_CTX ctx; SHA1_Init(&ctx); -SHA1_Update(&ctx, (const uint8_t*)prefix, strlen(prefix)+1); +SHA1_Update(&ctx, (unsigned char *)prefix, strlen(prefix)+1); size_t nr; -char buf[BS]; +unsigned char buf[BS]; while ((nr=fread(buf, 1, sizeof(buf), fp))) - SHA1_Update(&ctx, (const uint8_t*)buf, nr); + SHA1_Update(&ctx, buf, nr); SHA1_Final(&ctx, hash); return sha1ToHex(hash); } void git_way3(char *filename) /* generate sha1 manually the hard way. */ { char cmd[1024]; safef(cmd, sizeof cmd, "git hash-object %s", filename); printf("executing system command [%s]\n", cmd); system(cmd); } char *string_empty() /* generate sha1 via lib on empty input. */ { char *buf = NULL; size_t bufSize = 0; return sha1HexForBuf(buf, bufSize); } -void digest_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], char *output) +void digest_to_hex(const bits8 digest[SHA1_DIGEST_SIZE], char *output) { int i,j; char *c = output; for (i = 0; i < 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; SHA1_CTX context; - uint8_t digest[20]; + bits8 digest[20]; char output[80]; fprintf(stdout, "verifying SHA-1 implementation... "); for (k = 0; k < 2; k++){ SHA1_Init(&context); - SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k])); + SHA1_Update(&context, (bits8*)test_data[k], strlen(test_data[k])); 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 */ SHA1_Init(&context); for (k = 0; k < 1000000; k++) - SHA1_Update(&context, (uint8_t*)"a", 1); + SHA1_Update(&context, (bits8*)"a", 1); 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"); if (argc < 2)