summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/objects/obj_lib.c
diff options
context:
space:
mode:
authorjsing <>2014-04-19 16:44:36 +0000
committerjsing <>2014-04-19 16:44:36 +0000
commita267d032e2aaa6ac481f33615c9e57c613d49e2e (patch)
tree49030d3fea9f966297eb3218259a4faca4c52c9f /src/lib/libcrypto/objects/obj_lib.c
parenta21c0bb00d07d5263cf88747b598ac88a87d65ec (diff)
downloadopenbsd-a267d032e2aaa6ac481f33615c9e57c613d49e2e.tar.gz
openbsd-a267d032e2aaa6ac481f33615c9e57c613d49e2e.tar.bz2
openbsd-a267d032e2aaa6ac481f33615c9e57c613d49e2e.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/objects/obj_lib.c')
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c116
1 files changed, 62 insertions, 54 deletions
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 338fe851fc..57f0b28cc0 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -5,21 +5,21 @@
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
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -62,68 +62,76 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64 64
65ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o) 65ASN1_OBJECT *
66 { 66OBJ_dup(const ASN1_OBJECT *o)
67{
67 ASN1_OBJECT *r; 68 ASN1_OBJECT *r;
68 int i; 69 int i;
69 char *ln=NULL,*sn=NULL; 70 char *ln = NULL, *sn = NULL;
70 unsigned char *data=NULL; 71 unsigned char *data = NULL;
71 72
72 if (o == NULL) return(NULL); 73 if (o == NULL)
74 return (NULL);
73 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) 75 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
74 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of 76 return((ASN1_OBJECT *)o); /* XXX: ugh! Why? What kind of
75 duplication is this??? */ 77 duplication is this??? */
76 78
77 r=ASN1_OBJECT_new(); 79 r = ASN1_OBJECT_new();
78 if (r == NULL) 80 if (r == NULL) {
79 { 81 OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 82 return (NULL);
81 return(NULL); 83 }
82 } 84 data = malloc(o->length);
83 data=malloc(o->length);
84 if (data == NULL) 85 if (data == NULL)
85 goto err; 86 goto err;
86 if (o->data != NULL) 87 if (o->data != NULL)
87 memcpy(data,o->data,o->length); 88 memcpy(data, o->data, o->length);
88 /* once data attached to object it remains const */ 89 /* once data attached to object it remains const */
89 r->data = data; 90 r->data = data;
90 r->length=o->length; 91 r->length = o->length;
91 r->nid=o->nid; 92 r->nid = o->nid;
92 r->ln=r->sn=NULL; 93 r->ln = r->sn = NULL;
93 if (o->ln != NULL) 94 if (o->ln != NULL) {
94 { 95 i = strlen(o->ln) + 1;
95 i=strlen(o->ln)+1; 96 ln = malloc(i);
96 ln=malloc(i); 97 if (ln == NULL)
97 if (ln == NULL) goto err; 98 goto err;
98 memcpy(ln,o->ln,i); 99 memcpy(ln, o->ln, i);
99 r->ln=ln; 100 r->ln = ln;
100 } 101 }
101 102
102 if (o->sn != NULL) 103 if (o->sn != NULL) {
103 { 104 i = strlen(o->sn) + 1;
104 i=strlen(o->sn)+1; 105 sn = malloc(i);
105 sn=malloc(i); 106 if (sn == NULL)
106 if (sn == NULL) goto err; 107 goto err;
107 memcpy(sn,o->sn,i); 108 memcpy(sn, o->sn, i);
108 r->sn=sn; 109 r->sn = sn;
109 }
110 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
111 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
112 return(r);
113err:
114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
115 if (ln != NULL) free(ln);
116 if (sn != NULL) free(sn);
117 if (data != NULL) free(data);
118 if (r != NULL) free(r);
119 return(NULL);
120 } 110 }
111 r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
112 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS | ASN1_OBJECT_FLAG_DYNAMIC_DATA);
113 return (r);
121 114
122int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b) 115err:
123 { 116 OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
117 if (ln != NULL)
118 free(ln);
119 if (sn != NULL)
120 free(sn);
121 if (data != NULL)
122 free(data);
123 if (r != NULL)
124 free(r);
125 return (NULL);
126}
127
128int
129OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
130{
124 int ret; 131 int ret;
125 132
126 ret=(a->length-b->length); 133 ret = (a->length - b->length);
127 if (ret) return(ret); 134 if (ret)
128 return(memcmp(a->data,b->data,a->length)); 135 return (ret);
129 } 136 return (memcmp(a->data, b->data, a->length));
137}