| OLD | NEW |
| 1 /* crypto/asn1/asn1_par.c */ | 1 /* crypto/asn1/asn1_par.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 #include <openssl/asn1.h> | 63 #include <openssl/asn1.h> |
| 64 | 64 |
| 65 static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | 65 static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, |
| 66 int indent); | 66 int indent); |
| 67 static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, | 67 static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, |
| 68 int offset, int depth, int indent, int dump); | 68 int offset, int depth, int indent, int dump); |
| 69 static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | 69 static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, |
| 70 int indent) | 70 int indent) |
| 71 { | 71 { |
| 72 static const char fmt[]="%-18s"; | 72 static const char fmt[]="%-18s"; |
| 73 static const char fmt2[]="%2d %-15s"; | |
| 74 char str[128]; | 73 char str[128]; |
| 75 » const char *p,*p2=NULL; | 74 » const char *p; |
| 76 | 75 |
| 77 if (constructed & V_ASN1_CONSTRUCTED) | 76 if (constructed & V_ASN1_CONSTRUCTED) |
| 78 p="cons: "; | 77 p="cons: "; |
| 79 else | 78 else |
| 80 p="prim: "; | 79 p="prim: "; |
| 81 if (BIO_write(bp,p,6) < 6) goto err; | 80 if (BIO_write(bp,p,6) < 6) goto err; |
| 82 BIO_indent(bp,indent,128); | 81 BIO_indent(bp,indent,128); |
| 83 | 82 |
| 84 p=str; | 83 p=str; |
| 85 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | 84 if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) |
| 86 BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag); | 85 BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag); |
| 87 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) | 86 else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) |
| 88 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); | 87 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); |
| 89 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | 88 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) |
| 90 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); | 89 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); |
| 91 else if (tag > 30) | 90 else if (tag > 30) |
| 92 BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag); | 91 BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag); |
| 93 else | 92 else |
| 94 p = ASN1_tag2str(tag); | 93 p = ASN1_tag2str(tag); |
| 95 | 94 |
| 96 » if (p2 != NULL) | 95 » if (BIO_printf(bp,fmt,p) <= 0) |
| 97 » » { | 96 » » goto err; |
| 98 » » if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; | |
| 99 » » } | |
| 100 » else | |
| 101 » » { | |
| 102 » » if (BIO_printf(bp,fmt,p) <= 0) goto err; | |
| 103 » » } | |
| 104 return(1); | 97 return(1); |
| 105 err: | 98 err: |
| 106 return(0); | 99 return(0); |
| 107 } | 100 } |
| 108 | 101 |
| 109 int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) | 102 int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) |
| 110 { | 103 { |
| 111 return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | 104 return(asn1_parse2(bp,&pp,len,0,0,indent,0)); |
| 112 } | 105 } |
| 113 | 106 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 ret=1; | 410 ret=1; |
| 418 end: | 411 end: |
| 419 if (o != NULL) ASN1_OBJECT_free(o); | 412 if (o != NULL) ASN1_OBJECT_free(o); |
| 420 if (os != NULL) M_ASN1_OCTET_STRING_free(os); | 413 if (os != NULL) M_ASN1_OCTET_STRING_free(os); |
| 421 *pp=p; | 414 *pp=p; |
| 422 return(ret); | 415 return(ret); |
| 423 } | 416 } |
| 424 | 417 |
| 425 const char *ASN1_tag2str(int tag) | 418 const char *ASN1_tag2str(int tag) |
| 426 { | 419 { |
| 427 » static const char *tag2str[] = { | 420 » static const char * const tag2str[] = { |
| 428 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | 421 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ |
| 429 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | 422 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ |
| 430 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | 423 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ |
| 431 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ | 424 "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ |
| 432 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ | 425 "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ |
| 433 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | 426 "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ |
| 434 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | 427 "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ |
| 435 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | 428 "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ |
| 436 }; | 429 }; |
| 437 | 430 |
| 438 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | 431 if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) |
| 439 tag &= ~0x100; | 432 tag &= ~0x100; |
| 440 | 433 |
| 441 if(tag < 0 || tag > 30) return "(unknown)"; | 434 if(tag < 0 || tag > 30) return "(unknown)"; |
| 442 return tag2str[tag]; | 435 return tag2str[tag]; |
| 443 } | 436 } |
| 444 | 437 |
| OLD | NEW |