Debian Codegraph @

src/ltc/pk/asn1/der/boolean/der_decode_boolean.c

raw
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file der_decode_boolean.c
7 ASN.1 DER, decode a BOOLEAN, Tom St Denis
8 */
9
10
11 #ifdef LTC_DER
12
13 /**
14 Read a BOOLEAN
15 @param in The destination for the DER encoded BOOLEAN
16 @param inlen The size of the DER BOOLEAN
17 @param out [out] The boolean to decode
18 @return CRYPT_OK if successful
19 */
20 int der_decode_boolean(const unsigned char *in, unsigned long inlen,
21 int *out)
22 {
23 LTC_ARGCHK(in != NULL);
24 LTC_ARGCHK(out != NULL);
25
26 if (inlen < 3 || in[0] != 0x01 || in[1] != 0x01 || (in[2] != 0x00 && in[2] != 0xFF)) {
27 return CRYPT_INVALID_ARG;
28 }
29
30 *out = (in[2]==0xFF) ? 1 : 0;
31
32 return CRYPT_OK;
33 }
34
35 #endif