mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-11-15 02:05:40 +00:00
Avoid any assumptions about the signedness of char.
This commit is contained in:
parent
d03b4c1958
commit
938dcaa450
2 changed files with 10 additions and 8 deletions
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include <cryb/rfc4648.h>
|
||||
|
||||
static const char b32dec[256] = {
|
||||
static const uint8_t b32dec[256] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
|
@ -87,8 +87,9 @@ static const char b32dec[256] = {
|
|||
* excess data, but returns the total amount.
|
||||
*/
|
||||
int
|
||||
base32_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen)
|
||||
base32_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
|
||||
{
|
||||
const uint8_t *in = (const uint8_t *)cin;
|
||||
size_t len;
|
||||
int bits, shift, padding;
|
||||
|
||||
|
@ -97,10 +98,10 @@ base32_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen)
|
|||
(padding && *in == '=')) {
|
||||
/* consume */
|
||||
continue;
|
||||
} else if (!padding && b32dec[(uint8_t)*in] >= 0) {
|
||||
} else if (!padding && b32dec[*in] != 0xff) {
|
||||
/* shift into accumulator */
|
||||
shift += 5;
|
||||
bits = bits << 5 | b32dec[(uint8_t)*in];
|
||||
bits = bits << 5 | b32dec[*in];
|
||||
} else if (!padding && *in == '=' &&
|
||||
(shift == 1 || shift == 2 || shift == 3 || shift == 4)) {
|
||||
/* final byte */
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include <cryb/rfc4648.h>
|
||||
|
||||
static const char b64dec[256] = {
|
||||
static const uint8_t b64dec[256] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
|
@ -87,8 +87,9 @@ static const char b64dec[256] = {
|
|||
* excess data, but returns the total amount.
|
||||
*/
|
||||
int
|
||||
base64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen)
|
||||
base64_decode(const char *cin, size_t ilen, uint8_t *out, size_t *olen)
|
||||
{
|
||||
const uint8_t *in = (const uint8_t *)cin;
|
||||
size_t len;
|
||||
int bits, shift, padding;
|
||||
|
||||
|
@ -97,10 +98,10 @@ base64_decode(const char *in, size_t ilen, uint8_t *out, size_t *olen)
|
|||
(padding && *in == '=')) {
|
||||
/* consume */
|
||||
continue;
|
||||
} else if (!padding && b64dec[(uint8_t)*in] >= 0) {
|
||||
} else if (!padding && b64dec[*in] != 0xff) {
|
||||
/* shift into accumulator */
|
||||
shift += 6;
|
||||
bits = bits << 6 | b64dec[(uint8_t)*in];
|
||||
bits = bits << 6 | b64dec[*in];
|
||||
} else if (!padding && *in == '=' &&
|
||||
(shift == 2 || shift == 4)) {
|
||||
/* final byte */
|
||||
|
|
Loading…
Reference in a new issue