comparison libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c @ 302:973fccb59ea4 ucc-axis-hack

propagate from branch 'au.asn.ucc.matt.dropbear' (head 11034278bd1917bebcbdc69cf53b1891ce9db121) to branch 'au.asn.ucc.matt.dropbear.ucc-axis-hack' (head 10a1f614fec73d0820c3f61160d9db409b9beb46)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:59:58 +0000
parents 1b9e69c058d2
children 0cbe8f6dbf9e
comparison
equal deleted inserted replaced
299:740e782679be 302:973fccb59ea4
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 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11 #include "tomcrypt.h"
12
13 /**
14 @file der_encode_utctime.c
15 ASN.1 DER, encode a UTCTIME, Tom St Denis
16 */
17
18 #ifdef LTC_DER
19
20 static const char *baseten = "0123456789";
21
22 #define STORE_V(y) \
23 out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
24 out[x++] = der_ia5_char_encode(baseten[y % 10]);
25
26 /**
27 Gets length of DER encoding of UTCTIME
28 @param outlen [out] The length of the DER encoding
29 @return CRYPT_OK if successful
30 */
31 int der_encode_utctime(ltc_utctime *utctime,
32 unsigned char *out, unsigned long *outlen)
33 {
34 unsigned long x, tmplen;
35 int err;
36
37 LTC_ARGCHK(utctime != NULL);
38 LTC_ARGCHK(out != NULL);
39 LTC_ARGCHK(outlen != NULL);
40
41 if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) {
42 return err;
43 }
44 if (tmplen > *outlen) {
45 return CRYPT_BUFFER_OVERFLOW;
46 }
47
48 /* store header */
49 out[0] = 0x17;
50
51 /* store values */
52 x = 2;
53 STORE_V(utctime->YY);
54 STORE_V(utctime->MM);
55 STORE_V(utctime->DD);
56 STORE_V(utctime->hh);
57 STORE_V(utctime->mm);
58 STORE_V(utctime->ss);
59
60 if (utctime->off_mm || utctime->off_hh) {
61 out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+');
62 STORE_V(utctime->off_hh);
63 STORE_V(utctime->off_mm);
64 } else {
65 out[x++] = der_ia5_char_encode('Z');
66 }
67
68 /* store length */
69 out[1] = x - 2;
70
71 /* all good let's return */
72 *outlen = x;
73 return CRYPT_OK;
74 }
75
76 #endif
77
78 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c,v $ */
79 /* $Revision: 1.5 $ */
80 /* $Date: 2005/06/19 12:07:00 $ */