|
1 /* |
|
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation for DER encoding of GeneralizedTime. |
|
16 * Following from the decoding class |
|
17 * 1) fractions of seconds are not supported |
|
18 * 2) regional time zone offsets are not supported |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #include "panic.h" |
|
24 |
|
25 #include <asn1enc.h> |
|
26 |
|
27 const TUint KEncodingLengthWithoutSeconds = 13; |
|
28 const TUint KEncodingLengthWithSeconds = 15; |
|
29 |
|
30 |
|
31 EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewLC(const TTime& aTime) |
|
32 { |
|
33 CASN1EncGeneralizedTime* self = new (ELeave) CASN1EncGeneralizedTime(aTime); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 return self; |
|
37 } |
|
38 |
|
39 EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewL(const TTime& aTime) |
|
40 { |
|
41 CASN1EncGeneralizedTime* self = NewLC(aTime); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CASN1EncGeneralizedTime::CASN1EncGeneralizedTime(const TTime& aTime) |
|
47 : CASN1EncPrimitive(EASN1GeneralizedTime), iDateTime(aTime.DateTime()) |
|
48 { |
|
49 __ASSERT_ALWAYS(iDateTime.Year() < 10000, Panic(KErrYearTooBigForGeneralizedTime)); |
|
50 } |
|
51 |
|
52 |
|
53 void CASN1EncGeneralizedTime::CalculateContentsLengthDER() |
|
54 { |
|
55 iContentsLengthDER = |
|
56 iDateTime.Second() ? KEncodingLengthWithSeconds : KEncodingLengthWithoutSeconds; |
|
57 } |
|
58 |
|
59 |
|
60 void CASN1EncGeneralizedTime::WriteContentsDERL(TDes8& aBuf) const |
|
61 { |
|
62 aBuf.SetLength(0); |
|
63 aBuf.AppendNumFixedWidth(iDateTime.Year(), EDecimal, 4); |
|
64 aBuf.AppendNumFixedWidth(iDateTime.Month() + 1, EDecimal, 2); // Our months are zero-based |
|
65 aBuf.AppendNumFixedWidth(iDateTime.Day() + 1, EDecimal, 2); // Our days are zero-based |
|
66 aBuf.AppendNumFixedWidth(iDateTime.Hour(), EDecimal, 2); |
|
67 aBuf.AppendNumFixedWidth(iDateTime.Minute(), EDecimal, 2); |
|
68 if (iDateTime.Second()) |
|
69 { |
|
70 aBuf.AppendNumFixedWidth(iDateTime.Second(), EDecimal, 2); |
|
71 } |
|
72 |
|
73 aBuf.Append('Z'); |
|
74 } |