diff options
| author | markus <> | 2002-09-05 12:51:50 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 12:51:50 +0000 |
| commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
| tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/asn1/a_dup.c | |
| parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
| download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip | |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/asn1/a_dup.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_dup.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c index 961b4cb069..58a017884c 100644 --- a/src/lib/libcrypto/asn1/a_dup.c +++ b/src/lib/libcrypto/asn1/a_dup.c | |||
| @@ -58,14 +58,11 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "asn1_mac.h" | 61 | #include <openssl/asn1.h> |
| 62 | 62 | ||
| 63 | #define READ_CHUNK 2048 | 63 | #ifndef NO_OLD_ASN1 |
| 64 | 64 | ||
| 65 | char *ASN1_dup(i2d,d2i,x) | 65 | char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x) |
| 66 | int (*i2d)(); | ||
| 67 | char *(*d2i)(); | ||
| 68 | char *x; | ||
| 69 | { | 66 | { |
| 70 | unsigned char *b,*p; | 67 | unsigned char *b,*p; |
| 71 | long i; | 68 | long i; |
| @@ -74,13 +71,37 @@ char *x; | |||
| 74 | if (x == NULL) return(NULL); | 71 | if (x == NULL) return(NULL); |
| 75 | 72 | ||
| 76 | i=(long)i2d(x,NULL); | 73 | i=(long)i2d(x,NULL); |
| 77 | b=(unsigned char *)Malloc((unsigned int)i+10); | 74 | b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); |
| 78 | if (b == NULL) | 75 | if (b == NULL) |
| 79 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | 76 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } |
| 80 | p= b; | 77 | p= b; |
| 81 | i=i2d(x,&p); | 78 | i=i2d(x,&p); |
| 82 | p= b; | 79 | p= b; |
| 83 | ret=d2i(NULL,&p,i); | 80 | ret=d2i(NULL,&p,i); |
| 84 | Free((char *)b); | 81 | OPENSSL_free(b); |
| 82 | return(ret); | ||
| 83 | } | ||
| 84 | |||
| 85 | #endif | ||
| 86 | |||
| 87 | /* ASN1_ITEM version of dup: this follows the model above except we don't need | ||
| 88 | * to allocate the buffer. At some point this could be rewritten to directly dup | ||
| 89 | * the underlying structure instead of doing and encode and decode. | ||
| 90 | */ | ||
| 91 | |||
| 92 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | ||
| 93 | { | ||
| 94 | unsigned char *b = NULL, *p; | ||
| 95 | long i; | ||
| 96 | void *ret; | ||
| 97 | |||
| 98 | if (x == NULL) return(NULL); | ||
| 99 | |||
| 100 | i=ASN1_item_i2d(x,&b,it); | ||
| 101 | if (b == NULL) | ||
| 102 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
| 103 | p= b; | ||
| 104 | ret=ASN1_item_d2i(NULL,&p,i, it); | ||
| 105 | OPENSSL_free(b); | ||
| 85 | return(ret); | 106 | return(ret); |
| 86 | } | 107 | } |
