summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_strex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_strex.c')
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index c2dbb6f9a5..a07122ba47 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -58,12 +58,12 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/crypto.h> 61#include <openssl/crypto.h>
63#include <openssl/x509.h> 62#include <openssl/x509.h>
64#include <openssl/asn1.h> 63#include <openssl/asn1.h>
65 64
66#include "charmap.h" 65#include "charmap.h"
66#include "cryptlib.h"
67 67
68/* ASN1_STRING_print_ex() and X509_NAME_print_ex(). 68/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
69 * Enhanced string and name printing routines handling 69 * Enhanced string and name printing routines handling
@@ -170,7 +170,7 @@ static int do_buf(unsigned char *buf, int buflen,
170 q = buf + buflen; 170 q = buf + buflen;
171 outlen = 0; 171 outlen = 0;
172 while(p != q) { 172 while(p != q) {
173 if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; 173 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
174 else orflags = 0; 174 else orflags = 0;
175 switch(type & BUF_TYPE_WIDTH_MASK) { 175 switch(type & BUF_TYPE_WIDTH_MASK) {
176 case 4: 176 case 4:
@@ -194,10 +194,8 @@ static int do_buf(unsigned char *buf, int buflen,
194 if(i < 0) return -1; /* Invalid UTF8String */ 194 if(i < 0) return -1; /* Invalid UTF8String */
195 p += i; 195 p += i;
196 break; 196 break;
197 default:
198 return -1; /* invalid width */
199 } 197 }
200 if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; 198 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
201 if(type & BUF_TYPE_CONVUTF8) { 199 if(type & BUF_TYPE_CONVUTF8) {
202 unsigned char utfbuf[6]; 200 unsigned char utfbuf[6];
203 int utflen; 201 int utflen;
@@ -225,7 +223,7 @@ static int do_buf(unsigned char *buf, int buflen,
225 223
226static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) 224static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
227{ 225{
228 static const char hexdig[] = "0123456789ABCDEF"; 226 const static char hexdig[] = "0123456789ABCDEF";
229 unsigned char *p, *q; 227 unsigned char *p, *q;
230 char hextmp[2]; 228 char hextmp[2];
231 if(arg) { 229 if(arg) {
@@ -281,7 +279,7 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING
281 * otherwise it is the number of bytes per character 279 * otherwise it is the number of bytes per character
282 */ 280 */
283 281
284static const signed char tag2nbyte[] = { 282const static signed char tag2nbyte[] = {
285 -1, -1, -1, -1, -1, /* 0-4 */ 283 -1, -1, -1, -1, -1, /* 0-4 */
286 -1, -1, -1, -1, -1, /* 5-9 */ 284 -1, -1, -1, -1, -1, /* 5-9 */
287 -1, -1, 0, -1, /* 10-13 */ 285 -1, -1, 0, -1, /* 10-13 */
@@ -358,13 +356,12 @@ static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STR
358 } 356 }
359 357
360 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL); 358 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
361 if(len < 0) return -1; 359 if(outlen < 0) return -1;
362 outlen += len; 360 outlen += len;
363 if(quotes) outlen += 2; 361 if(quotes) outlen += 2;
364 if(!arg) return outlen; 362 if(!arg) return outlen;
365 if(quotes && !io_ch(arg, "\"", 1)) return -1; 363 if(quotes && !io_ch(arg, "\"", 1)) return -1;
366 if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) 364 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
367 return -1;
368 if(quotes && !io_ch(arg, "\"", 1)) return -1; 365 if(quotes && !io_ch(arg, "\"", 1)) return -1;
369 return outlen; 366 return outlen;
370} 367}
@@ -516,7 +513,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
516 return do_name_ex(send_bio_chars, out, nm, indent, flags); 513 return do_name_ex(send_bio_chars, out, nm, indent, flags);
517} 514}
518 515
519#ifndef OPENSSL_NO_FP_API 516
520int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) 517int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
521{ 518{
522 if(flags == XN_FLAG_COMPAT) 519 if(flags == XN_FLAG_COMPAT)
@@ -531,19 +528,17 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long fla
531 } 528 }
532 return do_name_ex(send_fp_chars, fp, nm, indent, flags); 529 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
533} 530}
534#endif
535 531
536int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) 532int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
537{ 533{
538 return do_print_ex(send_bio_chars, out, flags, str); 534 return do_print_ex(send_bio_chars, out, flags, str);
539} 535}
540 536
541#ifndef OPENSSL_NO_FP_API 537
542int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) 538int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
543{ 539{
544 return do_print_ex(send_fp_chars, fp, flags, str); 540 return do_print_ex(send_fp_chars, fp, flags, str);
545} 541}
546#endif
547 542
548/* Utility function: convert any string type to UTF8, returns number of bytes 543/* Utility function: convert any string type to UTF8, returns number of bytes
549 * in output string or a negative error code 544 * in output string or a negative error code
@@ -558,7 +553,12 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
558 if((type < 0) || (type > 30)) return -1; 553 if((type < 0) || (type > 30)) return -1;
559 mbflag = tag2nbyte[type]; 554 mbflag = tag2nbyte[type];
560 if(mbflag == -1) return -1; 555 if(mbflag == -1) return -1;
561 mbflag |= MBSTRING_FLAG; 556 if (mbflag == 0)
557 mbflag = MBSTRING_UTF8;
558 else if (mbflag == 4)
559 mbflag = MBSTRING_UNIV;
560 else
561 mbflag |= MBSTRING_FLAG;
562 stmp.data = NULL; 562 stmp.data = NULL;
563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); 563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
564 if(ret < 0) return ret; 564 if(ret < 0) return ret;