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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* This file contains the implementation of the ASN1 Set and Set-of object, 
sl@0
    16
* as described in X208 Sections 22 and 23 and X209 Sections 16 and 17. The 
sl@0
    17
* set object can contain an ordered series of zero, one or more other ASN1 
sl@0
    18
* objects. The set-of object contains zero, one or more of the objects 
sl@0
    19
* described in its definition. The data encodings of both these objects is 
sl@0
    20
* identical. The ordering of the elements contained within set objects is not
sl@0
    21
* significant.
sl@0
    22
* The implementation of sets is pretty much the same as that for sequences 
sl@0
    23
* (indeed it has started from a straight cut'n'paste) but there are some 
sl@0
    24
* significant differences with regard to ordering of items within the set,
sl@0
    25
* comparison and retrieval of items.
sl@0
    26
*
sl@0
    27
*/
sl@0
    28
sl@0
    29
sl@0
    30
#include "asn1dec.h"
sl@0
    31
sl@0
    32
void TASN1DecSet::CleanupSet(TAny* aArray)
sl@0
    33
	{
sl@0
    34
	CArrayPtrFlat<TASN1DecGeneric>* array = REINTERPRET_CAST(CArrayPtrFlat<TASN1DecGeneric>*, aArray);
sl@0
    35
	array->ResetAndDestroy();
sl@0
    36
	delete array;
sl@0
    37
	}
sl@0
    38
sl@0
    39
EXPORT_C TASN1DecSet::TASN1DecSet()
sl@0
    40
	{
sl@0
    41
	}
sl@0
    42
sl@0
    43
sl@0
    44
EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::NewDERLC(const TDesC8& aSource)
sl@0
    45
// this whole things needs looking at!
sl@0
    46
	{
sl@0
    47
	TInt Pos=0;
sl@0
    48
	CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
sl@0
    49
	TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
sl@0
    50
	CleanupStack::PushL(cleanupSeq);
sl@0
    51
	TASN1DecGeneric gen(aSource);
sl@0
    52
	gen.InitL();
sl@0
    53
	DecodeContentsL(gen.GetContentDER(), Pos, *ret);
sl@0
    54
	return ret;
sl@0
    55
	}
sl@0
    56
sl@0
    57
EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos)
sl@0
    58
sl@0
    59
	{
sl@0
    60
	TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
sl@0
    61
	return TASN1DecSet::NewDERLC(Ptr);
sl@0
    62
	}
sl@0
    63
sl@0
    64
EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource)
sl@0
    65
	{
sl@0
    66
	TInt pos = 0;
sl@0
    67
	CArrayPtrFlat<TASN1DecGeneric>* ret = new(ELeave) CArrayPtrFlat<TASN1DecGeneric> (1);
sl@0
    68
	TCleanupItem cleanupSeq(TASN1DecSet::CleanupSet, ret);
sl@0
    69
	CleanupStack::PushL(cleanupSeq);
sl@0
    70
	DecodeContentsL(aSource.GetContentDER(), pos, *ret);
sl@0
    71
	return ret;
sl@0
    72
	}
sl@0
    73
sl@0
    74
EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TDesC8& aSource,TInt& aPos, TInt aMin, TInt aMax)
sl@0
    75
sl@0
    76
	{
sl@0
    77
	CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource, aPos);
sl@0
    78
	TInt count = res->Count();
sl@0
    79
	if ((count < aMin) || (count > aMax))
sl@0
    80
		{
sl@0
    81
		User::Leave(KErrArgument);
sl@0
    82
		}
sl@0
    83
	return res;
sl@0
    84
	}
sl@0
    85
sl@0
    86
EXPORT_C CArrayPtrFlat<TASN1DecGeneric>* TASN1DecSet::DecodeDERLC(const TASN1DecGeneric& aSource,  TInt aMin, TInt aMax)
sl@0
    87
	{
sl@0
    88
	CArrayPtrFlat<TASN1DecGeneric>* res = DecodeDERLC(aSource);
sl@0
    89
	TInt count = res->Count();
sl@0
    90
	if ((count < aMin) || (count > aMax))
sl@0
    91
		{
sl@0
    92
		User::Leave(KErrArgument);
sl@0
    93
		}
sl@0
    94
	return res;
sl@0
    95
	}
sl@0
    96
sl@0
    97
void TASN1DecSet::DecodeContentsL(const TDesC8& aSource, TInt& aPos, CArrayPtrFlat<TASN1DecGeneric>& aDest)
sl@0
    98
	{
sl@0
    99
	while (aPos < aSource.Length())
sl@0
   100
		{
sl@0
   101
		TPtrC8 Ptr=aSource.Right(aSource.Length() - aPos);
sl@0
   102
		TASN1DecGeneric* Decoded = new(ELeave) TASN1DecGeneric(Ptr);
sl@0
   103
		CleanupStack::PushL(Decoded);
sl@0
   104
		Decoded->InitL();
sl@0
   105
		aDest.AppendL(Decoded);
sl@0
   106
		aPos+=Decoded->LengthDER();
sl@0
   107
		CleanupStack::Pop();//i think this should be just 'pop': need to find out
sl@0
   108
		}
sl@0
   109
	}
sl@0
   110