sl@0: /* sl@0: * Copyright (c) 1998-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: * This file contains the implementation of the ASN1 Object ID base class. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "asn1dec.h" sl@0: sl@0: const TInt KMaxOIDLength = 164; sl@0: sl@0: EXPORT_C TASN1DecObjectIdentifier::TASN1DecObjectIdentifier(void) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C HBufC* TASN1DecObjectIdentifier::DecodeDERL(const TDesC8& aSource,TInt& aPos) sl@0: { sl@0: TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos)); sl@0: gen.InitL(); sl@0: HBufC* res = DecodeDERL(gen); sl@0: aPos+=gen.LengthDER(); sl@0: return res; sl@0: } sl@0: sl@0: EXPORT_C HBufC* TASN1DecObjectIdentifier::DecodeDERL(const TASN1DecGeneric& aSource) sl@0: { sl@0: TFixedArray* oid = new(ELeave) TFixedArray; sl@0: CleanupStack::PushL(oid); sl@0: TInt count = DecodeContentsL(*oid, aSource.GetContentDER()); sl@0: HBufC* res = HBufC::NewLC(KMaxOIDLength); sl@0: TPtr pRes = res->Des(); sl@0: if (count > 0) sl@0: { sl@0: pRes.AppendNum((*oid)[0]); sl@0: for (TInt i = 1; i < count; i++) sl@0: { sl@0: pRes.Append('.'); sl@0: pRes.AppendNum((*oid)[i]); sl@0: } sl@0: } sl@0: CleanupStack::Pop();//res sl@0: CleanupStack::PopAndDestroy();//oid sl@0: return res; sl@0: } sl@0: sl@0: TInt TASN1DecObjectIdentifier::DecodeContentsL(TFixedArray& aArray, const TDesC8& aSource) sl@0: { sl@0: TInt l = aSource.Length(); sl@0: TInt i=0; sl@0: TInt SubID=0; sl@0: TInt SIDn=0; sl@0: if(l < 1) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: SubID+=aSource[i]; sl@0: i++; sl@0: if (SubID>=80) sl@0: { sl@0: aArray[SIDn++]=2; sl@0: SubID-=80; sl@0: } sl@0: else sl@0: { sl@0: if (SubID>=40) sl@0: { sl@0: aArray[SIDn++]=1; sl@0: SubID-=40; sl@0: } sl@0: else sl@0: { sl@0: aArray[SIDn++]=0; sl@0: } sl@0: } sl@0: aArray[SIDn++]=SubID; sl@0: for (;i < l;) sl@0: { sl@0: SubID=0; sl@0: while (aSource[i]&0x80) sl@0: { sl@0: // if shifting by 7 does not increase the value its overflowed sl@0: if ( SubID && ((SubID << 7) <= SubID) ) sl@0: { sl@0: User::Leave(KErrOverflow); sl@0: } sl@0: sl@0: SubID<<=7; sl@0: SubID+=aSource[i]&0x7f; sl@0: if(i == (l-1)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: i++; sl@0: } sl@0: if ( SubID && ((SubID << 7) <= SubID) ) sl@0: { sl@0: User::Leave(KErrOverflow); sl@0: } sl@0: SubID<<=7; sl@0: SubID+=aSource[i]; sl@0: sl@0: i++; sl@0: if (SIDn >= KNumberOfIDs) sl@0: { sl@0: User::Leave(KErrOverflow); sl@0: } sl@0: aArray[SIDn++]=SubID; sl@0: } sl@0: return SIDn; sl@0: }