03-encrypt-decrypt-file.sh 1.3 KB

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