From 5349047602e96efdd0730af1dc34d6f18e94eb20 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:13:06 +0100 Subject: [PATCH] secretbase 1.0.0 --- DESCRIPTION | 4 +-- NEWS.md | 2 +- R/base.R | 66 +++++++++++++++++++++++---------------- R/secret.R | 2 +- inst/CITATION | 2 +- man/base64dec.Rd | 41 ++++++++++++++++++++++++ man/base64enc.Rd | 40 +++++++----------------- man/secretbase-package.Rd | 2 +- 8 files changed, 98 insertions(+), 61 deletions(-) create mode 100644 man/base64dec.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 94ba43d..45bab12 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/NEWS.md b/NEWS.md index 9429439..0f892f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/base.R b/R/base.R index 87ba416..9f714dc 100644 --- a/R/base.R +++ b/R/base.R @@ -14,53 +14,65 @@ # You should have received a copy of the GNU General Public License along with # secretbase. If not, see . -# 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) diff --git a/R/secret.R b/R/secret.R index f0e012b..5688d03 100644 --- a/R/secret.R +++ b/R/secret.R @@ -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 diff --git a/inst/CITATION b/inst/CITATION index 42a51fd..11d259a 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -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), diff --git a/man/base64dec.Rd b/man/base64dec.Rd new file mode 100644 index 0000000..14b0dd4 --- /dev/null +++ b/man/base64dec.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/base.R +\name{base64dec} +\alias{base64dec} +\title{Base64 Decode} +\usage{ +base64dec(x, convert = TRUE) +} +\arguments{ +\item{x}{an object.} + +\item{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.} +} +\value{ +A character string, raw vector, or other object depending on the + value of \sQuote{convert}. +} +\description{ +Decodes a character string, raw vector or other object from base64 encoding. +} +\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. +} +\examples{ +base64dec(base64enc("secret base")) +base64dec(base64enc(as.raw(c(1L, 2L, 4L))), convert = FALSE) +base64dec(base64enc(data.frame()), convert = NA) + +} +\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}} +} diff --git a/man/base64enc.Rd b/man/base64enc.Rd index a4dd0ed..efdcd07 100644 --- a/man/base64enc.Rd +++ b/man/base64enc.Rd @@ -2,51 +2,32 @@ % Please edit documentation in R/base.R \name{base64enc} \alias{base64enc} -\alias{base64dec} -\title{Base64 Encode / Decode} +\title{Base64 Encode} \usage{ base64enc(x, convert = TRUE) - -base64dec(x, convert = TRUE) } \arguments{ \item{x}{an object.} -\item{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.} +\item{convert}{[default TRUE] logical TRUE to encode to a character string or +FALSE to a raw vector.} } \value{ -For \strong{base64enc}: 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}. +A character string or raw vector depending on the value of + \sQuote{convert}. } \description{ -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. } \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. +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). } \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) } \references{ @@ -54,3 +35,6 @@ 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}} +} diff --git a/man/secretbase-package.Rd b/man/secretbase-package.Rd index 87272e7..e1d3aba 100644 --- a/man/secretbase-package.Rd +++ b/man/secretbase-package.Rd @@ -5,7 +5,7 @@ \name{secretbase-package} \alias{secretbase} \alias{secretbase-package} -\title{secretbase: Cryptographic Hash and Extendable-Output Functions} +\title{secretbase: Cryptographic Hash, Extendable-Output and Base64 Functions} \description{ Fast and memory-efficient streaming hash functions and base64 encoding and decoding. Performs direct hashing of strings and raw vectors. Stream