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 Sequence and Sequence-of sl@0: * object, as described in X208 Sections 20 and 21 and X209 Sections 14 and sl@0: * 15. The sequence object can contain an ordered series of zero, one or more sl@0: * other ASN1 objects. The sequence-of object contains zero, one or more of sl@0: * the objects described in its definition. The data encodings of both these sl@0: * objects is identical. The ordering of the objects contained within the sl@0: * sequence is defined outside the scope of this object, normally this would sl@0: * be handled by an object deriving from this object but it may be handled sl@0: * somewhere else. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "asn1dec.h" sl@0: sl@0: sl@0: void TASN1DecSequence::CleanupSequence(TAny* aArray) sl@0: { sl@0: CArrayPtrFlat* array = REINTERPRET_CAST(CArrayPtrFlat*, aArray); sl@0: array->ResetAndDestroy(); sl@0: delete array; sl@0: } sl@0: sl@0: EXPORT_C TASN1DecSequence::TASN1DecSequence() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos) sl@0: sl@0: { sl@0: CArrayPtrFlat* ret = new(ELeave) CArrayPtrFlat (1); sl@0: TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret); sl@0: CleanupStack::PushL(cleanupSeq); sl@0: TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos)); sl@0: gen.InitL(); sl@0: aPos += gen.LengthDER(); sl@0: DecodeContentsL(gen.GetContentDER(), *ret); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource) sl@0: { sl@0: CArrayPtrFlat* ret = new(ELeave) CArrayPtrFlat (1); sl@0: TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret); sl@0: CleanupStack::PushL(cleanupSeq); sl@0: DecodeContentsL(aSource.GetContentDER(), *ret); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax) sl@0: sl@0: { sl@0: CArrayPtrFlat* ret = DecodeDERLC(aSource, aPos); sl@0: TInt count = ret->Count(); sl@0: if ((count < aMin) || (count > aMax)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax) sl@0: { sl@0: CArrayPtrFlat* ret = DecodeDERLC(aSource); sl@0: TInt count = ret->Count(); sl@0: if ((count < aMin) || (count > aMax)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: void TASN1DecSequence::DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat& aDest) sl@0: { sl@0: TInt pos = 0; sl@0: while (pos < aSource.Length()) sl@0: { sl@0: TPtrC8 p(aSource.Right(aSource.Length() - pos)); sl@0: TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(p); sl@0: CleanupStack::PushL(Decoded); sl@0: Decoded->InitL(); sl@0: aDest.AppendL(Decoded); sl@0: pos+=Decoded->LengthDER(); sl@0: CleanupStack::Pop(); sl@0: } sl@0: }