diff options
author | jsing <> | 2021-12-15 18:00:32 +0000 |
---|---|---|
committer | jsing <> | 2021-12-15 18:00:32 +0000 |
commit | e61e8eab0ed72cba26134860e9976f836728d877 (patch) | |
tree | 582bd7e91dc07b37e1a88c57120d362994f5a80b /src/lib/libcrypto/asn1/asn1_lib.c | |
parent | d97abc08cae4df58901d8ea1f6fe74e35d142843 (diff) | |
download | openbsd-e61e8eab0ed72cba26134860e9976f836728d877.tar.gz openbsd-e61e8eab0ed72cba26134860e9976f836728d877.tar.bz2 openbsd-e61e8eab0ed72cba26134860e9976f836728d877.zip |
Consolidate various ASN.1 code.
Rather than having multiple files per type (with minimal code per file),
use one file per type (a_<type>.c).
No functional change.
Discussed with tb@
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_lib.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_lib.c | 148 |
1 files changed, 1 insertions, 147 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 3e2ba29495..fc0958fb45 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_lib.c,v 1.48 2021/12/03 17:03:54 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_lib.c,v 1.49 2021/12/15 18:00:31 jsing Exp $ */ |
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 | * |
@@ -284,149 +284,3 @@ ASN1_object_size(int constructed, int length, int tag) | |||
284 | } | 284 | } |
285 | return (ret); | 285 | return (ret); |
286 | } | 286 | } |
287 | |||
288 | int | ||
289 | ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str) | ||
290 | { | ||
291 | if (str == NULL) | ||
292 | return 0; | ||
293 | if (!ASN1_STRING_set(dst, str->data, str->length)) | ||
294 | return 0; | ||
295 | dst->type = str->type; | ||
296 | dst->flags = str->flags; | ||
297 | return 1; | ||
298 | } | ||
299 | |||
300 | ASN1_STRING * | ||
301 | ASN1_STRING_dup(const ASN1_STRING *str) | ||
302 | { | ||
303 | ASN1_STRING *ret; | ||
304 | |||
305 | if (!str) | ||
306 | return NULL; | ||
307 | ret = ASN1_STRING_new(); | ||
308 | if (!ret) | ||
309 | return NULL; | ||
310 | if (!ASN1_STRING_copy(ret, str)) { | ||
311 | ASN1_STRING_free(ret); | ||
312 | return NULL; | ||
313 | } | ||
314 | return ret; | ||
315 | } | ||
316 | |||
317 | int | ||
318 | ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | ||
319 | { | ||
320 | const char *data = _data; | ||
321 | |||
322 | if (len < 0) { | ||
323 | if (data == NULL) | ||
324 | return (0); | ||
325 | else | ||
326 | len = strlen(data); | ||
327 | } | ||
328 | if ((str->length < len) || (str->data == NULL)) { | ||
329 | unsigned char *tmp; | ||
330 | tmp = realloc(str->data, len + 1); | ||
331 | if (tmp == NULL) { | ||
332 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
333 | return (0); | ||
334 | } | ||
335 | str->data = tmp; | ||
336 | } | ||
337 | str->length = len; | ||
338 | if (data != NULL) { | ||
339 | memmove(str->data, data, len); | ||
340 | } | ||
341 | str->data[str->length] = '\0'; | ||
342 | return (1); | ||
343 | } | ||
344 | |||
345 | void | ||
346 | ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) | ||
347 | { | ||
348 | freezero(str->data, str->length); | ||
349 | str->data = data; | ||
350 | str->length = len; | ||
351 | } | ||
352 | |||
353 | ASN1_STRING * | ||
354 | ASN1_STRING_new(void) | ||
355 | { | ||
356 | return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
357 | } | ||
358 | |||
359 | ASN1_STRING * | ||
360 | ASN1_STRING_type_new(int type) | ||
361 | { | ||
362 | ASN1_STRING *a; | ||
363 | |||
364 | if ((a = calloc(1, sizeof(ASN1_STRING))) == NULL) { | ||
365 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
366 | return NULL; | ||
367 | } | ||
368 | a->type = type; | ||
369 | |||
370 | return a; | ||
371 | } | ||
372 | |||
373 | void | ||
374 | ASN1_STRING_free(ASN1_STRING *a) | ||
375 | { | ||
376 | if (a == NULL) | ||
377 | return; | ||
378 | if (a->data != NULL && !(a->flags & ASN1_STRING_FLAG_NDEF)) | ||
379 | freezero(a->data, a->length); | ||
380 | free(a); | ||
381 | } | ||
382 | |||
383 | int | ||
384 | ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
385 | { | ||
386 | int cmp; | ||
387 | |||
388 | if (a == NULL || b == NULL) | ||
389 | return -1; | ||
390 | if ((cmp = (a->length - b->length)) != 0) | ||
391 | return cmp; | ||
392 | if ((cmp = memcmp(a->data, b->data, a->length)) != 0) | ||
393 | return cmp; | ||
394 | |||
395 | return (a->type - b->type); | ||
396 | } | ||
397 | |||
398 | void | ||
399 | asn1_add_error(const unsigned char *address, int offset) | ||
400 | { | ||
401 | ERR_asprintf_error_data("offset=%d", offset); | ||
402 | } | ||
403 | |||
404 | int | ||
405 | ASN1_STRING_length(const ASN1_STRING *x) | ||
406 | { | ||
407 | return (x->length); | ||
408 | } | ||
409 | |||
410 | void | ||
411 | ASN1_STRING_length_set(ASN1_STRING *x, int len) | ||
412 | { | ||
413 | x->length = len; | ||
414 | } | ||
415 | |||
416 | int | ||
417 | ASN1_STRING_type(const ASN1_STRING *x) | ||
418 | { | ||
419 | return (x->type); | ||
420 | } | ||
421 | |||
422 | unsigned char * | ||
423 | ASN1_STRING_data(ASN1_STRING *x) | ||
424 | { | ||
425 | return (x->data); | ||
426 | } | ||
427 | |||
428 | const unsigned char * | ||
429 | ASN1_STRING_get0_data(const ASN1_STRING *x) | ||
430 | { | ||
431 | return (x->data); | ||
432 | } | ||