Browse Source

tools/ffhash: implement base64 output.

Also fix usage string: the algorithm is not optional.
tags/n2.3
Nicolas George 11 years ago
parent
commit
73c4b6ce4b
1 changed files with 18 additions and 7 deletions
  1. +18
    -7
      tools/ffhash.c

+ 18
- 7
tools/ffhash.c View File

@@ -21,6 +21,7 @@
*/ */


#include "config.h" #include "config.h"
#include "libavutil/avstring.h"
#include "libavutil/error.h" #include "libavutil/error.h"
#include "libavutil/hash.h" #include "libavutil/hash.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
@@ -40,13 +41,14 @@
#define SIZE 65536 #define SIZE 65536


static struct AVHashContext *hash; static struct AVHashContext *hash;
static int out_b64;


static void usage(void) static void usage(void)
{ {
int i = 0; int i = 0;
const char *name; const char *name;


printf("usage: ffhash [algorithm] [input]...\n");
printf("usage: ffhash [b64:]algorithm [input]...\n");
printf("Supported hash algorithms:"); printf("Supported hash algorithms:");
do { do {
name = av_hash_names(i); name = av_hash_names(i);
@@ -59,10 +61,16 @@ static void usage(void)


static void finish(void) static void finish(void)
{ {
char res[2 * AV_HASH_MAX_SIZE + 1];

av_hash_final_hex(hash, res, sizeof(res));
printf("%s=0x%s", av_hash_get_name(hash), res);
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) static int check(char *file)
@@ -110,16 +118,19 @@ int main(int argc, char **argv)
{ {
int i; int i;
int ret = 0; int ret = 0;
const char *hash_name;


if (argc == 1) { if (argc == 1) {
usage(); usage();
return 0; 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) { switch(ret) {
case AVERROR(EINVAL): case AVERROR(EINVAL):
printf("Invalid hash type: %s\n", argv[1]);
printf("Invalid hash type: %s\n", hash_name);
break; break;
case AVERROR(ENOMEM): case AVERROR(ENOMEM):
printf("%s\n", strerror(errno)); printf("%s\n", strerror(errno));


Loading…
Cancel
Save