os/security/cryptoservices/certificateandkeymgmt/pkcs10/pkcs10attr.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs10/pkcs10attr.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,197 @@
     1.4 +/*
     1.5 +* Copyright (c) 2002-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 +* CPKCS10Attributes class implementation.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#include <e32std.h>
    1.24 +#include <e32def.h>
    1.25 +#include <asn1enc.h>
    1.26 +#include <pkcs10attr.h>
    1.27 +
    1.28 +
    1.29 +// CPKCS10AttributeBase /////////////////////////////////////////////////////////
    1.30 +
    1.31 +CPKCSAttributeBase::CPKCSAttributeBase()
    1.32 +	{
    1.33 +	}
    1.34 +
    1.35 +CPKCSAttributeBase::~CPKCSAttributeBase()
    1.36 +	{
    1.37 +	delete iRoot;
    1.38 +	}
    1.39 +
    1.40 +CASN1EncBase* CPKCSAttributeBase::GetEncodingLC()
    1.41 +	{
    1.42 +	CASN1EncBase* result = iRoot;
    1.43 +	iRoot = NULL;
    1.44 +	iValueSet = NULL;
    1.45 +	CleanupStack::PushL(result);
    1.46 +	return result;
    1.47 +	}
    1.48 +
    1.49 +// CPKCS10Attribute /////////////////////////////////////////////////////////
    1.50 +
    1.51 +// This is being deprecated, will be removed
    1.52 +EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID)
    1.53 +	{
    1.54 +	CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute;
    1.55 +	CleanupStack::PushL(self);
    1.56 +	self->ConstructL(aAttrOID, NULL);
    1.57 +	return self;
    1.58 +	}
    1.59 +
    1.60 +EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1)
    1.61 +	{
    1.62 +	if (aASN1 == NULL)
    1.63 +		{
    1.64 +		User::Leave(KErrArgument);
    1.65 +		}
    1.66 +	CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute;
    1.67 +	CleanupStack::PushL(self);
    1.68 +	self->ConstructL(aAttrOID, aASN1);
    1.69 +	return self;
    1.70 +	}
    1.71 +
    1.72 +EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
    1.73 +	{
    1.74 +	CPKCS10Attribute* self = NewLC(aAttrOID, aASN1);
    1.75 +	CleanupStack::Pop(self);
    1.76 +	return self;
    1.77 +	}
    1.78 +
    1.79 +EXPORT_C void CPKCS10Attribute::ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
    1.80 +	{
    1.81 +	if (aASN1 == NULL)
    1.82 +		{
    1.83 +		User::Leave(KErrArgument);
    1.84 +		}
    1.85 +	delete iRoot;
    1.86 +	iRoot = NULL;
    1.87 +	ConstructL(aAttrOID, aASN1);
    1.88 +	}
    1.89 +
    1.90 +EXPORT_C void CPKCS10Attribute::AddValueL(CASN1EncBase* aASN1)
    1.91 +	{
    1.92 +	if (aASN1 == NULL)
    1.93 +		{
    1.94 +		User::Leave(KErrArgument);
    1.95 +		}
    1.96 +	iValueSet->AddChildL(aASN1);
    1.97 +	}
    1.98 +
    1.99 +CPKCS10Attribute::CPKCS10Attribute()
   1.100 +	{
   1.101 +	}
   1.102 +
   1.103 +CPKCS10Attribute::~CPKCS10Attribute()
   1.104 +	{
   1.105 +	}
   1.106 +
   1.107 +void CPKCS10Attribute::ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
   1.108 +	{
   1.109 +	iRoot = CASN1EncSequence::NewL();
   1.110 +	CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(aAttrOID);
   1.111 +	iRoot->AddAndPopChildL(oid);
   1.112 +	iValueSet = CASN1EncSet::NewLC();
   1.113 +	iRoot->AddAndPopChildL(iValueSet);	// Takes ownership
   1.114 +
   1.115 +	// For now just to allow for deprecated NewLC() which allows for NULL aASN1
   1.116 +	// Replace with call to AddValueL() once the quirky NewLC() is removed
   1.117 +	if (aASN1)
   1.118 +		{
   1.119 +		iValueSet->AddChildL(aASN1);
   1.120 +		}
   1.121 +	}
   1.122 +
   1.123 +// Deprecated
   1.124 +CASN1EncBase* CPKCS10Attribute::TakeEncodingC()
   1.125 +	{
   1.126 +	return CPKCSAttributeBase::GetEncodingLC();
   1.127 +	}
   1.128 +
   1.129 +// Deprecated
   1.130 +CASN1EncBase* CPKCS10Attribute::TakeEncodingLC()
   1.131 +	{
   1.132 +	return CPKCSAttributeBase::GetEncodingLC();
   1.133 +	}
   1.134 +
   1.135 +CASN1EncBase* CPKCS10Attribute::GetEncodingLC()
   1.136 +	{
   1.137 +	return CPKCSAttributeBase::GetEncodingLC();
   1.138 +	}
   1.139 +
   1.140 +
   1.141 +// CPKCS10Attributes ///////////////////////////////////////////////////////////
   1.142 +
   1.143 +CPKCS10Attributes::CPKCS10Attributes()
   1.144 +	{
   1.145 +	}
   1.146 +
   1.147 +EXPORT_C CPKCS10Attributes::~CPKCS10Attributes()
   1.148 +	{
   1.149 +	delete iRoot;
   1.150 +	}
   1.151 +
   1.152 +EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewLC()
   1.153 +	{
   1.154 +	CPKCS10Attributes* self = new (ELeave) CPKCS10Attributes();
   1.155 +	CleanupStack::PushL(self);
   1.156 +	self->ConstructL();
   1.157 +	return self;
   1.158 +	}
   1.159 +
   1.160 +EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewL()
   1.161 +	{
   1.162 +	CPKCS10Attributes* self = NewLC();
   1.163 +	CleanupStack::Pop(self);
   1.164 +	return self;
   1.165 +	}
   1.166 +
   1.167 +void CPKCS10Attributes::ConstructL()
   1.168 +	{
   1.169 +	// Create top level ASN1 sequence
   1.170 +	iRoot = CASN1EncSequence::NewL();
   1.171 +	iRoot->SetTag(0);
   1.172 +	}
   1.173 +
   1.174 +// To be deprecated
   1.175 +EXPORT_C void CPKCS10Attributes::AddAttributeL(CPKCS10Attribute* aAttr)
   1.176 +	{
   1.177 +	ASSERT(iRoot != NULL);
   1.178 +	ASSERT(aAttr != NULL);
   1.179 +	iRoot->AddAndPopChildL(aAttr->TakeEncodingLC());
   1.180 +	delete aAttr;
   1.181 +	}
   1.182 +
   1.183 +EXPORT_C void CPKCS10Attributes::AddPKCSAttributeL(CPKCSAttributeBase* aAttr)
   1.184 +	{
   1.185 +	ASSERT(iRoot != NULL);
   1.186 +	if (aAttr == NULL)
   1.187 +		{
   1.188 +		User::Leave(KErrArgument);
   1.189 +		}
   1.190 +	iRoot->AddAndPopChildL(aAttr->GetEncodingLC());
   1.191 +	delete aAttr;
   1.192 +	}
   1.193 +
   1.194 +CASN1EncBase* CPKCS10Attributes::TakeEncodingLC()
   1.195 +	{
   1.196 +	CASN1EncBase* result = iRoot;
   1.197 + 	iRoot = NULL;
   1.198 +	CleanupStack::PushL(result);
   1.199 +	return result;
   1.200 +	}