X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=tools%2Fffhash.c;h=a9f71c26c5237546c944dc501cdaff61d899a4c8;hb=039630631e96cc04d09101acf71756174ce00dad;hp=086d48a7ab5292681e02d9bc3cd64a4ef9f504f3;hpb=878f8b0d26e9bd34f27949e8b7d2be6c864ca998;p=ffmpeg diff --git a/tools/ffhash.c b/tools/ffhash.c index 086d48a7ab5..a9f71c26c52 100644 --- a/tools/ffhash.c +++ b/tools/ffhash.c @@ -21,6 +21,7 @@ */ #include "config.h" +#include "libavutil/avstring.h" #include "libavutil/error.h" #include "libavutil/hash.h" #include "libavutil/mem.h" @@ -40,14 +41,14 @@ #define SIZE 65536 static struct AVHashContext *hash; -static uint8_t *res; +static int out_b64; static void usage(void) { int i = 0; const char *name; - printf("usage: ffhash [algorithm] [input]...\n"); + printf("usage: ffhash [b64:]algorithm [input]...\n"); printf("Supported hash algorithms:"); do { name = av_hash_names(i); @@ -60,12 +61,16 @@ static void usage(void) static void finish(void) { - int i, len = av_hash_get_size(hash); - - printf("%s=0x", av_hash_get_name(hash)); - av_hash_final(hash, res); - for (i = 0; i < len; i++) - printf("%02x", res[i]); + char res[2 * AV_HASH_MAX_SIZE + 4]; + + printf("%s=", av_hash_get_name(hash)); + if (out_b64) { + av_hash_final_b64(hash, res, sizeof(res)); + printf("b64:%s", res); + } else { + av_hash_final_hex(hash, res, sizeof(res)); + printf("0x%s", res); + } } static int check(char *file) @@ -113,16 +118,19 @@ int main(int argc, char **argv) { int i; int ret = 0; + const char *hash_name; if (argc == 1) { usage(); return 0; } - if ((ret = av_hash_alloc(&hash, argv[1])) < 0) { + hash_name = argv[1]; + out_b64 = av_strstart(hash_name, "b64:", &hash_name); + if ((ret = av_hash_alloc(&hash, hash_name)) < 0) { switch(ret) { case AVERROR(EINVAL): - printf("Invalid hash type: %s\n", argv[1]); + printf("Invalid hash type: %s\n", hash_name); break; case AVERROR(ENOMEM): printf("%s\n", strerror(errno)); @@ -130,11 +138,6 @@ int main(int argc, char **argv) } return 1; } - res = av_malloc(av_hash_get_size(hash)); - if (!res) { - printf("%s\n", strerror(errno)); - return 1; - } for (i = 2; i < argc; i++) ret |= check(argv[i]); @@ -143,7 +146,6 @@ int main(int argc, char **argv) ret |= check(NULL); av_hash_freep(&hash); - av_freep(&res); return ret; }