os/security/cryptoservices/certificateandkeymgmt/asn1/sequencedec.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/sequencedec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,100 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* This file contains the implementation of the ASN1 Sequence and Sequence-of 
    1.19 +* object, as described in X208 Sections 20 and 21 and X209 Sections 14 and 
    1.20 +* 15. The sequence object can contain an ordered series of zero, one or more
    1.21 +* other ASN1 objects. The sequence-of object contains zero, one or more of 
    1.22 +* the objects described in its definition. The data encodings of both these
    1.23 +* objects is identical. The ordering of the objects contained within the 
    1.24 +* sequence is defined outside the scope of this object, normally this would
    1.25 +* be handled by an object deriving from this object but it may be handled
    1.26 +* somewhere else. 
    1.27 +*
    1.28 +*/
    1.29 +
    1.30 +
    1.31 +#include "asn1dec.h"
    1.32 +
    1.33 +
    1.34 +void TASN1DecSequence::CleanupSequence(TAny* aArray)
    1.35 +	{
    1.36 +	CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
    1.37 +	array->ResetAndDestroy();
    1.38 +	delete array;
    1.39 +	}
    1.40 +
    1.41 +EXPORT_C TASN1DecSequence::TASN1DecSequence()
    1.42 +	{
    1.43 +	}
    1.44 +	
    1.45 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
    1.46 +
    1.47 +	{
    1.48 +	CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
    1.49 +	TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret);
    1.50 +	CleanupStack::PushL(cleanupSeq);
    1.51 +	TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos));
    1.52 +	gen.InitL();
    1.53 +	aPos += gen.LengthDER();
    1.54 +	DecodeContentsL(gen.GetContentDER(), *ret);
    1.55 +	return ret;
    1.56 +	}
    1.57 +
    1.58 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource)
    1.59 +	{
    1.60 +	CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
    1.61 +	TCleanupItem cleanupSeq(TASN1DecSequence::CleanupSequence, ret);
    1.62 +	CleanupStack::PushL(cleanupSeq);
    1.63 +	DecodeContentsL(aSource.GetContentDER(), *ret);
    1.64 +	return ret;
    1.65 +	}
    1.66 +
    1.67 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
    1.68 +
    1.69 +	{
    1.70 +	CArrayPtrFlat<TASN1DecGeneric>* ret = DecodeDERLC(aSource, aPos);
    1.71 +	TInt count = ret->Count();
    1.72 +	if ((count < aMin) || (count > aMax))
    1.73 +		{
    1.74 +		User::Leave(KErrArgument);
    1.75 +		}
    1.76 +	return ret;
    1.77 +	}
    1.78 +
    1.79 +EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSequence::DecodeDERLC(const TASN1DecGeneric& aSource, TInt aMin, TInt aMax)
    1.80 +	{
    1.81 +	CArrayPtrFlat<TASN1DecGeneric>* ret = DecodeDERLC(aSource);
    1.82 +	TInt count = ret->Count();
    1.83 +	if ((count < aMin) || (count > aMax))
    1.84 +		{
    1.85 +		User::Leave(KErrArgument);
    1.86 +		}
    1.87 +	return ret;
    1.88 +	}
    1.89 +
    1.90 +void TASN1DecSequence::DecodeContentsL(const TDesC8& aSource, CArrayPtrFlat<TASN1DecGeneric>& aDest)
    1.91 +	{
    1.92 +	TInt pos = 0;
    1.93 +	while (pos < aSource.Length())
    1.94 +		{
    1.95 +		TPtrC8 p(aSource.Right(aSource.Length() - pos));
    1.96 +		TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(p);
    1.97 +		CleanupStack::PushL(Decoded);
    1.98 +		Decoded->InitL();
    1.99 +		aDest.AppendL(Decoded);
   1.100 +		pos+=Decoded->LengthDER();
   1.101 +		CleanupStack::Pop();
   1.102 +		}
   1.103 +	}