X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-hash.c;h=f3578c76a7068a6a7b072709c261486ab715edb8;hb=4efa2cf91ddcce727fd66be55f504510b6400b8b;hp=31791b184a197fd3f16c8b55e0b9b69aaae22616;hpb=adbbf2f54cfd5254ed439e17d2fa21d22ed072fd;p=zpackage diff --git a/zpm-hash.c b/zpm-hash.c index 31791b1..f3578c7 100644 --- a/zpm-hash.c +++ b/zpm-hash.c @@ -1,11 +1,39 @@ #include #include #include "zpm.h" +#include "sha256.h" int main(int ac, char **av){ int rv; char hash[65]; + /* + * hash stdin + */ + if (ac == 1 || (ac == 2 && !strcmp(av[1], "-"))) { + hash_state md; + unsigned char buf[4096]; + size_t bytes; + unsigned char tmp[32]; + int j; + + sha256_init(&md); + do { + bytes = fread(buf, 1, sizeof buf, stdin); + sha256_process(&md, buf, bytes); + } while (bytes && !feof(stdin)); + if (ferror(stdin)) { + exit(1); + } + sha256_done(&md, tmp); + for (j=0;j<32;j++) { + sprintf(hash+j*2, "%02x", (unsigned)tmp[j]); + } + hash[64] = 0; + printf("%s\n", hash); + return 0; + } + if (ac < 2) { fprintf(stderr, "usage: path\n"); return 1;