Use typedefs in i2d and d2i_ASN1_BOOLEAN.
This makes it slightly clearer which ints are lengths and which are
substituting for T*. (ASN1_BOOLEAN is weird. It is the one non-pointer
representation in crypto/asn1.)
Change-Id: I93ff87264835e64c9f8613edae63e93731e77548
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49865
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/asn1/a_bool.c b/crypto/asn1/a_bool.c
index 15396ff..1282176 100644
--- a/crypto/asn1/a_bool.c
+++ b/crypto/asn1/a_bool.c
@@ -59,7 +59,7 @@
#include <openssl/err.h>
#include <openssl/mem.h>
-int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
+int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **pp)
{
int r;
unsigned char *p, *allocated = NULL;
@@ -88,36 +88,30 @@
return r;
}
-int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)
-{
- int ret = -1;
- const unsigned char *p;
+ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *a, const unsigned char **pp,
+ long length) {
+ const unsigned char *p = *pp;
long len;
int inf, tag, xclass;
- int i = 0;
-
- p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
- i = ASN1_R_BAD_OBJECT_HEADER;
- goto err;
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
+ return -1;
}
if (tag != V_ASN1_BOOLEAN) {
- i = ASN1_R_EXPECTING_A_BOOLEAN;
- goto err;
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPECTING_A_BOOLEAN);
+ return -1;
}
if (len != 1) {
- i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
- goto err;
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
+ return -1;
}
- ret = (int)*(p++);
- if (a != NULL)
+ ASN1_BOOLEAN ret = (ASN1_BOOLEAN)*(p++);
+ if (a != NULL) {
(*a) = ret;
+ }
*pp = p;
- return (ret);
- err:
- OPENSSL_PUT_ERROR(ASN1, i);
- return (ret);
+ return ret;
}
diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h
index f9d980f..799732d 100644
--- a/include/openssl/asn1.h
+++ b/include/openssl/asn1.h
@@ -1113,9 +1113,10 @@
const unsigned char **pp,
long length);
-OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(int a, unsigned char **pp);
-OPENSSL_EXPORT int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp,
- long length);
+OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **pp);
+OPENSSL_EXPORT ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *a,
+ const unsigned char **pp,
+ long length);
DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *a, unsigned char **pp);