]> pd.if.org Git - zpackage/blob - libtomcrypt/src/pk/asn1/der/boolean/der_decode_boolean.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / pk / asn1 / der / boolean / der_decode_boolean.c
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2  *
3  * LibTomCrypt is a library that provides various cryptographic
4  * algorithms in a highly modular and flexible manner.
5  *
6  * The library is free for all purposes without any express
7  * guarantee it works.
8  */
9 #include "tomcrypt.h"
10
11 /**
12   @file der_decode_boolean.c
13   ASN.1 DER, decode a BOOLEAN, Tom St Denis
14 */
15
16
17 #ifdef LTC_DER
18
19 /**
20   Read a BOOLEAN
21   @param in      The destination for the DER encoded BOOLEAN
22   @param inlen   The size of the DER BOOLEAN
23   @param out     [out]  The boolean to decode
24   @return CRYPT_OK if successful
25 */
26 int der_decode_boolean(const unsigned char *in, unsigned long inlen,
27                                        int *out)
28 {
29    LTC_ARGCHK(in  != NULL);
30    LTC_ARGCHK(out != NULL);
31
32    if (inlen < 3 || in[0] != 0x01 || in[1] != 0x01 || (in[2] != 0x00 && in[2] != 0xFF)) {
33       return CRYPT_INVALID_ARG;
34    }
35
36    *out = (in[2]==0xFF) ? 1 : 0;
37
38    return CRYPT_OK;
39 }
40
41 #endif
42
43 /* ref:         $Format:%D$ */
44 /* git commit:  $Format:%H$ */
45 /* commit time: $Format:%ai$ */