Skip to content

Commit

Permalink
secretbase 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jun 16, 2024
1 parent 5ff8162 commit 5349047
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 61 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: secretbase
Type: Package
Title: Cryptographic Hash and Extendable-Output Functions
Version: 0.5.0.9003
Title: Cryptographic Hash, Extendable-Output and Base64 Functions
Version: 1.0.0
Description: Fast and memory-efficient streaming hash functions and base64
encoding and decoding. Performs direct hashing of strings and raw vectors.
Stream hashes files potentially larger than memory, as well as in-memory
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# secretbase 0.5.0.9003 (development)
# secretbase 1.0.0

* Adds base64 encoding and decoding.
* `sha3()` restricts 'bit' argument to one of 224, 256, 384 or 512.
Expand Down
66 changes: 39 additions & 27 deletions R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,65 @@
# You should have received a copy of the GNU General Public License along with
# secretbase. If not, see <https://www.gnu.org/licenses/>.

# secretbase - Base Functions --------------------------------------------------
# secretbase - Base64 Functions ------------------------------------------------

#' Base64 Encode / Decode
#' Base64 Encode
#'
#' Encodes / decodes a character string, raw vector or other object to base64
#' encoding.
#' Encodes a character string, raw vector or other object to base64 encoding.
#'
#' @param x an object.
#' @param convert For \strong{base64enc}: [default TRUE] logical TRUE to encode
#' to a character string or FALSE to a raw vector.\cr
#' For \strong{base64dec}: [default TRUE] logical TRUE to convert back to a
#' character string, FALSE to convert back to a raw vector or NA to decode
#' and then unserialize back to the original object.
#' @param convert [default TRUE] logical TRUE to encode to a character string or
#' FALSE to a raw vector.
#'
#' @return For \strong{base64enc}: A character string or raw vector depending on
#' the value of \sQuote{convert}.
#' @return A character string or raw vector depending on the value of
#' \sQuote{convert}.
#'
#' For \strong{base64dec}: A character string, raw vector, or other object
#' depending on the value of \sQuote{convert}.
#'
#' @details For encoding: a character string or raw vector (with no attributes)
#' is encoded \emph{as is}, whilst all other objects are first serialized
#' (using R serialisation version 3, big-endian representation).
#'
#' For decoding: the value of \sQuote{convert} should be set to TRUE, FALSE
#' or NA to be the analogue of the above 3 cases in order to return the
#' original object.
#' @details A character string or raw vector (with no attributes) is encoded
#' \emph{as is}, whilst all other objects are first serialized (using R
#' serialisation version 3, big-endian representation).
#'
#' @references This implementation is based that by 'The Mbed TLS Contributors'
#' under the 'Mbed TLS' Trusted Firmware Project at
#' \url{https://www.trustedfirmware.org/projects/mbed-tls}.
#'
#' @seealso \code{\link{base64dec}}
#'
#' @examples
#' base64enc("secret base")
#' base64dec(base64enc("secret base"))
#'
#' base64enc(as.raw(c(1L, 2L, 4L)), convert = FALSE)
#' base64dec(base64enc(as.raw(c(1L, 2L, 4L))), convert = FALSE)
#'
#' base64enc(data.frame())
#' base64dec(base64enc(data.frame()), convert = NA)
#'
#' @export
#'
base64enc <- function(x, convert = TRUE) .Call(secretbase_base64enc, x, convert)

#' @rdname base64enc
#' Base64 Decode
#'
#' Decodes a character string, raw vector or other object from base64 encoding.
#'
#' @param x an object.
#' @param convert [default TRUE] logical TRUE to convert back to a character
#' string, FALSE to convert back to a raw vector or NA to decode and then
#' unserialize back to the original object.
#'
#' @return A character string, raw vector, or other object depending on the
#' value of \sQuote{convert}.
#'
#' @details The value of \sQuote{convert} should be set to TRUE, FALSE or NA to
#' be the reverse of the 3 encoding operations (for strings, raw vectors and
#' arbitrary objects), in order to return the original object.
#'
#' @references This implementation is based that by 'The Mbed TLS Contributors'
#' under the 'Mbed TLS' Trusted Firmware Project at
#' \url{https://www.trustedfirmware.org/projects/mbed-tls}.
#'
#' @seealso \code{\link{base64enc}}
#'
#' @examples
#' base64dec(base64enc("secret base"))
#' base64dec(base64enc(as.raw(c(1L, 2L, 4L))), convert = FALSE)
#' base64dec(base64enc(data.frame()), convert = NA)
#'
#' @export
#'
base64dec <- function(x, convert = TRUE) .Call(secretbase_base64dec, x, convert)
2 changes: 1 addition & 1 deletion R/secret.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# secretbase - Package Documentation -------------------------------------------

#' secretbase: Cryptographic Hash and Extendable-Output Functions
#' secretbase: Cryptographic Hash, Extendable-Output and Base64 Functions
#'
#' Fast and memory-efficient streaming hash functions and base64 encoding and
#' decoding. Performs direct hashing of strings and raw vectors. Stream
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bibentry(bibtype = "Manual",
title = "secretbase: Cryptographic Hash and Extendable-Output Functions",
title = "secretbase: Cryptographic Hash, Extendable-Output and Base64 Functions",
author = person("Charlie", "Gao"),
year = 2024,
note = sprintf("R package version %s", meta$Version),
Expand Down
41 changes: 41 additions & 0 deletions man/base64dec.Rd

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

40 changes: 12 additions & 28 deletions man/base64enc.Rd

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

2 changes: 1 addition & 1 deletion man/secretbase-package.Rd

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

0 comments on commit 5349047

Please sign in to comment.