diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:10:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:10:49 +0000 |
commit | cfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch) | |
tree | d0baf160cbee3195249d095f85e52d20c21acf02 /tests/helpers/test_sha1.c | |
parent | Initial commit. (diff) | |
download | util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip |
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/helpers/test_sha1.c')
-rw-r--r-- | tests/helpers/test_sha1.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/helpers/test_sha1.c b/tests/helpers/test_sha1.c new file mode 100644 index 0000000..7cb107f --- /dev/null +++ b/tests/helpers/test_sha1.c @@ -0,0 +1,37 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * Copyright (C) 2017 Philip Prindeville <philipp@redfish-solutions.com> + */ +#include <stdio.h> +#include <unistd.h> +#include <err.h> +#include <stdlib.h> + +#include "sha1.h" + +int main(void) +{ + int i, ret; + UL_SHA1_CTX ctx; + unsigned char digest[UL_SHA1LENGTH]; + unsigned char buf[BUFSIZ]; + + ul_SHA1Init( &ctx ); + + while(!feof(stdin) && !ferror(stdin)) { + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret) + ul_SHA1Update( &ctx, buf, ret ); + } + + if(freopen ("/dev/null", "r", stdin) == NULL) + err(EXIT_FAILURE, "stdin->null failed!"); + + ul_SHA1Final( digest, &ctx ); + + for (i = 0; i < UL_SHA1LENGTH; i++) + printf( "%02x", digest[i] ); + printf("\n"); + return 0; +} |