os/security/cryptoservices/certificateandkeymgmt/pkcs10/pkcs10attr.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) 2002-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
* CPKCS10Attributes class implementation.
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
#include <e32def.h>
sl@0
    22
#include <asn1enc.h>
sl@0
    23
#include <pkcs10attr.h>
sl@0
    24
sl@0
    25
sl@0
    26
// CPKCS10AttributeBase /////////////////////////////////////////////////////////
sl@0
    27
sl@0
    28
CPKCSAttributeBase::CPKCSAttributeBase()
sl@0
    29
	{
sl@0
    30
	}
sl@0
    31
sl@0
    32
CPKCSAttributeBase::~CPKCSAttributeBase()
sl@0
    33
	{
sl@0
    34
	delete iRoot;
sl@0
    35
	}
sl@0
    36
sl@0
    37
CASN1EncBase* CPKCSAttributeBase::GetEncodingLC()
sl@0
    38
	{
sl@0
    39
	CASN1EncBase* result = iRoot;
sl@0
    40
	iRoot = NULL;
sl@0
    41
	iValueSet = NULL;
sl@0
    42
	CleanupStack::PushL(result);
sl@0
    43
	return result;
sl@0
    44
	}
sl@0
    45
sl@0
    46
// CPKCS10Attribute /////////////////////////////////////////////////////////
sl@0
    47
sl@0
    48
// This is being deprecated, will be removed
sl@0
    49
EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID)
sl@0
    50
	{
sl@0
    51
	CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute;
sl@0
    52
	CleanupStack::PushL(self);
sl@0
    53
	self->ConstructL(aAttrOID, NULL);
sl@0
    54
	return self;
sl@0
    55
	}
sl@0
    56
sl@0
    57
EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1)
sl@0
    58
	{
sl@0
    59
	if (aASN1 == NULL)
sl@0
    60
		{
sl@0
    61
		User::Leave(KErrArgument);
sl@0
    62
		}
sl@0
    63
	CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute;
sl@0
    64
	CleanupStack::PushL(self);
sl@0
    65
	self->ConstructL(aAttrOID, aASN1);
sl@0
    66
	return self;
sl@0
    67
	}
sl@0
    68
sl@0
    69
EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
sl@0
    70
	{
sl@0
    71
	CPKCS10Attribute* self = NewLC(aAttrOID, aASN1);
sl@0
    72
	CleanupStack::Pop(self);
sl@0
    73
	return self;
sl@0
    74
	}
sl@0
    75
sl@0
    76
EXPORT_C void CPKCS10Attribute::ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
sl@0
    77
	{
sl@0
    78
	if (aASN1 == NULL)
sl@0
    79
		{
sl@0
    80
		User::Leave(KErrArgument);
sl@0
    81
		}
sl@0
    82
	delete iRoot;
sl@0
    83
	iRoot = NULL;
sl@0
    84
	ConstructL(aAttrOID, aASN1);
sl@0
    85
	}
sl@0
    86
sl@0
    87
EXPORT_C void CPKCS10Attribute::AddValueL(CASN1EncBase* aASN1)
sl@0
    88
	{
sl@0
    89
	if (aASN1 == NULL)
sl@0
    90
		{
sl@0
    91
		User::Leave(KErrArgument);
sl@0
    92
		}
sl@0
    93
	iValueSet->AddChildL(aASN1);
sl@0
    94
	}
sl@0
    95
sl@0
    96
CPKCS10Attribute::CPKCS10Attribute()
sl@0
    97
	{
sl@0
    98
	}
sl@0
    99
sl@0
   100
CPKCS10Attribute::~CPKCS10Attribute()
sl@0
   101
	{
sl@0
   102
	}
sl@0
   103
sl@0
   104
void CPKCS10Attribute::ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1)
sl@0
   105
	{
sl@0
   106
	iRoot = CASN1EncSequence::NewL();
sl@0
   107
	CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(aAttrOID);
sl@0
   108
	iRoot->AddAndPopChildL(oid);
sl@0
   109
	iValueSet = CASN1EncSet::NewLC();
sl@0
   110
	iRoot->AddAndPopChildL(iValueSet);	// Takes ownership
sl@0
   111
sl@0
   112
	// For now just to allow for deprecated NewLC() which allows for NULL aASN1
sl@0
   113
	// Replace with call to AddValueL() once the quirky NewLC() is removed
sl@0
   114
	if (aASN1)
sl@0
   115
		{
sl@0
   116
		iValueSet->AddChildL(aASN1);
sl@0
   117
		}
sl@0
   118
	}
sl@0
   119
sl@0
   120
// Deprecated
sl@0
   121
CASN1EncBase* CPKCS10Attribute::TakeEncodingC()
sl@0
   122
	{
sl@0
   123
	return CPKCSAttributeBase::GetEncodingLC();
sl@0
   124
	}
sl@0
   125
sl@0
   126
// Deprecated
sl@0
   127
CASN1EncBase* CPKCS10Attribute::TakeEncodingLC()
sl@0
   128
	{
sl@0
   129
	return CPKCSAttributeBase::GetEncodingLC();
sl@0
   130
	}
sl@0
   131
sl@0
   132
CASN1EncBase* CPKCS10Attribute::GetEncodingLC()
sl@0
   133
	{
sl@0
   134
	return CPKCSAttributeBase::GetEncodingLC();
sl@0
   135
	}
sl@0
   136
sl@0
   137
sl@0
   138
// CPKCS10Attributes ///////////////////////////////////////////////////////////
sl@0
   139
sl@0
   140
CPKCS10Attributes::CPKCS10Attributes()
sl@0
   141
	{
sl@0
   142
	}
sl@0
   143
sl@0
   144
EXPORT_C CPKCS10Attributes::~CPKCS10Attributes()
sl@0
   145
	{
sl@0
   146
	delete iRoot;
sl@0
   147
	}
sl@0
   148
sl@0
   149
EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewLC()
sl@0
   150
	{
sl@0
   151
	CPKCS10Attributes* self = new (ELeave) CPKCS10Attributes();
sl@0
   152
	CleanupStack::PushL(self);
sl@0
   153
	self->ConstructL();
sl@0
   154
	return self;
sl@0
   155
	}
sl@0
   156
sl@0
   157
EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewL()
sl@0
   158
	{
sl@0
   159
	CPKCS10Attributes* self = NewLC();
sl@0
   160
	CleanupStack::Pop(self);
sl@0
   161
	return self;
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CPKCS10Attributes::ConstructL()
sl@0
   165
	{
sl@0
   166
	// Create top level ASN1 sequence
sl@0
   167
	iRoot = CASN1EncSequence::NewL();
sl@0
   168
	iRoot->SetTag(0);
sl@0
   169
	}
sl@0
   170
sl@0
   171
// To be deprecated
sl@0
   172
EXPORT_C void CPKCS10Attributes::AddAttributeL(CPKCS10Attribute* aAttr)
sl@0
   173
	{
sl@0
   174
	ASSERT(iRoot != NULL);
sl@0
   175
	ASSERT(aAttr != NULL);
sl@0
   176
	iRoot->AddAndPopChildL(aAttr->TakeEncodingLC());
sl@0
   177
	delete aAttr;
sl@0
   178
	}
sl@0
   179
sl@0
   180
EXPORT_C void CPKCS10Attributes::AddPKCSAttributeL(CPKCSAttributeBase* aAttr)
sl@0
   181
	{
sl@0
   182
	ASSERT(iRoot != NULL);
sl@0
   183
	if (aAttr == NULL)
sl@0
   184
		{
sl@0
   185
		User::Leave(KErrArgument);
sl@0
   186
		}
sl@0
   187
	iRoot->AddAndPopChildL(aAttr->GetEncodingLC());
sl@0
   188
	delete aAttr;
sl@0
   189
	}
sl@0
   190
sl@0
   191
CASN1EncBase* CPKCS10Attributes::TakeEncodingLC()
sl@0
   192
	{
sl@0
   193
	CASN1EncBase* result = iRoot;
sl@0
   194
 	iRoot = NULL;
sl@0
   195
	CleanupStack::PushL(result);
sl@0
   196
	return result;
sl@0
   197
	}