From a1aa360082915390f4dce8cb202c7a908f0801d7 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 25 Dec 2021 08:52:44 +0000 Subject: Consolidate code/templates for ASN.1 types. Where an ASN.1 type has its own file, move the ASN.1 item template and template related functions into the file. Discussed with tb@ --- src/lib/libcrypto/asn1/a_int.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/lib/libcrypto/asn1/a_int.c') diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index 9218a17c11..eac7546eac 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_int.c,v 1.36 2021/12/25 07:48:09 jsing Exp $ */ +/* $OpenBSD: a_int.c,v 1.37 2021/12/25 08:52:44 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -61,10 +61,29 @@ #include #include +#include #include #include #include +const ASN1_ITEM ASN1_INTEGER_it = { + .itype = ASN1_ITYPE_PRIMITIVE, + .utype = V_ASN1_INTEGER, + .sname = "ASN1_INTEGER", +}; + +ASN1_INTEGER * +ASN1_INTEGER_new(void) +{ + return (ASN1_INTEGER *)ASN1_item_new(&ASN1_INTEGER_it); +} + +void +ASN1_INTEGER_free(ASN1_INTEGER *a) +{ + ASN1_item_free((ASN1_VALUE *)a, &ASN1_INTEGER_it); +} + static int ASN1_INTEGER_valid(const ASN1_INTEGER *a) { @@ -567,6 +586,18 @@ err: return (NULL); } +int +i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **out) +{ + return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_INTEGER_it); +} + +ASN1_INTEGER * +d2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **in, long len) +{ + return (ASN1_INTEGER *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, + &ASN1_INTEGER_it); +} /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of * ASN1 integers: some broken software can encode a positive INTEGER -- cgit v1.2.3-55-g6feb