03-encrypt-decrypt-file.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. ### Constants
  3. c_valgrind_min=1
  4. reference_file="${scriptdir}/verify-strings/test_scrypt.good"
  5. encrypted_file="${out}/attempt.enc"
  6. decrypted_file="${out}/attempt.txt"
  7. scenario_cmd() {
  8. # Encrypt a file.
  9. setup_check_variables
  10. (
  11. echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \
  12. enc -P -t 1 ${reference_file} ${encrypted_file}
  13. echo $? > ${c_exitfile}
  14. )
  15. # The encrypted file should be different from the original file.
  16. # We cannot check against the "reference" encrypted file, because
  17. # encrypted files include random salt. If successful, don't delete
  18. # ${encrypted_file} yet; we need it for the next test.
  19. setup_check_variables
  20. cmp -s ${encrypted_file} ${reference_file}
  21. expected_exitcode 1 $? > ${c_exitfile}
  22. # Decrypt the file we just encrypted.
  23. setup_check_variables
  24. (
  25. echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \
  26. dec -P ${encrypted_file} ${decrypted_file}
  27. echo $? > ${c_exitfile}
  28. )
  29. # The decrypted file should match the reference.
  30. setup_check_variables
  31. cmp -s ${decrypted_file} ${reference_file}
  32. echo $? > ${c_exitfile}
  33. }