Skip to content

Commit

Permalink
refresh docs
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jan 16, 2025
1 parent b921b7e commit 800a173
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 101 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: Cryptographic Hash, Extendable-Output and Base64 Functions
Version: 1.0.3.9000
Description: Fast and memory-efficient streaming hash functions and base64
encoding / decoding. Hashes strings and raw vectors directly. Stream hashes
files potentially larger than memory, as well as in-memory objects through
files which can be larger than memory, as well as in-memory objects through
R's serialization mechanism. Implementations include the SHA-256, SHA-3 and
'Keccak' cryptographic hash functions, SHAKE256 extendable-output function
(XOF), and 'SipHash' pseudo-random function.
Expand Down
19 changes: 9 additions & 10 deletions R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
#' 3, big-endian representation).
#'
#' @param x an object.
#' @param convert logical TRUE to encode to a character string or FALSE to a raw
#' vector.
#' @param convert logical `TRUE` to encode to a character string or `FALSE` to a
#' raw vector.
#'
#' @return 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 `convert`.
#'
#' @references
#' This implementation is based that by 'The Mbed TLS Contributors' under the
Expand All @@ -51,18 +50,18 @@ base64enc <- function(x, convert = TRUE) .Call(secretbase_base64enc, x, convert)
#'
#' Decodes a character string, raw vector or other object from base64 encoding.
#'
#' The value of \sQuote{convert} should be set to TRUE, FALSE or NA to be the
#' The value of `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.
#'
#' @param x an object.
#' @param convert 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 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}. If conversion to a character string fails, a raw
#' vector will be returned instead (accompanied by a warning).
#' value of `convert`. If conversion to a character string fails, a raw vector
#' will be returned instead (accompanied by a warning).
#'
#' @references
#' This implementation is based that by 'The Mbed TLS Contributors' under the
Expand Down
43 changes: 19 additions & 24 deletions R/secret.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#' secretbase: Cryptographic Hash, Extendable-Output and Base64 Functions
#'
#' Fast and memory-efficient streaming hash functions and base64 encoding /
#' decoding. Hashes strings and raw vectors directly. Stream hashes files
#' potentially larger than memory, as well as in-memory objects through R's
#' decoding. Hashes strings and raw vectors directly. Stream hashes files which
#' can be larger than memory, as well as in-memory objects through R's
#' serialization mechanism. Implementations include the SHA-256, SHA-3 and
#' 'Keccak' cryptographic hash functions, SHAKE256 extendable-output function
#' (XOF), and 'SipHash' pseudo-random function.
Expand All @@ -40,18 +40,17 @@
#' Returns a SHA-3 hash of the supplied object or file.
#'
#' @param x object to hash. A character string or raw vector (without
#' attributes) is hashed \sQuote{as is}. All other objects are stream hashed
#' using R serialization (but without allocation of the serialized object).
#' attributes) is hashed *as is*. All other objects are stream hashed
#' using R serialization (without allocation of the serialized object).
#' @param bits integer output size of the returned hash. Must be one of 224,
#' 256, 384 or 512.
#' @param convert logical TRUE to convert the hash to its hex representation as
#' a character string, FALSE to return directly as a raw vector, or NA to
#' return as a vector of (32-bit) integers.
#' @param file character file name / path. If specified, \sQuote{x} is ignored.
#' The file is stream hashed, hence files larger than memory are permitted.
#'
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#' @param convert logical `TRUE` to convert the hash to its hex representation
#' as a character string, `FALSE` to return directly as a raw vector, or `NA`
#' to return as a vector of (32-bit) integers.
#' @param file character file name / path. If specified, `x` is ignored. The
#' file is stream hashed, and the file can be larger than memory.
#'
#' @return A character string, raw or integer vector depending on `convert`.
#'
#' @section R Serialization Stream Hashing:
#'
Expand Down Expand Up @@ -106,8 +105,7 @@ sha3 <- function(x, bits = 256L, convert = TRUE, file)
#' @param bits integer output size of the returned hash. Value must be between 8
#' and 2^24.
#'
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#' @return A character string, raw or integer vector depending on `convert`.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -143,8 +141,7 @@ shake256 <- function(x, bits = 256L, convert = TRUE, file)
#'
#' @inheritParams sha3
#'
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#' @return A character string, raw or integer vector depending on `convert`.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -192,12 +189,11 @@ keccak <- function(x, bits = 256L, convert = TRUE, file)
#' key is supplied.
#'
#' @inheritParams sha3
#' @param key if NULL, the SHA-256 hash of \sQuote{x} is returned. If a
#' character string or raw vector, this is used as a secret key to generate an
#' HMAC. Note: for character vectors, only the first element is used.
#' @param key if `NULL`, the SHA-256 hash of `x` is returned. If a character
#' string or raw vector, this is used as a secret key to generate an HMAC.
#' Note: for character vectors, only the first element is used.
#'
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#' @return A character string, raw or integer vector depending on `convert`.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -242,12 +238,11 @@ sha256 <- function(x, key = NULL, convert = TRUE, file)
#'
#' @inheritParams sha3
#' @param key a character string or raw vector comprising the 16 byte (128 bit)
#' key data, or else NULL which is equivalent to '0'. If a longer vector is
#' key data, or else `NULL` which is equivalent to '0'. If a longer vector is
#' supplied, only the first 16 bytes are used, and if shorter, padded with
#' trailing '0'. Note: for character vectors, only the first element is used.
#'
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#' @return A character string, raw or integer vector depending on `convert`.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ knitr::opts_chunk$set(

Fast and memory-efficient streaming hash functions and base64 encoding / decoding.

Hashes strings and raw vectors directly. Stream hashes files potentially larger than memory, as well as in-memory objects through R's serialization mechanism.
Hashes strings and raw vectors directly. Stream hashes files which can be larger than memory, as well as in-memory objects through R's serialization mechanism.

Implementations include the SHA-256, SHA-3 and 'Keccak' cryptographic hash functions, SHAKE256 extendable-output function (XOF), and 'SipHash' pseudo-random function.

Expand Down Expand Up @@ -112,7 +112,7 @@ sha256("secret base", key = "秘密の基地の中")
SipHash-1-3 is optimized for performance. <br />
Pass to `key` a character string or raw vector of up to 16 bytes (128 bits):
```{r siphash}
siphash13("secret base", key = charToRaw("秘密の基地の中"))
siphash13("secret base", key = "秘密の基地の中")
```

#### Base64 Encoding / Decoding
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=ff803d)](https
Fast and memory-efficient streaming hash functions and base64 encoding /
decoding.

Hashes strings and raw vectors directly. Stream hashes files potentially
larger than memory, as well as in-memory objects through R’s
Hashes strings and raw vectors directly. Stream hashes files which can
be larger than memory, as well as in-memory objects through R’s
serialization mechanism.

Implementations include the SHA-256, SHA-3 and ‘Keccak’ cryptographic
Expand Down Expand Up @@ -130,7 +130,7 @@ SipHash-1-3 is optimized for performance. <br /> Pass to `key` a
character string or raw vector of up to 16 bytes (128 bits):

``` r
siphash13("secret base", key = charToRaw("秘密の基地の中"))
siphash13("secret base", key = "秘密の基地の中")
#> [1] "a1f0a751892cc7dd"
```

Expand Down
12 changes: 6 additions & 6 deletions man/base64dec.Rd

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

7 changes: 3 additions & 4 deletions man/base64enc.Rd

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

17 changes: 8 additions & 9 deletions man/keccak.Rd

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

4 changes: 2 additions & 2 deletions man/secretbase-package.Rd

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

23 changes: 11 additions & 12 deletions man/sha256.Rd

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

17 changes: 8 additions & 9 deletions man/sha3.Rd

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

17 changes: 8 additions & 9 deletions man/shake256.Rd

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

19 changes: 9 additions & 10 deletions man/siphash13.Rd

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

0 comments on commit 800a173

Please sign in to comment.