williamr@2: /*
williamr@2: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2: * All rights reserved.
williamr@2: * This component and the accompanying materials are made available
williamr@2: * under the terms of the License "Eclipse Public License v1.0"
williamr@2: * which accompanies this distribution, and is available
williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2: *
williamr@2: * Initial Contributors:
williamr@2: * Nokia Corporation - initial contribution.
williamr@2: *
williamr@2: * Contributors:
williamr@2: *
williamr@2: * Description: 
williamr@2: * PKCS#10 Certificate Request Attributes class.
williamr@2: *
williamr@2: */
williamr@2: 
williamr@2: 
williamr@2: 
williamr@2: 
williamr@2: /**
williamr@2:  @file
williamr@2:  @publishedPartner
williamr@2:  @released 
williamr@2: */
williamr@2: 
williamr@2: #if !defined (__PKCS10ATTR_H__)
williamr@2: #define __PKCS10ATTR_H__
williamr@2: 
williamr@2: class CASN1EncBase;
williamr@2: class CASN1EncSequence;
williamr@2: 
williamr@2: //
williamr@2: // Class capturing common functionality of a PKCS attribute.
williamr@2: //
williamr@2: class CPKCSAttributeBase : public CBase
williamr@2: 	{
williamr@2: public:
williamr@2: 
williamr@2: 	/** Get the ASN.1 encoding of the attribute and relinquish ownership of it,
williamr@2: 		leaving it on the cleanup stack.  This is called by CPKCS10Attribtues
williamr@2: 		when AddAttribute() is called. 
williamr@2: 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		@return ASN.1 encoding object
williamr@2: 	*/
williamr@2: 	virtual CASN1EncBase* GetEncodingLC() = 0;
williamr@2: 
williamr@2: 	virtual ~CPKCSAttributeBase();
williamr@2: 
williamr@2: protected:
williamr@2: 	/** @internalComponent */
williamr@2: 	CPKCSAttributeBase();
williamr@2: 	CASN1EncSequence* iRoot;
williamr@2: 	CASN1EncSet* iValueSet;
williamr@2: 	};
williamr@2: 
williamr@2: /** Class representing a generic certificate attribute.  Attributes have an
williamr@2: 	object identifier and one or more values.
williamr@2: */
williamr@2: class CPKCS10Attribute : public CPKCSAttributeBase
williamr@2: 	{
williamr@2: public:
williamr@2: 
williamr@2: 	/** Create an attribute with a specified OID and no values, leaving it on
williamr@2: 		the cleanup stack.
williamr@2: 		NOTE: This method is deprecated. Use the other forms of NewLC instead.
williamr@2: 		@param aAttrOID	The specified OID in the form a.b.c. etc.
williamr@2: 		@return New PKCS10 attribute object on the cleanup stack
williamr@2: 		@deprecated
williamr@2: 	*/
williamr@2: 	IMPORT_C static CPKCS10Attribute* NewLC(const TDesC& aAttrOID);
williamr@2: 
williamr@2: 	/** Create an attribute with a specified OID and one value, leaving it on
williamr@2: 		the cleanup stack. The value forms part of a set. Additional values can
williamr@2: 		be added by calling the AddValueL method.
williamr@2: 		@param aAttrOID	The specified OID in the form a.b.c. etc.
williamr@2: 		@param aASN1	ASN1 encoding object for attribute value
williamr@2: 		 				-- this method takes ownership.
williamr@2: 		@return New PKCS10 attribute object on the cleanup stack
williamr@2: 	*/
williamr@2: 	IMPORT_C static CPKCS10Attribute* NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1);
williamr@2: 
williamr@2: 	/** Create an attribute with a specified OID and one value. The value forms 
williamr@2: 		part of a set. Additional values can be added by calling the AddValueL method.
williamr@2: 		@param aAttrOID	The specified OID in the form a.b.c. etc.
williamr@2: 		@param aASN1	ASN1 encoding object for attribute value
williamr@2: 		 				-- this method takes ownership.
williamr@2: 		@return New PKCS10 attribute object
williamr@2: 	*/
williamr@2: 	IMPORT_C static CPKCS10Attribute* NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
williamr@2: 
williamr@2: 	/** Add a value to the attribute.
williamr@2: 		@param aASN1	ASN1 encoding object for attribute value
williamr@2: 		 				-- this method takes ownership.
williamr@2: 	*/
williamr@2: 	IMPORT_C void AddValueL(CASN1EncBase* aASN1);
williamr@2: 
williamr@2: 	/** ResetL method to allow for re-use of the generic attribute object. 
williamr@2: 		Additional values can be added by calling the AddValueL method.
williamr@2: 		@param aAttrOID	The specified OID in the form a.b.c. etc.
williamr@2: 		@param aASN1	ASN1 encoding object for attribute value
williamr@2: 		 				-- this method takes ownership.
williamr@2: 	*/
williamr@2: 	IMPORT_C void ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
williamr@2: 
williamr@2: 	virtual ~CPKCS10Attribute();
williamr@2: 
williamr@2: 	/** 
williamr@2: 	 * @internalComponent
williamr@2: 	 *
williamr@2: 	 * Get the ASN1 encoding of the attribute and relinquish ownership of it,
williamr@2: 		leaving it on the cleanup stack. This is called by CPKCS10Attribtues
williamr@2: 		when AddAttribute() is called. This method may leave with E32USER-CBase:66 
williamr@2: 		if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		NOTE: This method is deprecated. Use GetEncodingLC() instead.
williamr@2: 		@deprecated
williamr@2: 	*/
williamr@2: 	CASN1EncBase* TakeEncodingC();
williamr@2: 
williamr@2: 	/** 
williamr@2: 	 * @internalComponent
williamr@2: 	 *
williamr@2: 	 * Get the ASN1 encoding of the attribute and relinquish ownership of it,
williamr@2: 		leaving it on the cleanup stack.  This is called by CPKCS10Attribtues
williamr@2: 		when AddAttribute() is called. This method may leave with E32USER-CBase:66 
williamr@2: 		if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		NOTE: This method is deprecated. Use GetEncodingLC() instead.
williamr@2: 		@deprecated
williamr@2: 	*/
williamr@2: 	CASN1EncBase* TakeEncodingLC();
williamr@2: 
williamr@2: 	/** Calls the base class implementation for getting the ASN1 encoding of the attribute.
williamr@2: 		Note that this method cannot be reused unless ResetL() has been called. 
williamr@2: 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		@return ASN.1 encoding object
williamr@2: 	*/
williamr@2: 	virtual CASN1EncBase* GetEncodingLC();
williamr@2: 
williamr@2: private:
williamr@2: 	// Default constructor.
williamr@2: 	CPKCS10Attribute();
williamr@2: 
williamr@2: 	// Second phase construction function.
williamr@2: 	void ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
williamr@2: 	};
williamr@2: 
williamr@2: /** Class for encoding a collection of certificate attributes and passing them
williamr@2: 	to the CPKCS10Request class. Some possible attributes are described in
williamr@2: 	PKCS#9.
williamr@2:   
williamr@2: 	@publishedPartner
williamr@2: 	@released
williamr@2: */
williamr@2: class CPKCS10Attributes : public CBase
williamr@2: 	{
williamr@2: public:
williamr@2: 	/** Creates an instance of the class.
williamr@2: 		@return New attributes object on the cleanup stack.
williamr@2: 	*/
williamr@2: 	IMPORT_C static CPKCS10Attributes* NewLC();
williamr@2: 
williamr@2: 	/** Creates an instance of the class.
williamr@2: 		@return New attributes object.
williamr@2: 	*/
williamr@2: 	IMPORT_C static CPKCS10Attributes* NewL();
williamr@2: 
williamr@2: 	/** Adds a new attribute for the certificate request.
williamr@2: 		@param aAttr The attribute to add - this method takes ownership.
williamr@2: 		@deprecated
williamr@2: 	*/
williamr@2: 	IMPORT_C void AddAttributeL(CPKCS10Attribute* aAttr);
williamr@2: 
williamr@2: 	/** Adds a new attribute for the certificate request.
williamr@2: 		@param aAttr The attribute to add - this method takes ownership.
williamr@2: 	*/
williamr@2: 	IMPORT_C void AddPKCSAttributeL(CPKCSAttributeBase* aAttr);
williamr@2: 
williamr@2: 	IMPORT_C ~CPKCS10Attributes(); // virtual from base
williamr@2: 
williamr@2: 	/** 
williamr@2: 	 * @internalComponent
williamr@2: 	 *
williamr@2: 	 * Get the ASN1 encoding of the attributes and relinquish ownership of it,
williamr@2: 		leaving it on the cleanup stack. This is called by CPKCS10Request when
williamr@2: 		SetAttributes() is called. This method may leave with E32USER-CBase:66 
williamr@2: 		if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		@deprecated
williamr@2: 	*/
williamr@2: 	CASN1EncBase* TakeEncodingC();
williamr@2: 
williamr@2: 	/** 
williamr@2: 	 * @internalComponent
williamr@2: 	 *
williamr@2: 	 * Get the ASN.1 encoding of the attribute and relinquish ownership of it,
williamr@2: 		leaving it on the cleanup stack. This is called by CPKCS10Request when
williamr@2: 		SetAttributes() is called. 
williamr@2: 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
williamr@2: 		@return ASN.1 encoding object
williamr@2: 	*/
williamr@2: 	CASN1EncBase* TakeEncodingLC();
williamr@2: 
williamr@2: private:
williamr@2: 	/** Default constructor.
williamr@2: 	*/
williamr@2: 	CPKCS10Attributes();
williamr@2: 
williamr@2: 	/** Second phase construction function. 
williamr@2: 		@note The structure of the attribute node is as follows:
williamr@2: 		@code
williamr@2: 		  SET
williamr@2: 		    SEQUENCE
williamr@2: 			  OID of attribute
williamr@2: 			  SET values
williamr@2: 			...
williamr@2: 		@endcode
williamr@2: 	*/
williamr@2: 	void ConstructL();
williamr@2: 	
williamr@2: private:
williamr@2: 	/** Pointer to sequence of user-supplied certificate attributes. 
williamr@2: 		#AddAttributeL method is used to create and fill this member. 
williamr@2: 		If it is initialized by the time #CalculateEncodingL method 
williamr@2: 		is called, the latter uses attributes from this member variable 
williamr@2: 		for the request, otherwise no attributes are inserted into 
williamr@2: 		the request. 
williamr@2: 		
williamr@2: 		See #AddAttributeL for the explanation of ASN.1 encoding of
williamr@2: 		attributes.
williamr@2: 	*/
williamr@2: 	CASN1EncSequence* iRoot;
williamr@2: 	};
williamr@2: 
williamr@2: #endif // __PKCS10ATTR_H__