diff options
author | Richard Levitte <levitte@openssl.org> | 2016-05-18 17:14:19 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2016-05-18 18:30:00 +0200 |
commit | bc776510982b3768761d32c1160e79cb45a561c3 (patch) | |
tree | f8df91513d99c083b1666196b99b3b3b4f8efbc6 /crypto/asn1/a_strex.c | |
parent | 52832e470f5fe8c222249ae5b539aeb3c74cdb25 (diff) |
Make it possible to have RFC2254 escapes with ASN1_STRING_print_ex()
Also adds 'esc_2254' to the possible command line name options
RT#1466
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/asn1/a_strex.c')
-rw-r--r-- | crypto/asn1/a_strex.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index e30743a464..59d51210c3 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -25,6 +25,7 @@ #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ + ASN1_STRFLGS_ESC_2254 | \ ASN1_STRFLGS_ESC_QUOTE | \ ASN1_STRFLGS_ESC_CTRL | \ ASN1_STRFLGS_ESC_MSB) @@ -64,7 +65,8 @@ typedef int char_io (void *arg, const void *buf, int len); static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) { - unsigned char chflgs, chtmp; + unsigned short chflgs; + unsigned char chtmp; char tmphex[HEX_SIZE(long) + 3]; if (c > 0xffffffffL) @@ -101,7 +103,9 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, return -1; return 2; } - if (chflgs & (ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB)) { + if (chflgs & (ASN1_STRFLGS_ESC_CTRL + | ASN1_STRFLGS_ESC_MSB + | ASN1_STRFLGS_ESC_2254)) { BIO_snprintf(tmphex, 11, "\\%02X", chtmp); if (!io_ch(arg, tmphex, 3)) return -1; @@ -131,11 +135,12 @@ static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, */ static int do_buf(unsigned char *buf, int buflen, - int type, unsigned char flags, char *quotes, char_io *io_ch, + int type, unsigned short flags, char *quotes, char_io *io_ch, void *arg) { int i, outlen, len; - unsigned char orflags, *p, *q; + unsigned short orflags; + unsigned char *p, *q; unsigned long c; p = buf; q = buf + buflen; @@ -185,7 +190,7 @@ static int do_buf(unsigned char *buf, int buflen, * character will never be escaped on first and last. */ len = - do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), + do_esc_char(utfbuf[i], (unsigned short)(flags | orflags), quotes, io_ch, arg); if (len < 0) return -1; @@ -193,7 +198,7 @@ static int do_buf(unsigned char *buf, int buflen, } } else { len = - do_esc_char(c, (unsigned char)(flags | orflags), quotes, + do_esc_char(c, (unsigned short)(flags | orflags), quotes, io_ch, arg); if (len < 0) return -1; @@ -295,10 +300,10 @@ static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, int outlen, len; int type; char quotes; - unsigned char flags; + unsigned short flags; quotes = 0; /* Keep a copy of escape flags */ - flags = (unsigned char)(lflags & ESC_FLAGS); + flags = (unsigned short)(lflags & ESC_FLAGS); type = str->type; |