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 ASN1 Object ID base class.
22 const TInt KMaxOIDLength = 164;
24 EXPORT_C TASN1DecObjectIdentifier::TASN1DecObjectIdentifier(void)
28 EXPORT_C HBufC* TASN1DecObjectIdentifier::DecodeDERL(const TDesC8& aSource,TInt& aPos)
30 TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos));
32 HBufC* res = DecodeDERL(gen);
33 aPos+=gen.LengthDER();
37 EXPORT_C HBufC* TASN1DecObjectIdentifier::DecodeDERL(const TASN1DecGeneric& aSource)
39 TFixedArray<TInt, KNumberOfIDs>* oid = new(ELeave) TFixedArray<TInt, KNumberOfIDs>;
40 CleanupStack::PushL(oid);
41 TInt count = DecodeContentsL(*oid, aSource.GetContentDER());
42 HBufC* res = HBufC::NewLC(KMaxOIDLength);
43 TPtr pRes = res->Des();
46 pRes.AppendNum((*oid)[0]);
47 for (TInt i = 1; i < count; i++)
50 pRes.AppendNum((*oid)[i]);
53 CleanupStack::Pop();//res
54 CleanupStack::PopAndDestroy();//oid
58 TInt TASN1DecObjectIdentifier::DecodeContentsL(TFixedArray<TInt, KNumberOfIDs>& aArray, const TDesC8& aSource)
60 TInt l = aSource.Length();
66 User::Leave(KErrArgument);
91 while (aSource[i]&0x80)
93 // if shifting by 7 does not increase the value its overflowed
94 if ( SubID && ((SubID << 7) <= SubID) )
96 User::Leave(KErrOverflow);
100 SubID+=aSource[i]&0x7f;
103 User::Leave(KErrArgument);
107 if ( SubID && ((SubID << 7) <= SubID) )
109 User::Leave(KErrOverflow);
115 if (SIDn >= KNumberOfIDs)
117 User::Leave(KErrOverflow);
119 aArray[SIDn++]=SubID;