File: test_hash.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
context("Test AES encryption")

test_that("AES-128 encrypts and decrypts for all lengths", {
  skip_if(fips_mode())
  key <- md5(charToRaw("supersecret"))
  for(n in 0:100){
    x <- rand_bytes(n)
    y <- aes_cbc_encrypt(x, key)
    x2 <- aes_cbc_decrypt(y, key)
    expect_identical(x, x2)
  }
})

test_that("AES-256 encrypts and decrypts for all lengths", {
  key <- sha256(charToRaw("supersecret"))
  for(n in 0:100){
    x <- rand_bytes(n)
    y <- aes_cbc_encrypt(x, key)
    x2 <- aes_cbc_decrypt(y, key)
    expect_equal(x, x2)
  }
})

test_that("File API", {
  file <- system.file("DESCRIPTION")
  key <- rand_bytes(32)
  ct <- aes_cbc_encrypt(file, key)
  expect_equal(aes_cbc_decrypt(ct, key), readBin(file, raw(), 1e5))
})