]> pd.if.org Git - zpackage/blob - libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c
commit files needed for zpm-fetchurl
[zpackage] / libtomcrypt / src / pk / asn1 / der / boolean / der_encode_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_encode_boolean.c
13   ASN.1 DER, encode a BOOLEAN, Tom St Denis
14 */
15
16
17 #ifdef LTC_DER
18
19 /**
20   Store a BOOLEAN
21   @param in       The boolean to encode
22   @param out      [out] The destination for the DER encoded BOOLEAN
23   @param outlen   [in/out] The max size and resulting size of the DER BOOLEAN
24   @return CRYPT_OK if successful
25 */
26 int der_encode_boolean(int in,
27                        unsigned char *out, unsigned long *outlen)
28 {
29    LTC_ARGCHK(outlen != NULL);
30    LTC_ARGCHK(out    != NULL);
31
32    if (*outlen < 3) {
33        *outlen = 3;
34        return CRYPT_BUFFER_OVERFLOW;
35    }
36
37    *outlen = 3;
38    out[0] = 0x01;
39    out[1] = 0x01;
40    out[2] = in ? 0xFF : 0x00;
41
42    return CRYPT_OK;
43 }
44
45 #endif
46
47 /* ref:         $Format:%D$ */
48 /* git commit:  $Format:%H$ */
49 /* commit time: $Format:%ai$ */