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 Set and Set-of object,
16 * as described in X208 Sections 22 and 23 and X209 Sections 16 and 17. The
17 * set object can contain an ordered series of zero, one or more other ASN1
18 * objects. The set-of object contains zero, one or more of the objects
19 * described in its definition. The data encodings of both these objects is
20 * identical. The ordering of the elements contained within set objects is not
22 * The implementation of sets is pretty much the same as that for sequences
23 * (indeed it has started from a straight cut'n'paste) but there are some
24 * significant differences with regard to ordering of items within the set,
25 * comparison and retrieval of items.
32 void TASN1DecSet::CleanupSet(TAny* aArray)
34 CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
35 array->ResetAndDestroy();
39 EXPORT_C TASN1DecSet::TASN1DecSet()
44 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::NewDERLC(const TDesC8& aSource)
45 // this whole things needs looking at!
48 CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
49 TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
50 CleanupStack::PushL(cleanupSeq);
51 TASN1DecGeneric gen(aSource);
53 DecodeContentsL(gen.GetContentDER(), Pos, *ret);
57 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
60 TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
61 return TASN1DecSet::NewDERLC(Ptr);
64 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource)
67 CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
68 TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
69 CleanupStack::PushL(cleanupSeq);
70 DecodeContentsL(aSource.GetContentDER(), pos, *ret);
74 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
77 CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource, aPos);
78 TInt count = res->Count();
79 if ((count < aMin) || (count > aMax))
81 User::Leave(KErrArgument);
86 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax)
88 CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource);
89 TInt count = res->Count();
90 if ((count < aMin) || (count > aMax))
92 User::Leave(KErrArgument);
97 void TASN1DecSet::DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest)
99 while (aPos < aSource.Length())
101 TPtrC8 Ptr=aSource.Right(aSource.Length() - aPos);
102 TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(Ptr);
103 CleanupStack::PushL(Decoded);
105 aDest.AppendL(Decoded);
106 aPos+=Decoded->LengthDER();
107 CleanupStack::Pop();//i think this should be just 'pop': need to find out