sl@0: /* sl@0: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Implementation for DER encoding of GeneralizedTime. sl@0: * Following from the decoding class sl@0: * 1) fractions of seconds are not supported sl@0: * 2) regional time zone offsets are not supported sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "panic.h" sl@0: sl@0: #include sl@0: sl@0: const TUint KEncodingLengthWithoutSeconds = 13; sl@0: const TUint KEncodingLengthWithSeconds = 15; sl@0: sl@0: sl@0: EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewLC(const TTime& aTime) sl@0: { sl@0: CASN1EncGeneralizedTime* self = new (ELeave) CASN1EncGeneralizedTime(aTime); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CASN1EncGeneralizedTime* CASN1EncGeneralizedTime::NewL(const TTime& aTime) sl@0: { sl@0: CASN1EncGeneralizedTime* self = NewLC(aTime); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CASN1EncGeneralizedTime::CASN1EncGeneralizedTime(const TTime& aTime) sl@0: : CASN1EncPrimitive(EASN1GeneralizedTime), iDateTime(aTime.DateTime()) sl@0: { sl@0: __ASSERT_ALWAYS(iDateTime.Year() < 10000, Panic(KErrYearTooBigForGeneralizedTime)); sl@0: } sl@0: sl@0: sl@0: void CASN1EncGeneralizedTime::CalculateContentsLengthDER() sl@0: { sl@0: iContentsLengthDER = sl@0: iDateTime.Second() ? KEncodingLengthWithSeconds : KEncodingLengthWithoutSeconds; sl@0: } sl@0: sl@0: sl@0: void CASN1EncGeneralizedTime::WriteContentsDERL(TDes8& aBuf) const sl@0: { sl@0: aBuf.SetLength(0); sl@0: aBuf.AppendNumFixedWidth(iDateTime.Year(), EDecimal, 4); sl@0: aBuf.AppendNumFixedWidth(iDateTime.Month() + 1, EDecimal, 2); // Our months are zero-based sl@0: aBuf.AppendNumFixedWidth(iDateTime.Day() + 1, EDecimal, 2); // Our days are zero-based sl@0: aBuf.AppendNumFixedWidth(iDateTime.Hour(), EDecimal, 2); sl@0: aBuf.AppendNumFixedWidth(iDateTime.Minute(), EDecimal, 2); sl@0: if (iDateTime.Second()) sl@0: { sl@0: aBuf.AppendNumFixedWidth(iDateTime.Second(), EDecimal, 2); sl@0: } sl@0: sl@0: aBuf.Append('Z'); sl@0: }