Use uint32_t for unicode code points.
The newer clang-cl is unhappy about the tautological comparison on Windows, but the comparison itself is unnecessary anyway, since the values will never exceed uint32_t. I think the reason it's not firing elsewhere is because on other 64-bit platforms, it is not tautological because long is 64-bit. On other 32-bit platforms, I'm not sure we actually have a standalone trunk clang builder right now. Update-Note: UTF8_getc and UTF8_putc were unexported. No one appears to be calling them. (We're a crypto library, not a Unicode library.) Change-Id: I0949ddea3131dca5f55d04e672c3ccf2915c41ab Reviewed-on: https://boringssl-review.googlesource.com/23844 Commit-Queue: Adam Langley <agl@google.com> Reviewed-by: Adam Langley <agl@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
296a61d600
commit
2b63addf6a
@ -61,17 +61,19 @@
|
|||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/mem.h>
|
#include <openssl/mem.h>
|
||||||
|
|
||||||
|
#include "asn1_locl.h"
|
||||||
|
|
||||||
static int traverse_string(const unsigned char *p, int len, int inform,
|
static int traverse_string(const unsigned char *p, int len, int inform,
|
||||||
int (*rfunc) (unsigned long value, void *in),
|
int (*rfunc) (uint32_t value, void *in),
|
||||||
void *arg);
|
void *arg);
|
||||||
static int in_utf8(unsigned long value, void *arg);
|
static int in_utf8(uint32_t value, void *arg);
|
||||||
static int out_utf8(unsigned long value, void *arg);
|
static int out_utf8(uint32_t value, void *arg);
|
||||||
static int type_str(unsigned long value, void *arg);
|
static int type_str(uint32_t value, void *arg);
|
||||||
static int cpy_asc(unsigned long value, void *arg);
|
static int cpy_asc(uint32_t value, void *arg);
|
||||||
static int cpy_bmp(unsigned long value, void *arg);
|
static int cpy_bmp(uint32_t value, void *arg);
|
||||||
static int cpy_univ(unsigned long value, void *arg);
|
static int cpy_univ(uint32_t value, void *arg);
|
||||||
static int cpy_utf8(unsigned long value, void *arg);
|
static int cpy_utf8(uint32_t value, void *arg);
|
||||||
static int is_printable(unsigned long value);
|
static int is_printable(uint32_t value);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These functions take a string in UTF8, ASCII or multibyte form and a mask
|
* These functions take a string in UTF8, ASCII or multibyte form and a mask
|
||||||
@ -100,7 +102,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
|||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
int nchar;
|
int nchar;
|
||||||
char strbuf[32];
|
char strbuf[32];
|
||||||
int (*cpyfunc) (unsigned long, void *) = NULL;
|
int (*cpyfunc) (uint32_t, void *) = NULL;
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
len = strlen((const char *)in);
|
len = strlen((const char *)in);
|
||||||
if (!mask)
|
if (!mask)
|
||||||
@ -253,10 +255,10 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int traverse_string(const unsigned char *p, int len, int inform,
|
static int traverse_string(const unsigned char *p, int len, int inform,
|
||||||
int (*rfunc) (unsigned long value, void *in),
|
int (*rfunc) (uint32_t value, void *in),
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
unsigned long value;
|
uint32_t value;
|
||||||
int ret;
|
int ret;
|
||||||
while (len) {
|
while (len) {
|
||||||
if (inform == MBSTRING_ASC) {
|
if (inform == MBSTRING_ASC) {
|
||||||
@ -267,8 +269,8 @@ static int traverse_string(const unsigned char *p, int len, int inform,
|
|||||||
value |= *p++;
|
value |= *p++;
|
||||||
len -= 2;
|
len -= 2;
|
||||||
} else if (inform == MBSTRING_UNIV) {
|
} else if (inform == MBSTRING_UNIV) {
|
||||||
value = ((unsigned long)*p++) << 24;
|
value = ((uint32_t)*p++) << 24;
|
||||||
value |= ((unsigned long)*p++) << 16;
|
value |= ((uint32_t)*p++) << 16;
|
||||||
value |= *p++ << 8;
|
value |= *p++ << 8;
|
||||||
value |= *p++;
|
value |= *p++;
|
||||||
len -= 4;
|
len -= 4;
|
||||||
@ -292,7 +294,7 @@ static int traverse_string(const unsigned char *p, int len, int inform,
|
|||||||
|
|
||||||
/* Just count number of characters */
|
/* Just count number of characters */
|
||||||
|
|
||||||
static int in_utf8(unsigned long value, void *arg)
|
static int in_utf8(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
int *nchar;
|
int *nchar;
|
||||||
nchar = arg;
|
nchar = arg;
|
||||||
@ -302,7 +304,7 @@ static int in_utf8(unsigned long value, void *arg)
|
|||||||
|
|
||||||
/* Determine size of output as a UTF8 String */
|
/* Determine size of output as a UTF8 String */
|
||||||
|
|
||||||
static int out_utf8(unsigned long value, void *arg)
|
static int out_utf8(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
int *outlen;
|
int *outlen;
|
||||||
outlen = arg;
|
outlen = arg;
|
||||||
@ -315,7 +317,7 @@ static int out_utf8(unsigned long value, void *arg)
|
|||||||
* "mask".
|
* "mask".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int type_str(unsigned long value, void *arg)
|
static int type_str(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
unsigned long types;
|
unsigned long types;
|
||||||
types = *((unsigned long *)arg);
|
types = *((unsigned long *)arg);
|
||||||
@ -335,7 +337,7 @@ static int type_str(unsigned long value, void *arg)
|
|||||||
|
|
||||||
/* Copy one byte per character ASCII like strings */
|
/* Copy one byte per character ASCII like strings */
|
||||||
|
|
||||||
static int cpy_asc(unsigned long value, void *arg)
|
static int cpy_asc(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
unsigned char **p, *q;
|
unsigned char **p, *q;
|
||||||
p = arg;
|
p = arg;
|
||||||
@ -347,7 +349,7 @@ static int cpy_asc(unsigned long value, void *arg)
|
|||||||
|
|
||||||
/* Copy two byte per character BMPStrings */
|
/* Copy two byte per character BMPStrings */
|
||||||
|
|
||||||
static int cpy_bmp(unsigned long value, void *arg)
|
static int cpy_bmp(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
unsigned char **p, *q;
|
unsigned char **p, *q;
|
||||||
p = arg;
|
p = arg;
|
||||||
@ -360,7 +362,7 @@ static int cpy_bmp(unsigned long value, void *arg)
|
|||||||
|
|
||||||
/* Copy four byte per character UniversalStrings */
|
/* Copy four byte per character UniversalStrings */
|
||||||
|
|
||||||
static int cpy_univ(unsigned long value, void *arg)
|
static int cpy_univ(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
unsigned char **p, *q;
|
unsigned char **p, *q;
|
||||||
p = arg;
|
p = arg;
|
||||||
@ -375,7 +377,7 @@ static int cpy_univ(unsigned long value, void *arg)
|
|||||||
|
|
||||||
/* Copy to a UTF8String */
|
/* Copy to a UTF8String */
|
||||||
|
|
||||||
static int cpy_utf8(unsigned long value, void *arg)
|
static int cpy_utf8(uint32_t value, void *arg)
|
||||||
{
|
{
|
||||||
unsigned char **p;
|
unsigned char **p;
|
||||||
int ret;
|
int ret;
|
||||||
@ -387,7 +389,7 @@ static int cpy_utf8(unsigned long value, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return 1 if the character is permitted in a PrintableString */
|
/* Return 1 if the character is permitted in a PrintableString */
|
||||||
static int is_printable(unsigned long value)
|
static int is_printable(uint32_t value)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
if (value > 0x7f)
|
if (value > 0x7f)
|
||||||
|
@ -59,6 +59,8 @@
|
|||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/mem.h>
|
#include <openssl/mem.h>
|
||||||
|
|
||||||
|
#include "asn1_locl.h"
|
||||||
|
|
||||||
/* UTF8 utilities */
|
/* UTF8 utilities */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -70,10 +72,10 @@
|
|||||||
* incorrectly (not minimal length).
|
* incorrectly (not minimal length).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
int UTF8_getc(const unsigned char *str, int len, uint32_t *val)
|
||||||
{
|
{
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
unsigned long value;
|
uint32_t value;
|
||||||
int ret;
|
int ret;
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -112,7 +114,7 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
|||||||
|| ((p[2] & 0xc0) != 0x80)
|
|| ((p[2] & 0xc0) != 0x80)
|
||||||
|| ((p[3] & 0xc0) != 0x80))
|
|| ((p[3] & 0xc0) != 0x80))
|
||||||
return -3;
|
return -3;
|
||||||
value = ((unsigned long)(*p++ & 0x7)) << 18;
|
value = ((uint32_t)(*p++ & 0x7)) << 18;
|
||||||
value |= (*p++ & 0x3f) << 12;
|
value |= (*p++ & 0x3f) << 12;
|
||||||
value |= (*p++ & 0x3f) << 6;
|
value |= (*p++ & 0x3f) << 6;
|
||||||
value |= *p++ & 0x3f;
|
value |= *p++ & 0x3f;
|
||||||
@ -127,9 +129,9 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
|||||||
|| ((p[3] & 0xc0) != 0x80)
|
|| ((p[3] & 0xc0) != 0x80)
|
||||||
|| ((p[4] & 0xc0) != 0x80))
|
|| ((p[4] & 0xc0) != 0x80))
|
||||||
return -3;
|
return -3;
|
||||||
value = ((unsigned long)(*p++ & 0x3)) << 24;
|
value = ((uint32_t)(*p++ & 0x3)) << 24;
|
||||||
value |= ((unsigned long)(*p++ & 0x3f)) << 18;
|
value |= ((uint32_t)(*p++ & 0x3f)) << 18;
|
||||||
value |= ((unsigned long)(*p++ & 0x3f)) << 12;
|
value |= ((uint32_t)(*p++ & 0x3f)) << 12;
|
||||||
value |= (*p++ & 0x3f) << 6;
|
value |= (*p++ & 0x3f) << 6;
|
||||||
value |= *p++ & 0x3f;
|
value |= *p++ & 0x3f;
|
||||||
if (value < 0x200000)
|
if (value < 0x200000)
|
||||||
@ -144,10 +146,10 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
|||||||
|| ((p[4] & 0xc0) != 0x80)
|
|| ((p[4] & 0xc0) != 0x80)
|
||||||
|| ((p[5] & 0xc0) != 0x80))
|
|| ((p[5] & 0xc0) != 0x80))
|
||||||
return -3;
|
return -3;
|
||||||
value = ((unsigned long)(*p++ & 0x1)) << 30;
|
value = ((uint32_t)(*p++ & 0x1)) << 30;
|
||||||
value |= ((unsigned long)(*p++ & 0x3f)) << 24;
|
value |= ((uint32_t)(*p++ & 0x3f)) << 24;
|
||||||
value |= ((unsigned long)(*p++ & 0x3f)) << 18;
|
value |= ((uint32_t)(*p++ & 0x3f)) << 18;
|
||||||
value |= ((unsigned long)(*p++ & 0x3f)) << 12;
|
value |= ((uint32_t)(*p++ & 0x3f)) << 12;
|
||||||
value |= (*p++ & 0x3f) << 6;
|
value |= (*p++ & 0x3f) << 6;
|
||||||
value |= *p++ & 0x3f;
|
value |= *p++ & 0x3f;
|
||||||
if (value < 0x4000000)
|
if (value < 0x4000000)
|
||||||
@ -167,7 +169,7 @@ int UTF8_getc(const unsigned char *str, int len, unsigned long *val)
|
|||||||
* most 6 characters.
|
* most 6 characters.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int UTF8_putc(unsigned char *str, int len, unsigned long value)
|
int UTF8_putc(unsigned char *str, int len, uint32_t value)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
len = 6; /* Maximum we will need */
|
len = 6; /* Maximum we will need */
|
||||||
|
@ -93,6 +93,9 @@ int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
|
|||||||
void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||||
int combine);
|
int combine);
|
||||||
|
|
||||||
|
int UTF8_getc(const unsigned char *str, int len, uint32_t *val);
|
||||||
|
int UTF8_putc(unsigned char *str, int len, uint32_t value);
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
} /* extern C */
|
} /* extern C */
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
#include <openssl/x509.h>
|
#include <openssl/x509.h>
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <openssl/asn1.h>
|
#include <openssl/asn1.h>
|
||||||
@ -63,6 +64,7 @@
|
|||||||
#include <openssl/obj.h>
|
#include <openssl/obj.h>
|
||||||
|
|
||||||
#include "charmap.h"
|
#include "charmap.h"
|
||||||
|
#include "../asn1/asn1_locl.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ASN1_STRING_print_ex() and X509_NAME_print_ex(). Enhanced string and name
|
* ASN1_STRING_print_ex() and X509_NAME_print_ex(). Enhanced string and name
|
||||||
@ -105,22 +107,20 @@ typedef int char_io (void *arg, const void *buf, int len);
|
|||||||
|
|
||||||
#define HEX_SIZE(type) (sizeof(type)*2)
|
#define HEX_SIZE(type) (sizeof(type)*2)
|
||||||
|
|
||||||
static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes,
|
static int do_esc_char(uint32_t c, unsigned char flags, char *do_quotes,
|
||||||
char_io *io_ch, void *arg)
|
char_io *io_ch, void *arg)
|
||||||
{
|
{
|
||||||
unsigned char chflgs, chtmp;
|
unsigned char chflgs, chtmp;
|
||||||
char tmphex[HEX_SIZE(long) + 3];
|
char tmphex[HEX_SIZE(uint32_t) + 3];
|
||||||
|
|
||||||
if (c > 0xffffffffL)
|
|
||||||
return -1;
|
|
||||||
if (c > 0xffff) {
|
if (c > 0xffff) {
|
||||||
BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c);
|
BIO_snprintf(tmphex, sizeof tmphex, "\\W%08" PRIX32, c);
|
||||||
if (!io_ch(arg, tmphex, 10))
|
if (!io_ch(arg, tmphex, 10))
|
||||||
return -1;
|
return -1;
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
if (c > 0xff) {
|
if (c > 0xff) {
|
||||||
BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c);
|
BIO_snprintf(tmphex, sizeof tmphex, "\\U%04" PRIX32, c);
|
||||||
if (!io_ch(arg, tmphex, 6))
|
if (!io_ch(arg, tmphex, 6))
|
||||||
return -1;
|
return -1;
|
||||||
return 6;
|
return 6;
|
||||||
@ -180,7 +180,7 @@ static int do_buf(unsigned char *buf, int buflen,
|
|||||||
{
|
{
|
||||||
int i, outlen, len;
|
int i, outlen, len;
|
||||||
unsigned char orflags, *p, *q;
|
unsigned char orflags, *p, *q;
|
||||||
unsigned long c;
|
uint32_t c;
|
||||||
p = buf;
|
p = buf;
|
||||||
q = buf + buflen;
|
q = buf + buflen;
|
||||||
outlen = 0;
|
outlen = 0;
|
||||||
@ -191,14 +191,14 @@ static int do_buf(unsigned char *buf, int buflen,
|
|||||||
orflags = 0;
|
orflags = 0;
|
||||||
switch (type & BUF_TYPE_WIDTH_MASK) {
|
switch (type & BUF_TYPE_WIDTH_MASK) {
|
||||||
case 4:
|
case 4:
|
||||||
c = ((unsigned long)*p++) << 24;
|
c = ((uint32_t)*p++) << 24;
|
||||||
c |= ((unsigned long)*p++) << 16;
|
c |= ((uint32_t)*p++) << 16;
|
||||||
c |= ((unsigned long)*p++) << 8;
|
c |= ((uint32_t)*p++) << 8;
|
||||||
c |= *p++;
|
c |= *p++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
c = ((unsigned long)*p++) << 8;
|
c = ((uint32_t)*p++) << 8;
|
||||||
c |= *p++;
|
c |= *p++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -708,9 +708,6 @@ DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
|
|||||||
DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
|
DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
|
||||||
DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
|
DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
|
||||||
|
|
||||||
OPENSSL_EXPORT int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
|
|
||||||
OPENSSL_EXPORT int UTF8_putc(unsigned char *str, int len, unsigned long value);
|
|
||||||
|
|
||||||
DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
|
DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
|
||||||
|
|
||||||
DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
|
DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
|
||||||
|
Loading…
Reference in New Issue
Block a user