OLD | NEW |
1 /* crypto/asn1/a_type.c */ | 1 /* crypto/asn1/a_type.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | 72 void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) |
73 { | 73 { |
74 if (a->value.ptr != NULL) | 74 if (a->value.ptr != NULL) |
75 { | 75 { |
76 ASN1_TYPE **tmp_a = &a; | 76 ASN1_TYPE **tmp_a = &a; |
77 ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); | 77 ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL); |
78 } | 78 } |
79 a->type=type; | 79 a->type=type; |
80 » a->value.ptr=value; | 80 » if (type == V_ASN1_BOOLEAN) |
| 81 » » a->value.boolean = value ? 0xff : 0; |
| 82 » else |
| 83 » » a->value.ptr=value; |
81 } | 84 } |
82 | 85 |
83 int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) | 86 int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) |
84 { | 87 { |
85 if (!value || (type == V_ASN1_BOOLEAN)) | 88 if (!value || (type == V_ASN1_BOOLEAN)) |
86 { | 89 { |
87 void *p = (void *)value; | 90 void *p = (void *)value; |
88 ASN1_TYPE_set(a, type, p); | 91 ASN1_TYPE_set(a, type, p); |
89 } | 92 } |
90 else if (type == V_ASN1_OBJECT) | 93 else if (type == V_ASN1_OBJECT) |
91 { | 94 { |
92 ASN1_OBJECT *odup; | 95 ASN1_OBJECT *odup; |
93 odup = OBJ_dup(value); | 96 odup = OBJ_dup(value); |
94 if (!odup) | 97 if (!odup) |
95 return 0; | 98 return 0; |
96 ASN1_TYPE_set(a, type, odup); | 99 ASN1_TYPE_set(a, type, odup); |
97 } | 100 } |
98 else | 101 else |
99 { | 102 { |
100 ASN1_STRING *sdup; | 103 ASN1_STRING *sdup; |
101 » » sdup = ASN1_STRING_dup((ASN1_STRING *)value); | 104 » » sdup = ASN1_STRING_dup(value); |
102 if (!sdup) | 105 if (!sdup) |
103 return 0; | 106 return 0; |
104 ASN1_TYPE_set(a, type, sdup); | 107 ASN1_TYPE_set(a, type, sdup); |
105 } | 108 } |
106 return 1; | 109 return 1; |
107 } | 110 } |
108 | 111 |
109 IMPLEMENT_STACK_OF(ASN1_TYPE) | 112 IMPLEMENT_STACK_OF(ASN1_TYPE) |
110 IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) | 113 IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) |
| 114 |
| 115 /* Returns 0 if they are equal, != 0 otherwise. */ |
| 116 int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b) |
| 117 { |
| 118 int result = -1; |
| 119 |
| 120 if (!a || !b || a->type != b->type) return -1; |
| 121 |
| 122 switch (a->type) |
| 123 { |
| 124 case V_ASN1_OBJECT: |
| 125 result = OBJ_cmp(a->value.object, b->value.object); |
| 126 break; |
| 127 case V_ASN1_NULL: |
| 128 result = 0; /* They do not have content. */ |
| 129 break; |
| 130 case V_ASN1_INTEGER: |
| 131 case V_ASN1_NEG_INTEGER: |
| 132 case V_ASN1_ENUMERATED: |
| 133 case V_ASN1_NEG_ENUMERATED: |
| 134 case V_ASN1_BIT_STRING: |
| 135 case V_ASN1_OCTET_STRING: |
| 136 case V_ASN1_SEQUENCE: |
| 137 case V_ASN1_SET: |
| 138 case V_ASN1_NUMERICSTRING: |
| 139 case V_ASN1_PRINTABLESTRING: |
| 140 case V_ASN1_T61STRING: |
| 141 case V_ASN1_VIDEOTEXSTRING: |
| 142 case V_ASN1_IA5STRING: |
| 143 case V_ASN1_UTCTIME: |
| 144 case V_ASN1_GENERALIZEDTIME: |
| 145 case V_ASN1_GRAPHICSTRING: |
| 146 case V_ASN1_VISIBLESTRING: |
| 147 case V_ASN1_GENERALSTRING: |
| 148 case V_ASN1_UNIVERSALSTRING: |
| 149 case V_ASN1_BMPSTRING: |
| 150 case V_ASN1_UTF8STRING: |
| 151 case V_ASN1_OTHER: |
| 152 default: |
| 153 result = ASN1_STRING_cmp((ASN1_STRING *) a->value.ptr, |
| 154 (ASN1_STRING *) b->value.ptr); |
| 155 break; |
| 156 } |
| 157 |
| 158 return result; |
| 159 } |
OLD | NEW |