Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit ecdc72a

Browse files
authored
Merge pull request Tarsnap#84 from Tarsnap/test-system-scrypt
Test system scrypt
2 parents e0e65f4 + 26c360a commit ecdc72a

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
3+
### Constants
4+
c_valgrind_min=1
5+
reference_file="${scriptdir}/test_scrypt.good"
6+
encrypted_file_1="${out}/sys-scrypt.enc"
7+
decrypted_file_1="${out}/sys-scrypt.txt"
8+
encrypted_file_2="${out}/our-scrypt.enc"
9+
decrypted_file_2="${out}/our-scrypt.txt"
10+
11+
scenario_cmd() {
12+
if [ -z "${system_scrypt}" ]; then
13+
printf "no suitable system scrypt: "
14+
# Inform test suite that we are skipping.
15+
setup_check_variables
16+
echo "-1" > ${c_exitfile}
17+
return
18+
fi
19+
20+
# Encrypt a file with our scrypt.
21+
setup_check_variables
22+
(
23+
echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \
24+
enc -P -t 1 ${reference_file} ${encrypted_file_1}
25+
echo $? > ${c_exitfile}
26+
)
27+
28+
# Use the system scrypt to decrypt the file we just
29+
# encrypted. Don't use valgrind for this.
30+
setup_check_variables
31+
(
32+
echo ${password} | ${system_scrypt}\
33+
dec -P ${encrypted_file_1} ${decrypted_file_1}
34+
echo $? > ${c_exitfile}
35+
)
36+
37+
# The decrypted file should match the reference.
38+
setup_check_variables
39+
if cmp -s ${decrypted_file_1} ${reference_file}; then
40+
echo "0"
41+
else
42+
echo "1"
43+
fi > ${c_exitfile}
44+
45+
# Encrypt a file with the system scrypt. Don't use
46+
# valgrind for this.
47+
setup_check_variables
48+
(
49+
echo ${password} | ${system_scrypt}\
50+
enc -P -t 1 ${reference_file} ${encrypted_file_2}
51+
echo $? > ${c_exitfile}
52+
)
53+
54+
# Use our scrypt to decrypt the file we just encrypted.
55+
setup_check_variables
56+
(
57+
echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \
58+
dec -P ${encrypted_file_2} ${decrypted_file_2}
59+
echo $? > ${c_exitfile}
60+
)
61+
62+
# The decrypted file should match the reference.
63+
setup_check_variables
64+
if cmp -s ${decrypted_file_2} ${reference_file}; then
65+
echo "0"
66+
else
67+
echo "1"
68+
fi > ${c_exitfile}
69+
}

tests/shared_test_functions.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ prepare_directories() {
6565
fi
6666
}
6767

68+
## find_system (cmd, args...):
69+
# Looks for ${cmd} in the $PATH, and ensure that it supports ${args}.
70+
find_system() {
71+
cmd=$1
72+
cmd_with_args=$@
73+
# Look for ${cmd}.
74+
system_binary=`command -v ${cmd}`
75+
if [ -z "${system_binary}" ]; then
76+
system_binary=""
77+
printf "System ${cmd} not found.\n" 1>&2
78+
# If the command exists, check it ensures the ${args}.
79+
elif ${cmd_with_args} 2>&1 >/dev/null |\
80+
grep -qE "(invalid|illegal) option"; then
81+
system_binary=""
82+
printf "Cannot use system ${cmd}; does not" 1>&2
83+
printf " support necessary arguments.\n" 1>&2
84+
fi
85+
echo "${system_binary}"
86+
}
6887

6988
## check_optional_valgrind ():
7089
# Return a $USE_VALGRIND variable defined; if it was previously defined and
@@ -177,7 +196,11 @@ notify_success_or_fail() {
177196
# Check each exitfile.
178197
for exitfile in `ls ${log_basename}-*.exit | sort`; do
179198
ret=`cat ${exitfile}`
180-
if [ "${ret}" -ne 0 ]; then
199+
if [ "${ret}" -lt 0 ]; then
200+
echo "SKIP!"
201+
return
202+
fi
203+
if [ "${ret}" -gt 0 ]; then
181204
echo "FAILED!"
182205
retval=${ret}
183206
if [ "${ret}" -eq "${valgrind_exit_code}" ]; then

tests/test_scrypt.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if [ -z ${bindir} ]; then
1717
bindir=".."
1818
fi
1919

20+
# Find system scrypt, and ensure it supports -P.
21+
system_scrypt=$( find_system scrypt enc -P )
22+
2023
# Check for optional valgrind.
2124
USE_VALGRIND=$( check_optional_valgrind )
2225

0 commit comments

Comments
 (0)