Error in `stringhash(x, algo, key)`: OpenSSL error: 0020810AF72E0000:error:03000086:digital envelope routines:evp_md_init_internal:initialization error:/usr/src/crypto/openssl/crypto/evp/digest.c:254:
al default library context, Algorithm (MD4 : 71), Properties ()

context("Test the length of the output of various algorithms.")
test_that("MD4 outputs a 32-character hash", {
test_that("MD5 outputs a 32-character hash", {
test_that("ripemd160 outputs a 40-character hash", {
test_that("SHA1 outputs a 40-character hash", {
test_that("SHA256 outputs a 64-character hash", {
test_that("SHA512 outputs a 128-character hash", {

"Test the length of the output of various algorithms."

test_that("Hash functions match openssl command line tool", {
# COMPARE: echo -n "foo" | openssl dgst -md4
test_that("HMAC functions match openssl command line tool", {
# #COMPARE: echo -n "foo" | openssl dgst -md4 -hmac "secret"
expect_that(unclass(sha1("foo", key = "secret")), equals("9baed91be7f58b57c824b60da7cb262b2ecafbd2"))
expect_that(unclass(sha256("foo", key = "secret")), equals("773ba44693c7553d6ee20f61ea5d2757a9a4f4a44d2841ae4e95b52e4cd62db4"))
expect_that(unclass(sha512("foo", key = "secret")), equals("82df7103de8d82de45e01c45fe642b5d13c6c2b47decafebc009431c665c6fa5f3d1af4e978ea1bde91426622073ebeac61a3461efd467e0971c788bc8ebdbbe"))
expect_that(unclass(md4("foo", key = "secret")), equals("93e81ded7aec4ec0d73a97bb4792742a"))
expect_that(unclass(md5("foo", key = "secret")), equals("ba19fbc606a960051b60244e9a5ed3d2"))
expect_that(unclass(ripemd160("foo", key = "secret")), equals("a87093c26e44fdfa04e142e59710daa94556a5ed"))
test_that("Connection interface matches raw interface", {
expect_equal(sha1(mydata, key = "secret"), sha1(file(tmp), key = "secret"))
expect_equal(sha256(mydata, key = "secret"), sha256(file(tmp), key = "secret"))
expect_equal(md5(mydata, key = "secret"), md5(file(tmp), key = "secret"))
test_that("Connection interface matches string interface", {
expect_equal(sha1(charToRaw("foo"), key = "secret"), sha1(textConnection("foo"), key = "secret"))
expect_equal(sha256(charToRaw("foo"), key = "secret"), sha256(textConnection("foo"), key = "secret"))
expect_equal(md5(charToRaw("foo"), key = "secret"), md5(textConnection("foo"), key = "secret"))