diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_item.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_item.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_item.c b/src/lib/libcrypto/asn1/asn1_item.c index 8db1713b29..d2819dbb96 100644 --- a/src/lib/libcrypto/asn1/asn1_item.c +++ b/src/lib/libcrypto/asn1/asn1_item.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_item.c,v 1.1 2021/12/25 12:00:22 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_item.c,v 1.2 2021/12/25 12:21:36 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 | * |
@@ -167,6 +167,53 @@ ASN1_item_dup(const ASN1_ITEM *it, void *x) | |||
167 | return (ret); | 167 | return (ret); |
168 | } | 168 | } |
169 | 169 | ||
170 | /* Pack an ASN1 object into an ASN1_STRING. */ | ||
171 | ASN1_STRING * | ||
172 | ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) | ||
173 | { | ||
174 | ASN1_STRING *octmp; | ||
175 | |||
176 | if (!oct || !*oct) { | ||
177 | if (!(octmp = ASN1_STRING_new ())) { | ||
178 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
179 | return NULL; | ||
180 | } | ||
181 | } else | ||
182 | octmp = *oct; | ||
183 | |||
184 | free(octmp->data); | ||
185 | octmp->data = NULL; | ||
186 | |||
187 | if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { | ||
188 | ASN1error(ASN1_R_ENCODE_ERROR); | ||
189 | goto err; | ||
190 | } | ||
191 | if (!octmp->data) { | ||
192 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
193 | goto err; | ||
194 | } | ||
195 | if (oct) | ||
196 | *oct = octmp; | ||
197 | return octmp; | ||
198 | err: | ||
199 | if (!oct || octmp != *oct) | ||
200 | ASN1_STRING_free(octmp); | ||
201 | return NULL; | ||
202 | } | ||
203 | |||
204 | /* Extract an ASN1 object from an ASN1_STRING. */ | ||
205 | void * | ||
206 | ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) | ||
207 | { | ||
208 | const unsigned char *p; | ||
209 | void *ret; | ||
210 | |||
211 | p = oct->data; | ||
212 | if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) | ||
213 | ASN1error(ASN1_R_DECODE_ERROR); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
170 | int | 217 | int |
171 | ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | 218 | ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, |
172 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) | 219 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, const EVP_MD *type) |