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 Sequence and Sequence-of
16 * object, as described in X208 Sections 20 and 21 and X209 Sections 14 and
17 * 15. The sequence object can contain an ordered series of zero, one or more
18 * other ASN1 objects. The sequence-of object contains zero, one or more of
19 * the objects described in its definition. The data encodings of both these
20 * objects is identical. The ordering of the objects contained within the
21 * sequence is defined outside the scope of this object, normally this would
22 * be handled by an object deriving from this object but it may be handled
31 void TASN1DecSequence::CleanupSequence(TAny* aArray)
33 CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
34 array->ResetAndDestroy();
38 EXPORT_C TASN1DecSequence::TASN1DecSequence()
42 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
45 CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
46 TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret);
47 CleanupStack::PushL(cleanupSeq);
48 TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos));
50 aPos += gen.LengthDER();
51 DecodeContentsL(gen.GetContentDER(), *ret);
55 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource)
57 CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
58 TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret);
59 CleanupStack::PushL(cleanupSeq);
60 DecodeContentsL(aSource.GetContentDER(), *ret);
64 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
67 CArrayPtrFlat<TASN1DecGeneric>* ret = DecodeDERLC(aSource, aPos);
68 TInt count = ret->Count();
69 if ((count < aMin) || (count > aMax))
71 User::Leave(KErrArgument);
76 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax)
78 CArrayPtrFlat<TASN1DecGeneric>* ret = DecodeDERLC(aSource);
79 TInt count = ret->Count();
80 if ((count < aMin) || (count > aMax))
82 User::Leave(KErrArgument);
87 void TASN1DecSequence::DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat<TASN1DecGeneric>& aDest)
90 while (pos < aSource.Length())
92 TPtrC8 p(aSource.Right(aSource.Length() - pos));
93 TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(p);
94 CleanupStack::PushL(Decoded);
96 aDest.AppendL(Decoded);
97 pos+=Decoded->LengthDER();