sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * CPKCS10Attributes class implementation. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: // CPKCS10AttributeBase ///////////////////////////////////////////////////////// sl@0: sl@0: CPKCSAttributeBase::CPKCSAttributeBase() sl@0: { sl@0: } sl@0: sl@0: CPKCSAttributeBase::~CPKCSAttributeBase() sl@0: { sl@0: delete iRoot; sl@0: } sl@0: sl@0: CASN1EncBase* CPKCSAttributeBase::GetEncodingLC() sl@0: { sl@0: CASN1EncBase* result = iRoot; sl@0: iRoot = NULL; sl@0: iValueSet = NULL; sl@0: CleanupStack::PushL(result); sl@0: return result; sl@0: } sl@0: sl@0: // CPKCS10Attribute ///////////////////////////////////////////////////////// sl@0: sl@0: // This is being deprecated, will be removed sl@0: EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID) sl@0: { sl@0: CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aAttrOID, NULL); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1) sl@0: { sl@0: if (aASN1 == NULL) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aAttrOID, aASN1); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1) sl@0: { sl@0: CPKCS10Attribute* self = NewLC(aAttrOID, aASN1); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C void CPKCS10Attribute::ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1) sl@0: { sl@0: if (aASN1 == NULL) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: delete iRoot; sl@0: iRoot = NULL; sl@0: ConstructL(aAttrOID, aASN1); sl@0: } sl@0: sl@0: EXPORT_C void CPKCS10Attribute::AddValueL(CASN1EncBase* aASN1) sl@0: { sl@0: if (aASN1 == NULL) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: iValueSet->AddChildL(aASN1); sl@0: } sl@0: sl@0: CPKCS10Attribute::CPKCS10Attribute() sl@0: { sl@0: } sl@0: sl@0: CPKCS10Attribute::~CPKCS10Attribute() sl@0: { sl@0: } sl@0: sl@0: void CPKCS10Attribute::ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1) sl@0: { sl@0: iRoot = CASN1EncSequence::NewL(); sl@0: CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(aAttrOID); sl@0: iRoot->AddAndPopChildL(oid); sl@0: iValueSet = CASN1EncSet::NewLC(); sl@0: iRoot->AddAndPopChildL(iValueSet); // Takes ownership sl@0: sl@0: // For now just to allow for deprecated NewLC() which allows for NULL aASN1 sl@0: // Replace with call to AddValueL() once the quirky NewLC() is removed sl@0: if (aASN1) sl@0: { sl@0: iValueSet->AddChildL(aASN1); sl@0: } sl@0: } sl@0: sl@0: // Deprecated sl@0: CASN1EncBase* CPKCS10Attribute::TakeEncodingC() sl@0: { sl@0: return CPKCSAttributeBase::GetEncodingLC(); sl@0: } sl@0: sl@0: // Deprecated sl@0: CASN1EncBase* CPKCS10Attribute::TakeEncodingLC() sl@0: { sl@0: return CPKCSAttributeBase::GetEncodingLC(); sl@0: } sl@0: sl@0: CASN1EncBase* CPKCS10Attribute::GetEncodingLC() sl@0: { sl@0: return CPKCSAttributeBase::GetEncodingLC(); sl@0: } sl@0: sl@0: sl@0: // CPKCS10Attributes /////////////////////////////////////////////////////////// sl@0: sl@0: CPKCS10Attributes::CPKCS10Attributes() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CPKCS10Attributes::~CPKCS10Attributes() sl@0: { sl@0: delete iRoot; sl@0: } sl@0: sl@0: EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewLC() sl@0: { sl@0: CPKCS10Attributes* self = new (ELeave) CPKCS10Attributes(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewL() sl@0: { sl@0: CPKCS10Attributes* self = NewLC(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: void CPKCS10Attributes::ConstructL() sl@0: { sl@0: // Create top level ASN1 sequence sl@0: iRoot = CASN1EncSequence::NewL(); sl@0: iRoot->SetTag(0); sl@0: } sl@0: sl@0: // To be deprecated sl@0: EXPORT_C void CPKCS10Attributes::AddAttributeL(CPKCS10Attribute* aAttr) sl@0: { sl@0: ASSERT(iRoot != NULL); sl@0: ASSERT(aAttr != NULL); sl@0: iRoot->AddAndPopChildL(aAttr->TakeEncodingLC()); sl@0: delete aAttr; sl@0: } sl@0: sl@0: EXPORT_C void CPKCS10Attributes::AddPKCSAttributeL(CPKCSAttributeBase* aAttr) sl@0: { sl@0: ASSERT(iRoot != NULL); sl@0: if (aAttr == NULL) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: iRoot->AddAndPopChildL(aAttr->GetEncodingLC()); sl@0: delete aAttr; sl@0: } sl@0: sl@0: CASN1EncBase* CPKCS10Attributes::TakeEncodingLC() sl@0: { sl@0: CASN1EncBase* result = iRoot; sl@0: iRoot = NULL; sl@0: CleanupStack::PushL(result); sl@0: return result; sl@0: }