Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead H5FD_s3comms_percent_encode_char() #4591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 0 additions & 118 deletions src/H5FDs3comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,124 +2110,6 @@ H5FD_s3comms_parse_url(const char *str, parsed_url_t **_purl)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_s3comms_parse_url() */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_percent_encode_char()
*
* Purpose:
*
* "Percent-encode" utf-8 character `c`, e.g.,
* '$' -> "%24"
* '¢' -> "%C2%A2"
*
* `c` cannot be null.
*
* Does not (currently) accept multi-byte characters...
* limit to (?) u+00ff, well below upper bound for two-byte utf-8 encoding
* (u+0080..u+07ff).
*
* Writes output to `repr`.
* `repr` cannot be null.
* Assumes adequate space i `repr`...
* >>> char[4] or [7] for most characters,
* >>> [13] as theoretical maximum.
*
* Representation `repr` is null-terminated.
*
* Stores length of representation (without null terminator) at pointer
* `repr_len`.
*
* Return : SUCCEED/FAIL
*
* - SUCCESS: `SUCCEED`
* - percent-encoded representation written to `repr`
* - 'repr' is null-terminated
* - FAILURE: `FAIL`
* - `c` or `repr` was NULL
*
*----------------------------------------------------------------------------
*/
herr_t
H5FD_s3comms_percent_encode_char(char *repr, const unsigned char c, size_t *repr_len)
{
unsigned int i = 0;
int chars_written = 0;
herr_t ret_value = SUCCEED;

FUNC_ENTER_NOAPI_NOINIT

if (repr == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no destination `repr`.");

if (c <= (unsigned char)0x7f) {
/* character represented in a single "byte"
* and single percent-code
*/
*repr_len = 3;
chars_written = snprintf(repr, 4, "%%%02X", c);
if (chars_written < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
} /* end if single-byte unicode char */
else {
/* multi-byte, multi-percent representation
*/
unsigned int acc = 0; /* byte accumulator */
unsigned int k = 0; /* uint character representation */
unsigned int stack_size = 0;
unsigned char stack[4] = {0, 0, 0, 0};

stack_size = 0;
k = (unsigned int)c;
*repr_len = 0;
do {
/* push number onto stack in six-bit slices
*/
acc = k;
acc >>= 6; /* cull least */
acc <<= 6; /* six bits */
stack[stack_size++] = (unsigned char)(k - acc);
k = acc >> 6;
} while (k > 0);

/* `stack` now has two to four six-bit 'numbers' to be put into
* UTF-8 byte fields.
*/

/****************
* leading byte *
****************/

/* prepend 11[1[1]]0 to first byte */
/* 110xxxxx, 1110xxxx, or 11110xxx */
acc = 0xC0; /* 0x11000000 */
acc += (stack_size > 2) ? 0x20 : 0; /* 0x00100000 */
acc += (stack_size > 3) ? 0x10 : 0; /* 0x00010000 */
stack_size--;
chars_written = snprintf(repr, 4, "%%%02X", (unsigned char)(acc + stack[stack_size]));
if (chars_written < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
*repr_len += 3;

/************************
* continuation byte(s) *
************************/

/* 10xxxxxx */
for (i = 0; i < stack_size; i++) {
chars_written =
snprintf(&repr[i * 3 + 3], 4, "%%%02X", (unsigned char)(0x80 + stack[stack_size - 1 - i]));
if (chars_written < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "cannot write char %c", c);
*repr_len += 3;
} /* end for each continuation byte */
} /* end else (multi-byte) */

*(repr + *repr_len) = '\0';

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5FD_s3comms_percent_encode_char */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_signing_key()
Expand Down
2 changes: 0 additions & 2 deletions src/H5FDs3comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ H5_DLL herr_t H5FD_s3comms_load_aws_profile(const char *name, char *key_id_out,

H5_DLL herr_t H5FD_s3comms_parse_url(const char *str, parsed_url_t **purl);

H5_DLL herr_t H5FD_s3comms_percent_encode_char(char *repr, const unsigned char c, size_t *repr_len);

H5_DLL herr_t H5FD_s3comms_signing_key(unsigned char *md, const char *secret, const char *region,
const char *iso8601now);

Expand Down
72 changes: 0 additions & 72 deletions test/s3comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,77 +1546,6 @@ test_parse_url(void)

} /* end test_parse_url() */

/*---------------------------------------------------------------------------
*
* Function: test_percent_encode_char()
*
* Purpose:
*
* Define and verify behavior of `H5FD_s3comms_percent_encode_char()`
*
* Return:
*
* Success: 0
* Failure: -1
*
*---------------------------------------------------------------------------
*/
static herr_t
test_percent_encode_char(void)
{
/*************************
* test-local structures *
*************************/

struct testcase {
const char c;
const char *exp;
size_t exp_len;
};

/************************
* test-local variables *
************************/

struct testcase cases[] = {
{'$', "%24", 3}, /* u+0024 dollar sign */
{' ', "%20", 3}, /* u+0020 space */
{'^', "%5E", 3}, /* u+0094 carat */
{'/', "%2F", 3}, /* u+002f solidus (forward slash) */
/* {??, "%C5%8C", 6},*/ /* u+014c Latin Capital Letter O with Macron */
/* Not included because it is multibyte "wide" character that poses */
/* issues both in the underlying function and in being written in */
/* this file. */
/* {'¢', "%C2%A2", 6}, */ /* u+00a2 cent sign */
/* above works, but complains about wide character overflow */
/* Elide for now, until it is determined (a) unnecessary or */
/* (b) requiring signature change to accommodate wide characters */
{'\0', "%00", 3}, /* u+0000 null */
};
char dest[13];
size_t dest_len = 0;
int i = 0;
int n_cases = 5;

TESTING("percent encode characters");

for (i = 0; i < n_cases; i++) {
JSVERIFY(SUCCEED, H5FD_s3comms_percent_encode_char(dest, (const unsigned char)cases[i].c, &dest_len),
NULL)
JSVERIFY(cases[i].exp_len, dest_len, NULL)
JSVERIFY(0, strncmp(dest, cases[i].exp, dest_len), NULL)
JSVERIFY_STR(cases[i].exp, dest, NULL)
}

JSVERIFY(FAIL, H5FD_s3comms_percent_encode_char(NULL, (const unsigned char)'^', &dest_len), NULL)

PASSED();
return 0;

error:
return -1;
} /* end test_percent_encode_char() */

/*---------------------------------------------------------------------------
* Function: test_s3r_get_filesize()
*---------------------------------------------------------------------------
Expand Down Expand Up @@ -2237,7 +2166,6 @@ main(void)

/* tests ordered roughly by dependence */
nerrors += test_macro_format_credential() < 0 ? 1 : 0;
nerrors += test_percent_encode_char() < 0 ? 1 : 0;
nerrors += test_bytes_to_hex() < 0 ? 1 : 0;
nerrors += test_HMAC_SHA256() < 0 ? 1 : 0;
nerrors += test_signing_key() < 0 ? 1 : 0;
Expand Down
Loading