logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

base64.sh (2403B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")"
  5. target="${WD}/../cmd/base64"
  6. plans=21
  7. . "$(dirname "$0")/tap.sh"
  8. t devnull '/dev/null' ''
  9. # Test vectors from RFC4648
  10. t --input='' 'rfc4648:' '' ''
  11. t --input='f' 'rfc4648:f' '' 'Zg==
  12. '
  13. t --input='fo' 'rfc4648:fo' '' 'Zm8=
  14. '
  15. t --input='foo' 'rfc4648:foo' '' 'Zm9v
  16. '
  17. t --input='foob' 'rfc4648:foob' '' 'Zm9vYg==
  18. '
  19. t --input='fooba' 'rfc4648:fooba' '' 'Zm9vYmE=
  20. '
  21. t --input='foobar' 'rfc4648:foobar' '' 'Zm9vYmFy
  22. '
  23. t --input='' 'rfc4648_decode:' '' ''
  24. t --input='Zg==\n' 'rfc4648_decode:Zg==\n' '-d' 'f'
  25. t --input='Zm8=\n' 'rfc4648_decode:Zm8=\n' '-d' 'fo'
  26. t --input='Zm9v\n' 'rfc4648_decode:Zm9v\n' '-d' 'foo'
  27. t --input='Zm9vYg==\n' 'rfc4648_decode:Zm9vYg==\n' '-d' 'foob'
  28. t --input='Zm9vYmE=\n' 'rfc4648_decode:Zm9vYmE=\n' '-d' 'fooba'
  29. t --input='Zm9vYmFy\n' 'rfc4648_decode:Zm9vYmFy\n' '-d' 'foobar'
  30. t_file multiliner_encode "$WD/outputs/base64/all_bytes_w76" "$WD/inputs/all_bytes"
  31. t_file multiliner_decode "$WD/inputs/all_bytes" -d "$WD/outputs/base64/all_bytes_w76"
  32. t_file oneliner_encode "$WD/outputs/base64/all_bytes_w0" -w0 "$WD/inputs/all_bytes"
  33. t_file oneliner_decode "$WD/inputs/all_bytes" -d -w0 "$WD/outputs/base64/all_bytes_w0"
  34. if [ "$(id -u)" = 0 ]
  35. then
  36. skip noperm 'needs to be run unprivileged'
  37. else
  38. touch "$WD/inputs/chmod_000"
  39. chmod 0000 "$WD/inputs/chmod_000"
  40. t --exit=1 'noperm' "$WD/inputs/chmod_000" "base64: Error opening ‘$WD/inputs/chmod_000’: Permission denied
  41. "
  42. chmod 0600 "$WD/inputs/chmod_000"
  43. rm "$WD/inputs/chmod_000"
  44. fi
  45. #atf_test_case devfull
  46. #devfull_body() {
  47. # error='inline:base64: Error writing: No space left on device\n'
  48. # [ "$(uname -s)" = "NetBSD" ] && error='inline:base64: Error writing: Inappropriate ioctl for device\n'
  49. # [ "$(uname -s)" = "FreeBSD" ] && error='inline:base64: Error writing: Inappropriate ioctl for device\n'
  50. #
  51. # atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 inputs/all_bytes >/dev/full'
  52. # atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 <inputs/all_bytes >/dev/full'
  53. # atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 - <inputs/all_bytes >/dev/full'
  54. #}
  55. #t --exit=1 'readslash' '/' 'base64: Error reading ‘/’: Is a directory
  56. #'
  57. t --exit=1 'enoent' '/var/empty/e/no/ent' 'base64: Error opening ‘/var/empty/e/no/ent’: No such file or directory
  58. '