1suppressMessages(library(digest))
2
3isWindows <- Sys.info()[["sysname"]] == "Windows"
4
5res <- digest(charToRaw("test"), "blake3", serialize = FALSE)
6
7# generated using the blake3 rust implementation
8expected <- "4878ca0425c739fa427f7eda20fe845f6b2e46ba5fe2a14df5b1e32f50603215"
9expect_equal(
10  res,
11  expected
12)
13
14res <- digest(charToRaw("test"), "blake3", serialize = FALSE, raw = TRUE)
15expect_equal(
16  paste0(res, collapse = ""),
17  expected
18)
19
20## blake3 example
21blake3Input <-
22  c(
23    "abc",
24    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
25    ""
26  )
27blake3Output <-
28  c(
29    "6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85",
30    "c19012cc2aaf0dc3d8e5c45a1b79114d2df42abb2a410bf54be09e891af06ff8",
31    "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
32  )
33for (i in seq(along = blake3Input)) {
34  blake3 <- digest(blake3Input[i], algo = "blake3", serialize = FALSE)
35  expect_equal(
36    blake3,
37    blake3Output[i]
38  )
39}
40
41if (isWindows) exit_file("Skipping remainder on Windows platform")
42
43# test file
44# used the b3sum rust crate
45file <- tempfile()
46writeLines("test", file)
47res <- digest(file = file, algo = "blake3")
48try(file.remove(file))
49expect_equal(
50  res,
51  "dea2b412aa90f1b43a06ca5e8b8feafec45ae1357971322749480f4e1572eaa2"
52)
53
54# try another long text
55file <- tempfile()
56text <- paste0(rep(LETTERS, 1000), collapse = "-")
57writeLines(text, file)
58res <- digest(file = file, algo = "blake3")
59try(file.remove(file))
60expect_equal(
61  res,
62  "a84aef38d9a7ad55fa458d9d1857eb895832e358385e8b6466c6af54ea46eeaa"
63)
64