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 Set and Set-of object, sl@0: * as described in X208 Sections 22 and 23 and X209 Sections 16 and 17. The sl@0: * set object can contain an ordered series of zero, one or more other ASN1 sl@0: * objects. The set-of object contains zero, one or more of the objects sl@0: * described in its definition. The data encodings of both these objects is sl@0: * identical. The ordering of the elements contained within set objects is not sl@0: * significant. sl@0: * The implementation of sets is pretty much the same as that for sequences sl@0: * (indeed it has started from a straight cut'n'paste) but there are some sl@0: * significant differences with regard to ordering of items within the set, sl@0: * comparison and retrieval of items. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "asn1dec.h" sl@0: sl@0: void TASN1DecSet::CleanupSet(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 TASN1DecSet::TASN1DecSet() sl@0: { sl@0: } sl@0: sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSet::NewDERLC(const TDesC8& aSource) sl@0: // this whole things needs looking at! sl@0: { sl@0: TInt Pos=0; sl@0: CArrayPtrFlat* ret = new(ELeave) CArrayPtrFlat (1); sl@0: TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret); sl@0: CleanupStack::PushL(cleanupSeq); sl@0: TASN1DecGeneric gen(aSource); sl@0: gen.InitL(); sl@0: DecodeContentsL(gen.GetContentDER(), Pos, *ret); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos) sl@0: sl@0: { sl@0: TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos); sl@0: return TASN1DecSet::NewDERLC(Ptr); sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource) sl@0: { sl@0: TInt pos = 0; sl@0: CArrayPtrFlat* ret = new(ELeave) CArrayPtrFlat (1); sl@0: TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret); sl@0: CleanupStack::PushL(cleanupSeq); sl@0: DecodeContentsL(aSource.GetContentDER(), pos, *ret); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax) sl@0: sl@0: { sl@0: CArrayPtrFlat* res = DecodeDERLC(aSource, aPos); sl@0: TInt count = res->Count(); sl@0: if ((count < aMin) || (count > aMax)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return res; sl@0: } sl@0: sl@0: EXPORT_C CArrayPtrFlat* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax) sl@0: { sl@0: CArrayPtrFlat* res = DecodeDERLC(aSource); sl@0: TInt count = res->Count(); sl@0: if ((count < aMin) || (count > aMax)) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return res; sl@0: } sl@0: sl@0: void TASN1DecSet::DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat& aDest) sl@0: { sl@0: while (aPos < aSource.Length()) sl@0: { sl@0: TPtrC8 Ptr=aSource.Right(aSource.Length() - aPos); sl@0: TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(Ptr); sl@0: CleanupStack::PushL(Decoded); sl@0: Decoded->InitL(); sl@0: aDest.AppendL(Decoded); sl@0: aPos+=Decoded->LengthDER(); sl@0: CleanupStack::Pop();//i think this should be just 'pop': need to find out sl@0: } sl@0: } sl@0: