Skip to content

Commit

Permalink
deprecate base64enc/base64dec
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jun 11, 2024
1 parent 85dd672 commit c2a08d4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 39 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* `request()` specifying argument 'cv' other than NULL or a 'conditionVariable' will cause the pipe connection to be dropped when the reply is (asynchronously) completed.
* Deprecated functions `strcat()`, `recv_aio_signal()` and `request_signal()` are removed.
* `base64enc()` and `base64dec()` are deprecated in favour of those in the {secretbase} package.

# nanonext 1.1.0

Expand Down
5 changes: 4 additions & 1 deletion R/tls.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ tls_config <- function(client = NULL, server = NULL, pass = NULL, auth = is.null
#' Base64 Encode / Decode
#'
#' Encodes / decodes a character string, raw vector or other object to base64
#' encoding.
#' encoding. DEPRECATED - these functions will be removed in a future
#' release.
#'
#' @param x an object.
#' @param convert For \strong{base64enc}: [default TRUE] logical TRUE to encode
Expand Down Expand Up @@ -109,11 +110,13 @@ tls_config <- function(client = NULL, server = NULL, pass = NULL, auth = is.null
#' base64enc(data.frame())
#' base64dec(base64enc(data.frame()), convert = NA)
#'
#' @keywords internal
#' @export
#'
base64enc <- function(x, convert = TRUE) .Call(rnng_base64enc, x, convert)

#' @rdname base64enc
#' @keywords internal
#' @export
#'
base64dec <- function(x, convert = TRUE) .Call(rnng_base64dec, x, convert)
Expand Down
1 change: 0 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Web utilities:

- [ncurl](https://shikokuchuo.net/nanonext/articles/nanonext.html#ncurl-async-http-client) - (async) http(s) client
- [stream](https://shikokuchuo.net/nanonext/articles/nanonext.html#stream-websocket-client) - secure websockets client / generic low-level socket interface
- `base64enc()` / `base64dec()`
- `messenger()` - console-based instant messaging with authentication

### Installation
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Web utilities:
(async) http(s) client
- [stream](https://shikokuchuo.net/nanonext/articles/nanonext.html#stream-websocket-client) -
secure websockets client / generic low-level socket interface
- `base64enc()` / `base64dec()`
- `messenger()` - console-based instant messaging with authentication

### Installation
Expand Down
4 changes: 3 additions & 1 deletion man/base64enc.Rd

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

42 changes: 16 additions & 26 deletions vignettes/nanonext.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ The return value from the server request is then retrieved and stored in the Aio

``` r
call_aio(aio)$data |> str()
#> num [1:100000000] 0.92 0.465 1.204 1.823 -0.731 ...
#> num [1:100000000] -0.3059 -0.2953 0.0876 1.7023 0.1703 ...
```

As `call_aio()` is blocking and will wait for completion, an alternative is to query `aio$data` directly. This will return an 'unresolved' logical NA value if the calculation is yet to complete.
Expand Down Expand Up @@ -325,7 +325,7 @@ Additionally, the convenience function `write_cert()` can automatically generate
cert <- write_cert(cn = "127.0.0.1")
str(cert)
#> List of 2
#> $ server: chr [1:2] "-----BEGIN CERTIFICATE-----\nMIIFOTCCAyGgAwIBAgIBATANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQDDAkxMjcu\nMC4wLjExETAPBgNV"| __truncated__ "-----BEGIN RSA PRIVATE KEY-----\nMIIJKAIBAAKCAgEAy6Ns47jxseuAK7o9waiEfsFK4KWZSbuEFxyrbzdxFtjzZll8\nkCnwsGqX7RHC"| __truncated__
#> $ server: chr [1:2] "-----BEGIN CERTIFICATE-----\nMIIFOTCCAyGgAwIBAgIBATANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQDDAkxMjcu\nMC4wLjExETAPBgNV"| __truncated__ "-----BEGIN RSA PRIVATE KEY-----\nMIIJKQIBAAKCAgEAsxMEhD9g5SB4efro+UU0eQ6fahMYkyVDh57ZAqHRp6AQlEKb\nNvGUpwRvTzg5"| __truncated__
#> $ client: chr [1:2] "-----BEGIN CERTIFICATE-----\nMIIFOTCCAyGgAwIBAgIBATANBgkqhkiG9w0BAQsFADA0MRIwEAYDVQQDDAkxMjcu\nMC4wLjExETAPBgNV"| __truncated__ ""

ser <- tls_config(server = cert$server)
Expand Down Expand Up @@ -483,7 +483,7 @@ ncurl("https://postman-echo.com/get")
#> NULL
#>
#> $data
#> [1] "{\n \"args\": {},\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"x-forwarded-port\": \"443\",\n \"host\": \"postman-echo.com\",\n \"x-amzn-trace-id\": \"Root=1-6666d478-77be648e30f5d9e858013ee9\"\n },\n \"url\": \"https://postman-echo.com/get\"\n}"
#> [1] "{\n \"args\": {},\n \"headers\": {\n \"host\": \"postman-echo.com\",\n \"x-forwarded-proto\": \"http\",\n \"x-request-start\": \"t=1718110009.390\",\n \"connection\": \"close\",\n \"x-forwarded-port\": \"443\",\n \"x-amzn-trace-id\": \"Root=1-66684739-5cd547205706a98b0d2f4768\"\n },\n \"url\": \"http://postman-echo.com/get\"\n}"
```

For advanced use, supports additional HTTP methods such as POST or PUT.
Expand All @@ -500,10 +500,10 @@ res

call_aio(res)$headers
#> $date
#> [1] "Mon, 10 Jun 2024 10:24:57 GMT"
#> [1] "Tue, 11 Jun 2024 12:46:50 GMT"

res$data
#> [1] "{\n \"args\": {},\n \"data\": {\n \"key\": \"value\"\n },\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"x-forwarded-proto\": \"https\",\n \"x-forwarded-port\": \"443\",\n \"host\": \"postman-echo.com\",\n \"x-amzn-trace-id\": \"Root=1-6666d478-5bfdbd6979cca57457d79abf\",\n \"content-length\": \"16\",\n \"content-type\": \"application/json\",\n \"authorization\": \"Bearer APIKEY\"\n },\n \"json\": {\n \"key\": \"value\"\n },\n \"url\": \"https://postman-echo.com/post\"\n}"
#> [1] "{\n \"args\": {},\n \"data\": {\n \"key\": \"value\"\n },\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"host\": \"postman-echo.com\",\n \"x-forwarded-proto\": \"http\",\n \"x-request-start\": \"t=1718110010.104\",\n \"connection\": \"close\",\n \"content-length\": \"16\",\n \"x-forwarded-port\": \"443\",\n \"x-amzn-trace-id\": \"Root=1-66684739-7b357da82c076c507c656d00\",\n \"content-type\": \"application/json\",\n \"authorization\": \"Bearer APIKEY\"\n },\n \"json\": {\n \"key\": \"value\"\n },\n \"url\": \"http://postman-echo.com/post\"\n}"
```

In this respect, it may be used as a performant and lightweight method for making REST API requests.
Expand All @@ -527,33 +527,23 @@ transact(sess)
#>
#> $headers
#> $headers$Date
#> [1] "Mon, 10 Jun 2024 10:24:57 GMT"
#> [1] "Tue, 11 Jun 2024 12:46:50 GMT"
#>
#> $headers$`Content-Type`
#> [1] "application/json; charset=utf-8"
#>
#>
#> $data
#> [1] 7b 0a 20 20 22 61 72 67 73 22 3a 20 7b 7d 2c 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 78 2d 66
#> [40] 6f 72 77 61 72 64 65 64 2d 70 72 6f 74 6f 22 3a 20 22 68 74 74 70 73 22 2c 0a 20 20 20 20 22 78 2d 66 6f 72 77 61 72
#> [79] 64 65 64 2d 70 6f 72 74 22 3a 20 22 34 34 33 22 2c 0a 20 20 20 20 22 68 6f 73 74 22 3a 20 22 70 6f 73 74 6d 61 6e 2d
#> [118] 65 63 68 6f 2e 63 6f 6d 22 2c 0a 20 20 20 20 22 78 2d 61 6d 7a 6e 2d 74 72 61 63 65 2d 69 64 22 3a 20 22 52 6f 6f 74
#> [157] 3d 31 2d 36 36 36 36 64 34 37 39 2d 32 64 39 37 38 63 33 37 36 31 37 63 61 32 61 61 37 63 32 65 30 30 62 34 22 2c 0a
#> [196] 20 20 20 20 22 63 6f 6e 74 65 6e 74 2d 74 79 70 65 22 3a 20 22 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 22 2c
#> [235] 0a 20 20 20 20 22 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 22 3a 20 22 42 65 61 72 65 72 20 41 50 49 4b 45 59 22 0a 20
#> [274] 20 7d 2c 0a 20 20 22 75 72 6c 22 3a 20 22 68 74 74 70 73 3a 2f 2f 70 6f 73 74 6d 61 6e 2d 65 63 68 6f 2e 63 6f 6d 2f
#> [313] 67 65 74 22 0a 7d
```

Optimised functions for base64 encoding and decoding from the 'Mbed TLS' library are also exposed as convenience utilities:


``` r
base64enc("hello world!")
#> [1] "aGVsbG8gd29ybGQh"

base64dec(base64enc("hello world!"))
#> [1] "hello world!"
#> [1] 7b 0a 20 20 22 61 72 67 73 22 3a 20 7b 7d 2c 0a 20 20 22 68 65 61 64 65 72 73 22 3a 20 7b 0a 20 20 20 20 22 68 6f 73
#> [40] 74 22 3a 20 22 70 6f 73 74 6d 61 6e 2d 65 63 68 6f 2e 63 6f 6d 22 2c 0a 20 20 20 20 22 78 2d 66 6f 72 77 61 72 64 65
#> [79] 64 2d 70 72 6f 74 6f 22 3a 20 22 68 74 74 70 22 2c 0a 20 20 20 20 22 78 2d 72 65 71 75 65 73 74 2d 73 74 61 72 74 22
#> [118] 3a 20 22 74 3d 31 37 31 38 31 31 30 30 31 30 2e 35 38 35 22 2c 0a 20 20 20 20 22 63 6f 6e 6e 65 63 74 69 6f 6e 22 3a
#> [157] 20 22 63 6c 6f 73 65 22 2c 0a 20 20 20 20 22 78 2d 66 6f 72 77 61 72 64 65 64 2d 70 6f 72 74 22 3a 20 22 34 34 33 22
#> [196] 2c 0a 20 20 20 20 22 78 2d 61 6d 7a 6e 2d 74 72 61 63 65 2d 69 64 22 3a 20 22 52 6f 6f 74 3d 31 2d 36 36 36 38 34 37
#> [235] 33 61 2d 36 62 31 61 65 37 36 36 36 30 61 36 39 62 61 35 30 64 30 64 32 30 38 34 22 2c 0a 20 20 20 20 22 63 6f 6e 74
#> [274] 65 6e 74 2d 74 79 70 65 22 3a 20 22 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 22 2c 0a 20 20 20 20 22 61 75 74
#> [313] 68 6f 72 69 7a 61 74 69 6f 6e 22 3a 20 22 42 65 61 72 65 72 20 41 50 49 4b 45 59 22 0a 20 20 7d 2c 0a 20 20 22 75 72
#> [352] 6c 22 3a 20 22 68 74 74 70 3a 2f 2f 70 6f 73 74 6d 61 6e 2d 65 63 68 6f 2e 63 6f 6d 2f 67 65 74 22 0a 7d
```

[&laquo; Back to ToC](#table-of-contents)
Expand Down
9 changes: 0 additions & 9 deletions vignettes/nanonext.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,6 @@ transact(sess)

```

Optimised functions for base64 encoding and decoding from the 'Mbed TLS' library are also exposed as convenience utilities:

```{r b64}
base64enc("hello world!")

base64dec(base64enc("hello world!"))

```

[&laquo; Back to ToC](#table-of-contents)

### stream: Websocket Client
Expand Down

0 comments on commit c2a08d4

Please sign in to comment.