os/security/cryptoservices/certificateandkeymgmt/asn1/setdec.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    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
    21 * significant.
    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.
    26 *
    27 */
    28 
    29 
    30 #include "asn1dec.h"
    31 
    32 void TASN1DecSet::CleanupSet(TAny* aArray)
    33 	{
    34 	CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
    35 	array->ResetAndDestroy();
    36 	delete array;
    37 	}
    38 
    39 EXPORT_C TASN1DecSet::TASN1DecSet()
    40 	{
    41 	}
    42 
    43 
    44 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::NewDERLC(const TDesC8& aSource)
    45 // this whole things needs looking at!
    46 	{
    47 	TInt Pos=0;
    48 	CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
    49 	TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
    50 	CleanupStack::PushL(cleanupSeq);
    51 	TASN1DecGeneric gen(aSource);
    52 	gen.InitL();
    53 	DecodeContentsL(gen.GetContentDER(), Pos, *ret);
    54 	return ret;
    55 	}
    56 
    57 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
    58 
    59 	{
    60 	TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
    61 	return TASN1DecSet::NewDERLC(Ptr);
    62 	}
    63 
    64 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource)
    65 	{
    66 	TInt pos = 0;
    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);
    71 	return ret;
    72 	}
    73 
    74 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
    75 
    76 	{
    77 	CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource, aPos);
    78 	TInt count = res->Count();
    79 	if ((count < aMin) || (count > aMax))
    80 		{
    81 		User::Leave(KErrArgument);
    82 		}
    83 	return res;
    84 	}
    85 
    86 EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource,  TInt aMin, TInt aMax)
    87 	{
    88 	CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource);
    89 	TInt count = res->Count();
    90 	if ((count < aMin) || (count > aMax))
    91 		{
    92 		User::Leave(KErrArgument);
    93 		}
    94 	return res;
    95 	}
    96 
    97 void TASN1DecSet::DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest)
    98 	{
    99 	while (aPos < aSource.Length())
   100 		{
   101 		TPtrC8 Ptr=aSource.Right(aSource.Length() - aPos);
   102 		TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(Ptr);
   103 		CleanupStack::PushL(Decoded);
   104 		Decoded->InitL();
   105 		aDest.AppendL(Decoded);
   106 		aPos+=Decoded->LengthDER();
   107 		CleanupStack::Pop();//i think this should be just 'pop': need to find out
   108 		}
   109 	}
   110