peek_packet.c: update comments to reflect remote_port addition
[girocco/readme.git] / src / ltsha256-test.sh
blob359391d387a237e5d83f3b82da221d9c98663347
1 #!/bin/sh
3 # License: public domain -or- http://www.wtfpl.net/txt/copying/
5 die() { >&2 printf 'Bail out! %s\n' "$*"; exit 1; }
7 testnum=0
9 # $1 => value to hash (may contain escapes)
10 # $2 => lowercase sha256 hash expected
11 # $3... => test name
12 test_sha256() {
13 _val="$1"; shift
14 _hash="$1"; shift
15 _test="$*"
16 _check="$(printf '%b' "$_val" | ./ltsha256)" ||
17 die "could not run ltsha256 utility"
18 _result="ok"
19 [ "$_check" = "$_hash" ] || _result="not ok"
20 testnum="$(( $testnum + 1 ))"
21 printf '%s %u - %s\n' "$_result" "$testnum" "$_test"
24 echo '1..4'
26 test_sha256 \
27 "abc" \
28 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad \
29 abc
31 test_sha256 \
32 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \
33 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 \
34 abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
36 test_sha256 \
37 "123456789" \
38 15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225 \
39 123456789
41 test_sha256 \
42 "The quick brown fox jumped over the lazy dog.\n" \
43 40d5c6f7fe5672fb52269f651c2b985867dfcfa4a5c5258e3d4f8736d5095037 \
44 "quick brown fox"
46 exit 0