Skip to content

Commit

Permalink
update string accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jul 1, 2024
1 parent 4d912b4 commit 2d1630a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# secretbase 1.0.0.9000 (development)

* Emits an improved error message if argument 'convert' is not of logical type.
* Improved error message if argument 'convert' is not of logical type.

# secretbase 1.0.0

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/secretbase?color=17411d)](https://CRAN.R-project.org/package=secretbase)
[![R-multiverse status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse)](https://community.r-multiverse.org/secretbase)
[![secretbase status badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e4723a)](https://shikokuchuo.r-universe.dev/secretbase)
[![secretbase status badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e67f53)](https://shikokuchuo.r-universe.dev/secretbase)
[![R-CMD-check](https://github.com/shikokuchuo/secretbase/workflows/R-CMD-check/badge.svg)](https://github.com/shikokuchuo/secretbase/actions)
[![codecov](https://codecov.io/gh/shikokuchuo/secretbase/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/secretbase)
[![DOI](https://zenodo.org/badge/745691432.svg)](https://zenodo.org/doi/10.5281/zenodo.10553139)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ status](https://www.r-pkg.org/badges/version/secretbase?color=17411d)](https://C
[![R-multiverse
status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse)](https://community.r-multiverse.org/secretbase)
[![secretbase status
badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e4723a)](https://shikokuchuo.r-universe.dev/secretbase)
badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e67f53)](https://shikokuchuo.r-universe.dev/secretbase)
[![R-CMD-check](https://github.com/shikokuchuo/secretbase/workflows/R-CMD-check/badge.svg)](https://github.com/shikokuchuo/secretbase/actions)
[![codecov](https://codecov.io/gh/shikokuchuo/secretbase/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/secretbase)
[![DOI](https://zenodo.org/badge/745691432.svg)](https://zenodo.org/doi/10.5281/zenodo.10553139)
Expand Down
6 changes: 3 additions & 3 deletions src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static nano_buf nano_any_buf(const SEXP x) {
switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
const char *s = CHAR(STRING_ELT(x, 0));
const char *s = SB_STRING(x);
NANO_INIT(&buf, (unsigned char *) s, strlen(s));
goto resume;
}
Expand Down Expand Up @@ -396,8 +396,8 @@ SEXP secretbase_base64dec(SEXP x, SEXP convert) {

switch (TYPEOF(x)) {
case STRSXP:
inbuf = (unsigned char *) CHAR(STRING_ELT(x, 0));
inlen = XLENGTH(STRING_ELT(x, 0));
inbuf = (unsigned char *) SB_STRING(x);
inlen = XLENGTH(*((const SEXP *) DATAPTR_RO(x)));
break;
case RAWSXP:
inbuf = RAW(x);
Expand Down
4 changes: 2 additions & 2 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) {
static void hash_file(mbedtls_sha3_context *ctx, const SEXP x) {

SB_CHK_STR(x);
const char *file = R_ExpandFileName(CHAR(STRING_ELT(x, 0)));
const char *file = R_ExpandFileName(SB_STRING(x));
unsigned char buf[SB_BUF_SIZE];
FILE *f;
size_t cur;
Expand All @@ -277,7 +277,7 @@ static void hash_object(mbedtls_sha3_context *ctx, const SEXP x) {
switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
const char *s = CHAR(STRING_ELT(x, 0));
const char *s = SB_STRING(x);
mbedtls_sha3_update(ctx, (uint8_t *) s, strlen(s));
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <R_ext/Visibility.h>

#define SB_DATAPTR(x) (void *) DATAPTR_RO(x)
#define SB_STRING(x) CHAR(*((const SEXP *) DATAPTR_RO(x)))
#define SB_LOGICAL(v, x) if (TYPEOF(x) != LGLSXP) \
Rf_error("'convert' must be a logical value"); else v = *(int *) DATAPTR_RO(x)
#define SB_CHK_STR(x) if (TYPEOF(x) != STRSXP) \
Expand Down
6 changes: 3 additions & 3 deletions src/secret2.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) {
static void hash_file(mbedtls_sha256_context *ctx, const SEXP x) {

SB_CHK_STR(x);
const char *file = R_ExpandFileName(CHAR(STRING_ELT(x, 0)));
const char *file = R_ExpandFileName(SB_STRING(x));
unsigned char buf[SB_BUF_SIZE];
FILE *f;
size_t cur;
Expand All @@ -412,7 +412,7 @@ static void hash_object(mbedtls_sha256_context *ctx, const SEXP x) {
switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
const char *s = CHAR(STRING_ELT(x, 0));
const char *s = SB_STRING(x);
mbedtls_sha256_update(ctx, (uint8_t *) s, strlen(s));
return;
}
Expand Down Expand Up @@ -470,7 +470,7 @@ static SEXP secretbase_sha256_impl(const SEXP x, const SEXP key, const SEXP conv

switch (TYPEOF(key)) {
case STRSXP:
data = (unsigned char *) (XLENGTH(key) ? CHAR(STRING_ELT(key, 0)) : "");
data = (unsigned char *) (XLENGTH(key) ? SB_STRING(key) : "");
klen = strlen((char *) data);
break;
case RAWSXP:
Expand Down
6 changes: 3 additions & 3 deletions src/secret3.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) {
static void hash_file(CSipHash *ctx, const SEXP x) {

SB_CHK_STR(x);
const char *file = R_ExpandFileName(CHAR(STRING_ELT(x, 0)));
const char *file = R_ExpandFileName(SB_STRING(x));
unsigned char buf[SB_BUF_SIZE];
FILE *f;
size_t cur;
Expand All @@ -217,7 +217,7 @@ static void hash_object(CSipHash *ctx, const SEXP x) {
switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
const char *s = CHAR(STRING_ELT(x, 0));
const char *s = SB_STRING(x);
c_siphash_append(ctx, (uint8_t *) s, strlen(s));
return;
}
Expand Down Expand Up @@ -266,7 +266,7 @@ static SEXP secretbase_siphash_impl(const SEXP x, const SEXP key, const SEXP con
size_t klen;
switch (TYPEOF(key)) {
case STRSXP:
data = (unsigned char *) (XLENGTH(key) ? CHAR(STRING_ELT(key, 0)) : "");
data = (unsigned char *) (XLENGTH(key) ? SB_STRING(key) : "");
klen = strlen((char *) data);
break;
case RAWSXP:
Expand Down

0 comments on commit 2d1630a

Please sign in to comment.