Skip to content

Commit

Permalink
polish documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 2, 2024
1 parent 8fc80e3 commit e1c1a4a
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 60 deletions.
2 changes: 1 addition & 1 deletion R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ base64enc <- function(x, convert = TRUE) .Call(secretbase_base64enc, x, convert)
#'
#' @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 (along with a warning).
#' a raw vector will be returned instead (accompanied by a warning).
#'
#' @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
Expand Down
38 changes: 22 additions & 16 deletions R/secret.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@
#' 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 'as is'. All other objects are stream hashed using
#' R serialization (but without allocation of the serialized object).
#' attributes) is hashed \sQuote{as is}. All other objects are stream hashed
#' using R serialization (but without allocation of the serialized object).
#' @param bits [default 256L] output size of the returned hash. Must be one of
#' 224, 256, 384 or 512.
#' @param convert [default TRUE] if TRUE, the hash is converted to its hex
#' representation as a character string, if FALSE, output directly as a raw
#' vector, or if NA, a vector of (32-bit) integer values.
#' @param file character file name / path. If specified, 'x' is ignored. The
#' file is stream hashed, thus capable of handling files larger than memory.
#' @param file character file name / path. If specified, \sQuote{x} is ignored.
#' The file is stream hashed, thus capable of handling files larger than
#' memory.
#'
#' @return A character string, raw or integer vector depending on 'convert'.
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#'
#' @section R Serialization Stream Hashing:
#'
Expand Down Expand Up @@ -101,11 +103,12 @@ sha3 <- function(x, bits = 256L, convert = TRUE, file)
#' @param bits [default 256L] output size of the returned hash. Must be between
#' 8 and 2^24 and coercible to integer.
#'
#' @return A character string, raw or integer vector depending on 'convert'.
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#'
#' @details To produce single integer values suitable for use as random seeds
#' for R's pseudo random number generators (RNGs), set 'bits' to 32 and
#' 'convert' to NA.
#' for R's pseudo random number generators (RNGs), set \sQuote{bits} to 32
#' and \sQuote{convert} to NA.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -140,7 +143,8 @@ shake256 <- function(x, bits = 256L, convert = TRUE, file)
#'
#' @inheritParams sha3
#'
#' @return A character string, raw or integer vector depending on 'convert'.
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -187,12 +191,13 @@ keccak <- function(x, bits = 256L, convert = TRUE, file)
#' key is supplied.
#'
#' @inheritParams sha3
#' @param key [default NULL] If NULL, the SHA-256 hash of 'x' is returned.
#' Alternatively, supply a character string or raw vector as a secret key to
#' generate an HMAC. Note: for character vectors only the first element is
#' used.
#' @param key [default NULL] If NULL, the SHA-256 hash of \sQuote{x} is
#' returned. Alternatively, supply a character string or raw vector 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 'convert'.
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down Expand Up @@ -238,10 +243,11 @@ sha256 <- function(x, key = NULL, convert = TRUE, file)
#' @param key [default NULL] 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 supplied, only the first 16 bytes are used, and if
#' shorter, padded with trailing '0'. Note: for character vectors only the
#' 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 'convert'.
#' @return A character string, raw or integer vector depending on
#' \sQuote{convert}.
#'
#' @inheritSection sha3 R Serialization Stream Hashing
#'
Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ library(secretbase)

#### SHA-3

For the SHA-3 cryptographic hash algorithm, specify 'bits' as `224`, `256`, `384` or `512`:
For the SHA-3 cryptographic hash algorithm, specify `bits` as `224`, `256`, `384` or `512`:

```{r sha3}
sha3("secret base")
Expand Down Expand Up @@ -83,7 +83,7 @@ unlink(file)
#### Hash to integer / SHAKE256 XOF

May be used as deterministic random seeds for R's pseudo random number generators (RNGs). <br />
Specify 'convert' as `NA` (and 'bits' as `32` for a single integer value):
Specify `convert = NA` (and `bits = 32` for a single integer value):
```{r integer}
shake256("秘密の基地の中", bits = 32L, convert = NA)
```
Expand All @@ -102,15 +102,15 @@ keccak("secret base", bits = 384L)
sha256("secret base")
```

For SHA-256 HMAC, pass a character string or raw vector to 'key':
For SHA-256 HMAC, pass to `key` a character string or raw vector:
```{r hmac}
sha256("secret base", key = "秘密の基地の中")
```

#### SipHash

SipHash-1-3 is optimized for performance. <br />
Pass a character string or raw vector of up to 16 bytes (128 bits) to 'key':
Pass to `key` a character string or raw vector of up to 16 bytes (128 bits):
```{r siphash}
siphash13("secret base", key = charToRaw("秘密の基地の中"))
```
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library(secretbase)

#### SHA-3

For the SHA-3 cryptographic hash algorithm, specify bits as `224`,
For the SHA-3 cryptographic hash algorithm, specify `bits` as `224`,
`256`, `384` or `512`:

``` r
Expand Down Expand Up @@ -89,8 +89,8 @@ sha3(file = file)
#### Hash to integer / SHAKE256 XOF

May be used as deterministic random seeds for R’s pseudo random number
generators (RNGs). <br /> Specify convert’ as `NA` (and bits’ as `32`
for a single integer value):
generators (RNGs). <br /> Specify `convert = NA` (and `bits = 32` for a
single integer value):

``` r
shake256("秘密の基地の中", bits = 32L, convert = NA)
Expand All @@ -117,7 +117,7 @@ sha256("secret base")
#> [1] "1951c1ca3d50e95e6ede2b1c26fefd0f0e8eba1e51a837f8ccefb583a2b686fe"
```

For SHA-256 HMAC, pass a character string or raw vector to ‘key’:
For SHA-256 HMAC, pass to `key` a character string or raw vector:

``` r
sha256("secret base", key = "秘密の基地の中")
Expand All @@ -126,8 +126,8 @@ sha256("secret base", key = "秘密の基地の中")

#### SipHash

SipHash-1-3 is optimized for performance. <br /> Pass a character string
or raw vector of up to 16 bytes (128 bits) to ‘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
siphash13("secret base", key = charToRaw("秘密の基地の中"))
Expand Down
2 changes: 1 addition & 1 deletion man/base64dec.Rd

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

12 changes: 7 additions & 5 deletions man/keccak.Rd

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

20 changes: 11 additions & 9 deletions man/sha256.Rd

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

12 changes: 7 additions & 5 deletions man/sha3.Rd

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

16 changes: 9 additions & 7 deletions man/shake256.Rd

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

14 changes: 8 additions & 6 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 e1c1a4a

Please sign in to comment.