| 1 |
// Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#include <openssl/asn1.h> |
| 5 |
|
| 6 |
#include <openssl/bytestring.h> |
| 7 |
#include <openssl/err.h> |
| 8 |
|
| 9 |
#include "../bytestring/internal.h" |
| 10 |
|
| 11 |
|
| 12 |
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp) { |
| 13 |
CBB cbb; |
| 14 |
if (!CBB_init(&cbb, 3) || // |
| 15 |
!CBB_add_asn1_bool(&cbb, a != ASN1_BOOLEAN_FALSE)) { |
| 16 |
CBB_cleanup(&cbb); |
| 17 |
return -1; |
| 18 |
} |
| 19 |
return CBB_finish_i2d(&cbb, outp); |
| 20 |
} |
| 21 |
|
| 22 |
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, const unsigned char **inp, |
| 23 |
long len) { |
| 24 |
if (len < 0) { |
| 25 |
return ASN1_BOOLEAN_NONE; |
| 26 |
} |
| 27 |
|
| 28 |
CBS cbs; |
| 29 |
CBS_init(&cbs, *inp, (size_t)len); |
| 30 |
int val; |
| 31 |
if (!CBS_get_asn1_bool(&cbs, &val)) { |
| 32 |
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR); |
| 33 |
return ASN1_BOOLEAN_NONE; |
| 34 |
} |
| 35 |
|
| 36 |
ASN1_BOOLEAN ret = val ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE; |
| 37 |
if (out != NULL) { |
| 38 |
*out = ret; |
| 39 |
} |
| 40 |
*inp = CBS_data(&cbs); |
| 41 |
return ret; |
| 42 |
} |