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
12 @file der_encode_utctime.c
13 ASN.1 DER, encode a UTCTIME, Tom St Denis
18 static const char * const baseten = "0123456789";
21 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
22 out[x++] = der_ia5_char_encode(baseten[y % 10]);
25 Encodes a UTC time structure in DER format
26 @param utctime The UTC time structure to encode
27 @param out The destination of the DER encoding of the UTC time structure
28 @param outlen [in/out] The length of the DER encoding
29 @return CRYPT_OK if successful
31 int der_encode_utctime(ltc_utctime *utctime,
32 unsigned char *out, unsigned long *outlen)
34 unsigned long x, tmplen;
37 LTC_ARGCHK(utctime != NULL);
38 LTC_ARGCHK(out != NULL);
39 LTC_ARGCHK(outlen != NULL);
41 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) {
44 if (tmplen > *outlen) {
46 return CRYPT_BUFFER_OVERFLOW;
61 if (utctime->off_mm || utctime->off_hh) {
62 out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+');
63 STORE_V(utctime->off_hh);
64 STORE_V(utctime->off_mm);
66 out[x++] = der_ia5_char_encode('Z');
70 out[1] = (unsigned char)(x - 2);
72 /* all good let's return */
79 /* ref: $Format:%D$ */
80 /* git commit: $Format:%H$ */
81 /* commit time: $Format:%ai$ */