First public contribution.
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
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
27 const TUint KEncodingLengthWithoutSeconds = 13;
28 const TUint KEncodingLengthWithSeconds = 15;
31 EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewLC(const TTime& aTime)
33 CASN1EncGeneralizedTime* self = new (ELeave) CASN1EncGeneralizedTime(aTime);
34 CleanupStack::PushL(self);
39 EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewL(const TTime& aTime)
41 CASN1EncGeneralizedTime* self = NewLC(aTime);
42 CleanupStack::Pop(self);
46 CASN1EncGeneralizedTime::CASN1EncGeneralizedTime(const TTime& aTime)
47 : CASN1EncPrimitive(EASN1GeneralizedTime), iDateTime(aTime.DateTime())
49 __ASSERT_ALWAYS(iDateTime.Year() < 10000, Panic(KErrYearTooBigForGeneralizedTime));
53 void CASN1EncGeneralizedTime::CalculateContentsLengthDER()
56 iDateTime.Second() ? KEncodingLengthWithSeconds : KEncodingLengthWithoutSeconds;
60 void CASN1EncGeneralizedTime::WriteContentsDERL(TDes8& aBuf) const
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())
70 aBuf.AppendNumFixedWidth(iDateTime.Second(), EDecimal, 2);