os/security/cryptoservices/certificateandkeymgmt/pkcs12/pkcs12attribute.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-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 *
    16 */
    17 
    18 
    19 #include "pkcs12attribute.h"
    20 
    21 using namespace PKCS12;
    22 
    23 CDecPkcs12Attribute::CDecPkcs12Attribute()
    24 	{
    25 	}
    26 	
    27 EXPORT_C CDecPkcs12Attribute* CDecPkcs12Attribute::NewL(const TDesC8& aBagAttributes)
    28 	{
    29 	CDecPkcs12Attribute* self = new (ELeave) CDecPkcs12Attribute;
    30     CleanupStack::PushL(self);
    31 	self->ConstructL(aBagAttributes);
    32 	CleanupStack::Pop(self);
    33 	return self;	
    34 	}
    35 
    36 CDecPkcs12Attribute::~CDecPkcs12Attribute()
    37 	{
    38 	delete iAttributeId;	
    39 	iAttributeValue.ResetAndDestroy();
    40 	iAttributeValue.Close();
    41 	}
    42 	
    43 void CDecPkcs12Attribute::ConstructL(const TDesC8& aBagAttributes)
    44 	{
    45 	TASN1DecGeneric seqGen(aBagAttributes);
    46 	seqGen.InitL();
    47 	
    48 	// Check if this is a Sequence
    49 	if (seqGen.Tag() != EASN1Sequence || seqGen.Class() != EUniversal)
    50 		{
    51 		User::Leave(KErrArgument);
    52 		}
    53 	
    54 	TASN1DecSequence seq;
    55 	CArrayPtrFlat<TASN1DecGeneric>* attributeSet = seq.DecodeDERLC(seqGen);
    56 	const TASN1DecGeneric* attributeSetAt0 = attributeSet->At(0);
    57 	if(attributeSetAt0->Tag() != EASN1ObjectIdentifier || attributeSetAt0->Class() != EUniversal)
    58 		{
    59 		User::Leave(KErrArgument);
    60 		}
    61 		
    62 	// Decode the ObjectIdentifier
    63 	TASN1DecObjectIdentifier oid;
    64 	iAttributeId = oid.DecodeDERL(*attributeSetAt0); 
    65 	 
    66 	const TASN1DecGeneric* attributeSetAt1 = attributeSet->At(1);
    67 	if(attributeSetAt1->Tag() != EASN1Set || attributeSetAt1->Class() != EUniversal)
    68 		{
    69 		User::Leave(KErrArgument);
    70 		}
    71 			
    72 	// Attribute Set
    73 	TASN1DecSet decSet;
    74     CArrayPtrFlat<TASN1DecGeneric>* attributeValues = decSet.NewDERLC(attributeSetAt1->Encoding());
    75     
    76     TInt attributeCount = attributeValues->Count();
    77 		    
    78     for(TInt index = 0; index < attributeCount; ++index)         
    79 	   	{
    80 	   	const TASN1DecGeneric* attributeValuesAt = attributeValues->At(index);
    81 		TASN1DecGeneric seqGen(*attributeValuesAt);
    82 		seqGen.InitL();
    83 		TPtrC8 attrValue = seqGen.Encoding();
    84 		TDesC8* attributeVal = attrValue.AllocL();
    85 		CleanupStack::PushL(attributeVal);
    86 		iAttributeValue.AppendL(attributeVal);
    87 		CleanupStack::Pop(attributeVal);
    88 	   	}
    89     CleanupStack::PopAndDestroy(2,attributeSet); // attributeSet,attributeValues    
    90 	}	
    91 		
    92 	
    93 EXPORT_C const TDesC& CDecPkcs12Attribute::AttributeId() const
    94 	{
    95 	return *iAttributeId;	
    96 	}
    97 	
    98 EXPORT_C const RPointerArray<TDesC8>& CDecPkcs12Attribute::AttributeValue() const
    99 	{
   100 	return iAttributeValue;	
   101 	}
   102