os/security/cryptoservices/certificateandkeymgmt/inc/pkcs10attr.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2002-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 * PKCS#10 Certificate Request Attributes class.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @publishedPartner
    23  @released 
    24 */
    25 
    26 #if !defined (__PKCS10ATTR_H__)
    27 #define __PKCS10ATTR_H__
    28 
    29 class CASN1EncBase;
    30 class CASN1EncSequence;
    31 class CASN1EncSet;
    32 
    33 //
    34 // Class capturing common functionality of a PKCS attribute.
    35 //
    36 class CPKCSAttributeBase : public CBase
    37 	{
    38 public:
    39 
    40 	/** Get the ASN.1 encoding of the attribute and relinquish ownership of it,
    41 		leaving it on the cleanup stack.  This is called by CPKCS10Attribtues
    42 		when AddAttribute() is called. 
    43 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
    44 		@return ASN.1 encoding object
    45 	*/
    46 	virtual CASN1EncBase* GetEncodingLC() = 0;
    47 
    48 	virtual ~CPKCSAttributeBase();
    49 
    50 protected:
    51 	/** @internalComponent */
    52 	CPKCSAttributeBase();
    53 	CASN1EncSequence* iRoot;
    54 	CASN1EncSet* iValueSet;
    55 	};
    56 
    57 /** Class representing a generic certificate attribute.  Attributes have an
    58 	object identifier and one or more values.
    59 */
    60 class CPKCS10Attribute : public CPKCSAttributeBase
    61 	{
    62 public:
    63 
    64 	/** Create an attribute with a specified OID and no values, leaving it on
    65 		the cleanup stack.
    66 		NOTE: This method is deprecated. Use the other forms of NewLC instead.
    67 		@param aAttrOID	The specified OID in the form a.b.c. etc.
    68 		@return New PKCS10 attribute object on the cleanup stack
    69 		@deprecated
    70 	*/
    71 	IMPORT_C static CPKCS10Attribute* NewLC(const TDesC& aAttrOID);
    72 
    73 	/** Create an attribute with a specified OID and one value, leaving it on
    74 		the cleanup stack. The value forms part of a set. Additional values can
    75 		be added by calling the AddValueL method.
    76 		@param aAttrOID	The specified OID in the form a.b.c. etc.
    77 		@param aASN1	ASN1 encoding object for attribute value
    78 		 				-- this method takes ownership.
    79 		@return New PKCS10 attribute object on the cleanup stack
    80 	*/
    81 	IMPORT_C static CPKCS10Attribute* NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1);
    82 
    83 	/** Create an attribute with a specified OID and one value. The value forms 
    84 		part of a set. Additional values can be added by calling the AddValueL method.
    85 		@param aAttrOID	The specified OID in the form a.b.c. etc.
    86 		@param aASN1	ASN1 encoding object for attribute value
    87 		 				-- this method takes ownership.
    88 		@return New PKCS10 attribute object
    89 	*/
    90 	IMPORT_C static CPKCS10Attribute* NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
    91 
    92 	/** Add a value to the attribute.
    93 		@param aASN1	ASN1 encoding object for attribute value
    94 		 				-- this method takes ownership.
    95 	*/
    96 	IMPORT_C void AddValueL(CASN1EncBase* aASN1);
    97 
    98 	/** ResetL method to allow for re-use of the generic attribute object. 
    99 		Additional values can be added by calling the AddValueL method.
   100 		@param aAttrOID	The specified OID in the form a.b.c. etc.
   101 		@param aASN1	ASN1 encoding object for attribute value
   102 		 				-- this method takes ownership.
   103 	*/
   104 	IMPORT_C void ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
   105 
   106 	virtual ~CPKCS10Attribute();
   107 
   108 	/** 
   109 	 * @internalComponent
   110 	 *
   111 	 * Get the ASN1 encoding of the attribute and relinquish ownership of it,
   112 		leaving it on the cleanup stack. This is called by CPKCS10Attribtues
   113 		when AddAttribute() is called. This method may leave with E32USER-CBase:66 
   114 		if a stack frame for the next PushL() cannot be allocated.
   115 		NOTE: This method is deprecated. Use GetEncodingLC() instead.
   116 		@deprecated
   117 	*/
   118 	CASN1EncBase* TakeEncodingC();
   119 
   120 	/** 
   121 	 * @internalComponent
   122 	 *
   123 	 * Get the ASN1 encoding of the attribute and relinquish ownership of it,
   124 		leaving it on the cleanup stack.  This is called by CPKCS10Attribtues
   125 		when AddAttribute() is called. This method may leave with E32USER-CBase:66 
   126 		if a stack frame for the next PushL() cannot be allocated.
   127 		NOTE: This method is deprecated. Use GetEncodingLC() instead.
   128 		@deprecated
   129 	*/
   130 	CASN1EncBase* TakeEncodingLC();
   131 
   132 	/** Calls the base class implementation for getting the ASN1 encoding of the attribute.
   133 		Note that this method cannot be reused unless ResetL() has been called. 
   134 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
   135 		@return ASN.1 encoding object
   136 	*/
   137 	virtual CASN1EncBase* GetEncodingLC();
   138 
   139 private:
   140 	// Default constructor.
   141 	CPKCS10Attribute();
   142 
   143 	// Second phase construction function.
   144 	void ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1);
   145 	};
   146 
   147 /** Class for encoding a collection of certificate attributes and passing them
   148 	to the CPKCS10Request class. Some possible attributes are described in
   149 	PKCS#9.
   150   
   151 	@publishedPartner
   152 	@released
   153 */
   154 class CPKCS10Attributes : public CBase
   155 	{
   156 public:
   157 	/** Creates an instance of the class.
   158 		@return New attributes object on the cleanup stack.
   159 	*/
   160 	IMPORT_C static CPKCS10Attributes* NewLC();
   161 
   162 	/** Creates an instance of the class.
   163 		@return New attributes object.
   164 	*/
   165 	IMPORT_C static CPKCS10Attributes* NewL();
   166 
   167 	/** Adds a new attribute for the certificate request.
   168 		@param aAttr The attribute to add - this method takes ownership.
   169 		@deprecated
   170 	*/
   171 	IMPORT_C void AddAttributeL(CPKCS10Attribute* aAttr);
   172 
   173 	/** Adds a new attribute for the certificate request.
   174 		@param aAttr The attribute to add - this method takes ownership.
   175 	*/
   176 	IMPORT_C void AddPKCSAttributeL(CPKCSAttributeBase* aAttr);
   177 
   178 	IMPORT_C ~CPKCS10Attributes(); // virtual from base
   179 
   180 	/** 
   181 	 * @internalComponent
   182 	 *
   183 	 * Get the ASN1 encoding of the attributes and relinquish ownership of it,
   184 		leaving it on the cleanup stack. This is called by CPKCS10Request when
   185 		SetAttributes() is called. This method may leave with E32USER-CBase:66 
   186 		if a stack frame for the next PushL() cannot be allocated.
   187 		@deprecated
   188 	*/
   189 	CASN1EncBase* TakeEncodingC();
   190 
   191 	/** 
   192 	 * @internalComponent
   193 	 *
   194 	 * Get the ASN.1 encoding of the attribute and relinquish ownership of it,
   195 		leaving it on the cleanup stack. This is called by CPKCS10Request when
   196 		SetAttributes() is called. 
   197 		@panic E32USER-CBase 66 if a stack frame for the next PushL() cannot be allocated.
   198 		@return ASN.1 encoding object
   199 	*/
   200 	CASN1EncBase* TakeEncodingLC();
   201 
   202 private:
   203 	/** Default constructor.
   204 	*/
   205 	CPKCS10Attributes();
   206 
   207 	/** Second phase construction function. 
   208 		@note The structure of the attribute node is as follows:
   209 		@code
   210 		  SET
   211 		    SEQUENCE
   212 			  OID of attribute
   213 			  SET values
   214 			...
   215 		@endcode
   216 	*/
   217 	void ConstructL();
   218 	
   219 private:
   220 	/** Pointer to sequence of user-supplied certificate attributes. 
   221 		#AddAttributeL method is used to create and fill this member. 
   222 		If it is initialized by the time #CalculateEncodingL method 
   223 		is called, the latter uses attributes from this member variable 
   224 		for the request, otherwise no attributes are inserted into 
   225 		the request. 
   226 		
   227 		See #AddAttributeL for the explanation of ASN.1 encoding of
   228 		attributes.
   229 	*/
   230 	CASN1EncSequence* iRoot;
   231 	};
   232 
   233 #endif // __PKCS10ATTR_H__