From f860ff473beb386fc88047a00a6e27437ba4ab75 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Thu, 24 Oct 2019 16:36:10 +0000 Subject: Provide ASN1_TYPE_{,un}pack_sequence(). These are internal only for now. Based on OpenSSL 1.1.1d. ok inoguchi@ --- src/lib/libcrypto/asn1/a_type.c | 33 ++++++++++++++++++++++++++++++++- src/lib/libcrypto/asn1/asn1_locl.h | 5 ++++- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c index 11d38300d6..a18ffe66ba 100644 --- a/src/lib/libcrypto/asn1/a_type.c +++ b/src/lib/libcrypto/asn1/a_type.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_type.c,v 1.20 2018/04/25 11:48:21 tb Exp $ */ +/* $OpenBSD: a_type.c,v 1.21 2019/10/24 16:36:10 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -154,3 +154,34 @@ ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) return result; } + +ASN1_TYPE * +ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t) +{ + ASN1_OCTET_STRING *oct; + ASN1_TYPE *rt; + + if ((oct = ASN1_item_pack(s, it, NULL)) == NULL) + return NULL; + + if (t != NULL && *t != NULL) { + rt = *t; + } else { + if ((rt = ASN1_TYPE_new()) == NULL) { + ASN1_OCTET_STRING_free(oct); + return NULL; + } + if (t != NULL) + *t = rt; + } + ASN1_TYPE_set(rt, V_ASN1_SEQUENCE, oct); + return rt; +} + +void * +ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t) +{ + if (t == NULL || t->type != V_ASN1_SEQUENCE || t->value.sequence == NULL) + return NULL; + return ASN1_item_unpack(t->value.sequence, it); +} diff --git a/src/lib/libcrypto/asn1/asn1_locl.h b/src/lib/libcrypto/asn1/asn1_locl.h index 5ade6c7e3f..39779d9377 100644 --- a/src/lib/libcrypto/asn1/asn1_locl.h +++ b/src/lib/libcrypto/asn1/asn1_locl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_locl.h,v 1.11 2018/08/24 20:22:15 tb Exp $ */ +/* $OpenBSD: asn1_locl.h,v 1.12 2019/10/24 16:36:10 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -60,6 +60,9 @@ __BEGIN_HIDDEN_DECLS /* Internal ASN1 structures and functions: not for application use */ +ASN1_TYPE *ASN1_TYPE_pack_sequence(const ASN1_ITEM *it, void *s, ASN1_TYPE **t); +void *ASN1_TYPE_unpack_sequence(const ASN1_ITEM *it, const ASN1_TYPE *t); + /* ASN1 print context structure */ struct asn1_pctx_st { -- cgit v1.2.3-55-g6feb