First public contribution.
2 * Copyright (c) 1998-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 * This file contains the implementation of the UTC time ASN1 object.
16 * At this moment in time this class will only deal with Zulu times and
17 * doesn't have any kind of handling for time offsets. This is not going to be
18 * a problem for certificate implementations as the PKIX (RFC2459) profile
19 * defines that certificate validity periods are specified as Zulu times.
20 * Points that need updating if handling for offsets are marked with __OFFSET__
27 EXPORT_C TASN1DecUTCTime::TASN1DecUTCTime()
32 TTime TASN1DecUTCTime::GetTimeL(const TDesC8& aSource)
35 // __OFFSET__ Extract corrected time to include offset too.
37 // Did this checking ought to be done on creation rather than when we attempt to get the result?
40 // I guess we ought to check that the contents we've got are long enough to contain a time!
41 if (aSource.Length()<11)
43 User::Leave(KErrArgument);
46 // Check all digits the main bit of time are valid - this doesn't check the seconds or offset
51 j=(TUint8)(aSource[i]-'0');
54 User::Leave(KErrArgument);
57 // Uh-oh, looks like we're going to have to pull each bit manually and pop it in a TDateTime thing
58 TInt Year,Month,Day,Hour,Minute,Second=0; // Only set seconds to zero 'cos they are optional, everything else is going to be set
59 Year=(aSource[0]-'0')*10+aSource[1]-'0';
60 Year+=(Year<50)?2000:1900; // collection to fit with PKIX UTC/Generalised time rollover at 2049/2050
61 Month=(aSource[2]-'0')*10+aSource[3]-'0';
62 Month--; // Because the enum for months starts at 0 not 1
63 Day=((aSource[4]-'0')*10+aSource[5]-'0') -1;//added -1 for offset from zero(!)
64 Hour=(aSource[6]-'0')*10+aSource[7]-'0';
65 Minute=(aSource[8]-'0')*10+aSource[9]-'0';
68 if (aSource.Length()>11)
70 if ((aSource[Pos]>='0')&&(aSource[Pos]<='9'))
73 Second=(aSource[Pos++]-'0')*10;
74 Second += aSource[Pos++]-'0';
77 if (aSource.Length()>Pos)
82 // Zulu - nothing more to do
86 // __OFFSET__ Extract corrected time to include offset too.
87 User::Leave(KErrNotSupported);
91 User::Leave(KErrArgument);
97 User::Leave(KErrArgument);
100 if (Month<EJanuary || Month>EDecember)
102 User::Leave(KErrArgument);
104 TMonth month = (TMonth)Month;
106 if ( (Day<0 || Day>=Time::DaysInMonth(Year,month)) ||
107 (Hour<0 || Hour>=24) ||
108 (Minute<0 || Minute>=60) ||
109 (Second<0 || Second>=60) )
111 User::Leave(KErrArgument);
114 TDateTime D(Year,month,Day,Hour,Minute,Second,0);
120 // __OFFSET__ Add GetOffset() method
122 EXPORT_C TTime TASN1DecUTCTime::DecodeDERL(const TDesC8& aSource,TInt& aPos)
125 TPtrC8 Source=aSource.Mid(aPos);
126 TASN1DecGeneric gen(Source);
128 TTime t = GetTimeL(gen.GetContentDER());
129 aPos+=gen.LengthDER();
133 EXPORT_C TTime TASN1DecUTCTime::DecodeDERL(const TASN1DecGeneric& aGen)
136 return GetTimeL(aGen.GetContentDER());