First public contribution.
2 * Copyright (c) 1997-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.
22 #define WTLS_UNIX_BASE TTime(MAKE_TINT64(0x00dcddb3,0x0f2f8000)) // 00:00, Jan 1st 1970
23 const TInt KTimeLength = 4;
26 TWTLSDecVector::TWTLSDecVector(const TDesC8& aSource, TInt aMinLength, TInt aMaxLength)
27 :iEncoding(aSource), iMinLength(aMinLength), iMaxLength(aMaxLength), iLengthOfContents(0), iLengthOfLength(0)
31 void TWTLSDecVector::InitL()
33 if (iMaxLength <= 255)
39 if (iMaxLength <= 65535)
45 if (iMaxLength <= 16777215)
55 if (iEncoding.Length() < (iLengthOfLength + iMinLength))
57 User::Leave(KErrArgument);
59 TWTLSDecUnsignedInteger decLength;
61 iLengthOfContents = decLength.DecodeShortL(iEncoding, pos, iLengthOfLength);
62 if (iEncoding.Length() < (iLengthOfLength + iLengthOfContents))
64 User::Leave(KErrArgument);
68 TPtrC8 TWTLSDecVector::Encoding() const
70 return iEncoding.Left(EncodingLength());
73 TInt TWTLSDecVector::EncodingLength() const
75 return iLengthOfLength + iLengthOfContents;
78 TPtrC8 TWTLSDecVector::Content() const
80 return iEncoding.Mid(iLengthOfLength, iLengthOfContents);
83 TInt TWTLSDecVector::ContentLength() const
85 return iLengthOfContents;
88 TInt TWTLSDecVector::HeaderLength() const
90 return iLengthOfLength;
93 TWTLSDecUnsignedInteger::TWTLSDecUnsignedInteger()
97 TInt TWTLSDecUnsignedInteger::DecodeShortL(const TDesC8& aSource,TInt& aPos, TInt aLength)
101 User::Leave(KErrOverflow);
103 TInt sourceLength = aSource.Length();
107 if (sourceLength <= aPos)
109 User::Leave(KErrArgument);
112 res+=aSource[aPos++];
118 RInteger TWTLSDecUnsignedInteger::DecodeLongL(const TDesC8& aSource,TInt& aPos, TInt aLength)
120 if (aSource.Length() < (aPos + aLength))
122 User::Leave(KErrArgument);
124 const TPtrC8 ptr = aSource.Mid(aPos, aLength);
126 RInteger res = RInteger::NewL(ptr);
131 TWTLSDecTime::TWTLSDecTime()
135 TTime TWTLSDecTime::DecodeL(const TDesC8& aSource, TInt& aPos)
137 if ((aSource.Length() - aPos) < KTimeLength)
139 User::Leave(KErrArgument);
141 TWTLSDecUnsignedInteger decInt;
142 TInt inc = decInt.DecodeShortL(aSource, aPos, 4);
143 return WTLS_UNIX_BASE + TTimeIntervalSeconds(inc);