1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
9 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
14 @file der_encode_utctime.c
15 ASN.1 DER, encode a UTCTIME, Tom St Denis
20 static const char *baseten = "0123456789";
23 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
24 out[x++] = der_ia5_char_encode(baseten[y % 10]);
27 Encodes a UTC time structure in DER format
28 @param utctime The UTC time structure to encode
29 @param out The destination of the DER encoding of the UTC time structure
30 @param outlen [in/out] The length of the DER encoding
31 @return CRYPT_OK if successful
33 int der_encode_utctime(ltc_utctime *utctime,
34 unsigned char *out, unsigned long *outlen)
36 unsigned long x, tmplen;
39 LTC_ARGCHK(utctime != NULL);
40 LTC_ARGCHK(out != NULL);
41 LTC_ARGCHK(outlen != NULL);
43 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) {
46 if (tmplen > *outlen) {
48 return CRYPT_BUFFER_OVERFLOW;
63 if (utctime->off_mm || utctime->off_hh) {
64 out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+');
65 STORE_V(utctime->off_hh);
66 STORE_V(utctime->off_mm);
68 out[x++] = der_ia5_char_encode('Z');
72 out[1] = (unsigned char)(x - 2);
74 /* all good let's return */
81 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c,v $ */
82 /* $Revision: 1.9 $ */
83 /* $Date: 2006/12/04 21:34:03 $ */