Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ Rprof\.out
^scripts$
^vignettes_src$
^appveyor\.yml$
^.*\.Rproj$
^\.Rproj\.user$
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ URL: https://github.com/richfitz/storr
BugReports: https://github.com/richfitz/storr/issues
Imports:
R6 (>= 2.1.0),
base64url,
digest
Suggests:
DBI (>= 0.6),
Expand All @@ -27,5 +28,5 @@ Suggests:
rbenchmark,
testthat (>= 1.0.0)
VignetteBuilder: knitr
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
Encoding: UTF-8
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export(storr_rds)
export(storr_redis_api)
export(test_driver)
importFrom(R6,R6Class)
importFrom(base64url,base64_urlencode)
37 changes: 16 additions & 21 deletions R/base64.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
##' @param pad Logical, indicating if strings should be padded with
##' \code{=} characters (as RFC 4648 requires)
##' @export
##' @importFrom base64url base64_urlencode
##' @examples
##' x <- encode64("hello")
##' x
Expand All @@ -21,28 +22,22 @@ encode64 <- function(x, char62 = "-", char63 = "_", pad = TRUE) {
if (length(x) != 1L) {
return(vcapply(x, encode64, char62, char63, pad, USE.NAMES = FALSE))
}
tr <- c(LETTERS, letters, 0:9, char62, char63)
x <- as.integer(charToRaw(x))
n_bytes <- length(x)
n_blocks <- ceiling(n_bytes / 3L)
n_pad <- 3L * n_blocks - n_bytes

## The integer() call here pads the *input* to have the correct number
## of blocks of bytes.
x <- matrix(c(x, integer(3L * n_blocks - n_bytes)), 3L, n_blocks)

y <- matrix(integer(4 * n_blocks), 4L, n_blocks)
y[1L, ] <- bitwShiftR(x[1L, ], 2L)
y[2L, ] <- bitwOr(bitwShiftL(x[1L, ], 4L), bitwShiftR(x[2L, ], 4L))
y[3L, ] <- bitwOr(bitwShiftL(x[2L, ], 2L), bitwShiftR(x[3L, ], 6L))
y[4L, ] <- x[3L, ]

z <- tr[bitwAnd(y, 63L) + 1L]
if (n_pad > 0) {
len <- length(z)
z[(len - n_pad + 1):len] <- if (pad) "=" else ""
out <- base64url::base64_urlencode(x)
if (!identical(char62, "-")) {
gsub(pattern = "-", replacement = char62, x = out, fixed = TRUE)
}
if (!identical(char63, "_")) {
gsub(pattern = "_", replacement = char62, x = out, fixed = TRUE)
}
if (pad) {
x <- as.integer(charToRaw(x))
n_bytes <- length(x)
n_blocks <- ceiling(n_bytes / 3L)
n_pad <- 3L * n_blocks - n_bytes
char_pad <- replicate(n_pad, "=")
out <- paste(c(out, char_pad), collapse = "")
}
paste0(z, collapse = "")
out
}


Expand Down
5 changes: 3 additions & 2 deletions man/storr_rds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.