a_mbstr.c (59191) | a_mbstr.c (68651) |
---|---|
1/* a_mbstr.c */ 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3 * project 1999. 4 */ 5/* ==================================================================== 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 78 unchanged lines hidden (view full) --- 87} 88 89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, 90 int inform, unsigned long mask, 91 long minsize, long maxsize) 92{ 93 int str_type; 94 int ret; | 1/* a_mbstr.c */ 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3 * project 1999. 4 */ 5/* ==================================================================== 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 78 unchanged lines hidden (view full) --- 87} 88 89int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, 90 int inform, unsigned long mask, 91 long minsize, long maxsize) 92{ 93 int str_type; 94 int ret; |
95 char free_out; |
|
95 int outform, outlen; 96 ASN1_STRING *dest; 97 unsigned char *p; 98 int nchar; 99 char strbuf[32]; 100 int (*cpyfunc)(unsigned long,void *) = NULL; 101 if(len == -1) len = strlen((const char *)in); 102 if(!mask) mask = DIRSTRING_TYPE; --- 72 unchanged lines hidden (view full) --- 175 str_type = V_ASN1_UNIVERSALSTRING; 176 outform = MBSTRING_UNIV; 177 } else { 178 str_type = V_ASN1_UTF8STRING; 179 outform = MBSTRING_UTF8; 180 } 181 if(!out) return str_type; 182 if(*out) { | 96 int outform, outlen; 97 ASN1_STRING *dest; 98 unsigned char *p; 99 int nchar; 100 char strbuf[32]; 101 int (*cpyfunc)(unsigned long,void *) = NULL; 102 if(len == -1) len = strlen((const char *)in); 103 if(!mask) mask = DIRSTRING_TYPE; --- 72 unchanged lines hidden (view full) --- 176 str_type = V_ASN1_UNIVERSALSTRING; 177 outform = MBSTRING_UNIV; 178 } else { 179 str_type = V_ASN1_UTF8STRING; 180 outform = MBSTRING_UTF8; 181 } 182 if(!out) return str_type; 183 if(*out) { |
184 free_out = 0; |
|
183 dest = *out; 184 if(dest->data) { 185 dest->length = 0; | 185 dest = *out; 186 if(dest->data) { 187 dest->length = 0; |
186 Free(dest->data); | 188 OPENSSL_free(dest->data); |
187 dest->data = NULL; 188 } 189 dest->type = str_type; 190 } else { | 189 dest->data = NULL; 190 } 191 dest->type = str_type; 192 } else { |
193 free_out = 1; |
|
191 dest = ASN1_STRING_type_new(str_type); 192 if(!dest) { 193 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, 194 ERR_R_MALLOC_FAILURE); 195 return -1; 196 } 197 *out = dest; 198 } --- 24 unchanged lines hidden (view full) --- 223 break; 224 225 case MBSTRING_UTF8: 226 outlen = 0; 227 traverse_string(in, len, inform, out_utf8, &outlen); 228 cpyfunc = cpy_utf8; 229 break; 230 } | 194 dest = ASN1_STRING_type_new(str_type); 195 if(!dest) { 196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, 197 ERR_R_MALLOC_FAILURE); 198 return -1; 199 } 200 *out = dest; 201 } --- 24 unchanged lines hidden (view full) --- 226 break; 227 228 case MBSTRING_UTF8: 229 outlen = 0; 230 traverse_string(in, len, inform, out_utf8, &outlen); 231 cpyfunc = cpy_utf8; 232 break; 233 } |
231 if(!(p = Malloc(outlen + 1))) { 232 ASN1_STRING_free(dest); | 234 if(!(p = OPENSSL_malloc(outlen + 1))) { 235 if(free_out) ASN1_STRING_free(dest); |
233 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE); 234 return -1; 235 } 236 dest->length = outlen; 237 dest->data = p; 238 p[outlen] = 0; 239 traverse_string(in, len, inform, cpyfunc, &p); 240 return str_type; --- 12 unchanged lines hidden (view full) --- 253 if(inform == MBSTRING_ASC) { 254 value = *p++; 255 len--; 256 } else if(inform == MBSTRING_BMP) { 257 value = *p++ << 8; 258 value |= *p++; 259 len -= 2; 260 } else if(inform == MBSTRING_UNIV) { | 236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE); 237 return -1; 238 } 239 dest->length = outlen; 240 dest->data = p; 241 p[outlen] = 0; 242 traverse_string(in, len, inform, cpyfunc, &p); 243 return str_type; --- 12 unchanged lines hidden (view full) --- 256 if(inform == MBSTRING_ASC) { 257 value = *p++; 258 len--; 259 } else if(inform == MBSTRING_BMP) { 260 value = *p++ << 8; 261 value |= *p++; 262 len -= 2; 263 } else if(inform == MBSTRING_UNIV) { |
261 value = *p++ << 24; 262 value |= *p++ << 16; | 264 value = ((unsigned long)*p++) << 24; 265 value |= ((unsigned long)*p++) << 16; |
263 value |= *p++ << 8; 264 value |= *p++; 265 len -= 4; 266 } else { 267 ret = UTF8_getc(p, len, &value); 268 if(ret < 0) return -1; 269 len -= ret; 270 p += ret; --- 106 unchanged lines hidden (view full) --- 377static int is_printable(unsigned long value) 378{ 379 int ch; 380 if(value > 0x7f) return 0; 381 ch = (int) value; 382 /* Note: we can't use 'isalnum' because certain accented 383 * characters may count as alphanumeric in some environments. 384 */ | 266 value |= *p++ << 8; 267 value |= *p++; 268 len -= 4; 269 } else { 270 ret = UTF8_getc(p, len, &value); 271 if(ret < 0) return -1; 272 len -= ret; 273 p += ret; --- 106 unchanged lines hidden (view full) --- 380static int is_printable(unsigned long value) 381{ 382 int ch; 383 if(value > 0x7f) return 0; 384 ch = (int) value; 385 /* Note: we can't use 'isalnum' because certain accented 386 * characters may count as alphanumeric in some environments. 387 */ |
388#ifndef CHARSET_EBCDIC |
|
385 if((ch >= 'a') && (ch <= 'z')) return 1; 386 if((ch >= 'A') && (ch <= 'Z')) return 1; 387 if((ch >= '0') && (ch <= '9')) return 1; 388 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; | 389 if((ch >= 'a') && (ch <= 'z')) return 1; 390 if((ch >= 'A') && (ch <= 'Z')) return 1; 391 if((ch >= '0') && (ch <= '9')) return 1; 392 if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; |
393#else /*CHARSET_EBCDIC*/ 394 if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1; 395 if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1; 396 if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1; 397 if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1; 398#endif /*CHARSET_EBCDIC*/ |
|
389 return 0; 390} | 399 return 0; 400} |