$ docker run --rm --name validator-libsodium-usage-r-cran-sodium-hex2bin-invalid-input-2732 -t --mount type=bind,src=/tmp/validator-status-libsodium-usage-r-cran-sodium-hex2bin-invalid-input,dst=/validator/status validator-libsodium-shared bash -lc 'set -euo pipefail /validator/tests/_shared/install_override_debs.sh exec /validator/tests/_shared/run_library_tests.sh "$@"' validator-testcase libsodium usage-r-cran-sodium-hex2bin-invalid-input -- bash -c 'PS4=$1; shift; set -x; source "$@"' validator-xtrace '__VALIDATOR_XTRACE__ ' /validator/tests/libsodium/tests/cases/usage/usage-r-cran-sodium-hex2bin-invalid-input.sh no override packages found; continuing with apt originals suppressMessages(library(sodium)) # Odd-length hex must not silently produce a valid 1-byte decoding. ok_odd <- tryCatch({ res <- hex2bin("abc") # If no error, the result must not pretend to be a valid odd-length decoding. if (is.raw(res) && length(res) > 0 && length(res) * 2 == nchar("abc")) { TRUE } else { FALSE } }, error = function(e) FALSE) stopifnot(!isTRUE(ok_odd)) # Non-hex characters must be rejected (or yield a non-roundtripping value). ok_garbage <- tryCatch({ res <- hex2bin("zz") # Even if a value comes back, bin2hex(res) must not equal "zz". is.raw(res) && identical(tolower(bin2hex(res)), "zz") }, error = function(e) FALSE) stopifnot(!isTRUE(ok_garbage)) # Valid 64-char lowercase hex still round-trips to 32 raw bytes. valid <- paste0(rep("ab", 32), collapse = "") decoded <- hex2bin(valid) stopifnot(is.raw(decoded)) stopifnot(length(decoded) == 32) stopifnot(identical(bin2hex(decoded), valid)) cat("ok\n") ' ok