Skip to content

Commit

Permalink
Add tests for envelope.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpvgoncalves committed Oct 1, 2023
1 parent d7c6fd0 commit df6cb66
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/testthat/test-envelope_create.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test_that("envelope with Kyber512", {

key <- keygen_kyber(512)
env <- envelope_create("Very important message.", key$public)

expect_true(inherits(env, "pqcrypto_cms_id_enveloped_data"))
expect_equal(length(env), 3)
})

test_that("envelope with Kyber768", {

key <- keygen_kyber(768)
env <- envelope_create("Very important message.", key$public)

expect_true(inherits(env, "pqcrypto_cms_id_enveloped_data"))
expect_equal(length(env), 3)
})

test_that("envelope with Kyber1024", {

key <- keygen_kyber(1024)
env <- envelope_create("Very important message.", key$public)

expect_true(inherits(env, "pqcrypto_cms_id_enveloped_data"))
expect_equal(length(env), 3)
})

test_that("fails on bad parameters", {

key <- keygen_kyber()
expect_error(envelope_create("My Message.", key$private))

key <- keygen_dilithium()
expect_error(envelope_create("My Message.", key$public))

})
78 changes: 78 additions & 0 deletions tests/testthat/test-envelope_open.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
test_that("Open envelope Kyber512", {

key <- keygen_kyber(512)

env <- envelope_create("My very important message.", key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, "My very important message.")

env <- envelope_create(1234567890, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, 1234567890)

env <- envelope_create(TRUE, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, TRUE)

obj <- data.frame(x = 1:3, y = letters[1:3])
env <- envelope_create(obj, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, obj)
})

test_that("Open envelope Kyber768", {

key <- keygen_kyber(768)

env <- envelope_create("My very important message.", key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, "My very important message.")

env <- envelope_create(1234567890, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, 1234567890)

env <- envelope_create(TRUE, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, TRUE)

obj <- data.frame(x = 1:3, y = letters[1:3])
env <- envelope_create(obj, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, obj)
})

test_that("Open envelope Kyber1024", {

key <- keygen_kyber(1024)

env <- envelope_create("My very important message.", key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, "My very important message.")

env <- envelope_create(1234567890, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, 1234567890)

env <- envelope_create(TRUE, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, TRUE)

obj <- data.frame(x = 1:3, y = letters[1:3])
env <- envelope_create(obj, key$public)
msg <- envelope_open(env, key$private)
expect_identical(msg, obj)
})

test_that("Failure on wrong data", {

key <- keygen_kyber(512)
env <- envelope_create("My very important message.", key$public)

expect_error(envelope_open(env, key$public))
expect_error(envelope_open("not_an_envelope", key$public))

key <- keygen_dilithium()
expect_error(envelope_open(env, key$private))

})

0 comments on commit df6cb66

Please sign in to comment.