os/security/cryptoservices/certificateandkeymgmt/inc/cmscertchoice.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) 2006-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 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @publishedPartner
    22  @released
    23 */
    24 
    25 
    26 #ifndef CMSCERTCHOICE_H
    27 #define CMSCERTCHOICE_H
    28 
    29 #include <e32base.h>
    30 
    31 class CX509Certificate;
    32 class CASN1EncEncoding;
    33 
    34 /**
    35 An instance of a member of the RFC2630 CertificateChoices.
    36 At present, only X509 certificates and attribute certificate are supported.
    37 (not PKCS#6 extended certificates).
    38 */
    39 class CCmsCertificateChoice : public CBase
    40 	{
    41 public:
    42 	/**
    43 	Certificate Types
    44 	*/
    45 	enum TCertificateType
    46 		{
    47 		/**
    48 		X.509 Certificate.
    49 		*/
    50 		ECertificateX509,
    51 		/**
    52 		Extended Certificate.
    53 		*/
    54 		ECertificateExtendedCerificate,
    55 		/**
    56 		Attribute Certificate.
    57 		*/
    58 		ECertificateAttribute
    59 		};
    60 		
    61 	/**
    62 	 * @internalComponent
    63 	 * 
    64 	 * Creates a CertificateChoices as defined in RFC2630.
    65 	 * @param aCertificate The X509 certificate used to build the CertificateChoices object.
    66 	 * The newly created object will create a copy of aCertificate.	
    67 	 * @return The fully constructed object.
    68 	 **/
    69 	static CCmsCertificateChoice* NewL(const CX509Certificate& aCertificate);
    70 
    71 	/**
    72 	 * @internalComponent
    73 	 *
    74 	 * Creates a CertificateChoices object as defined in RFC2630
    75 	 * and leaves the object on the cleanup stack.
    76 	 * @param aCertificate The X509 certificate used to build the CertificateChoices object.
    77 	 * The newly created object will create a copy of aCertificate.	
    78 	 * @return The fully constructed object.
    79 	 **/
    80 	static CCmsCertificateChoice* NewLC(const CX509Certificate& aCertificate);
    81 
    82 	/**
    83 	 * @internalComponent
    84 	 *
    85 	 * Creates a CertificateChoices object as defined in RFC2630.
    86 	 * @param aCertType The encoded certificate type. ECertificateExtendedCerificate is not supported.
    87 	 * @param aEncodedCertificate The encoded certificate used to build the CertificateChoices object.
    88 	 * The newly created object will create a copy of aEncodedCertificate.
    89 	 * @return The fully constructed object.
    90 	 **/	
    91 	static CCmsCertificateChoice* NewL(TCertificateType aCertType, const TDesC8& aEncodedCertificate);
    92 	
    93 	/**
    94 	 * @internalComponent
    95 	 * 
    96 	 * Creates a CertificateChoices object as defined in RFC2630 and leaves the object on the cleanup stack.
    97 	 * @param aCertType The encoded certificate type. ECertificateExtendedCerificate is not supported.
    98 	 * @param aEncodedCertificate The encoded certificate used to build the CertificateChoices object.
    99 	 * The newly created object will create a copy of aEncodedCertificate.
   100 	 * @return The fully constructed object.
   101 	 **/		
   102 	static CCmsCertificateChoice* NewLC(TCertificateType aCertType, const TDesC8& aEncodedCertificate);
   103 	
   104 	/**
   105 	 * @internalComponent
   106 	 * 
   107 	 * Creates a CertificateChoices object as defined in RFC2630.
   108 	 * @param aRawData The encoded CertificateChoices object to be decoded.
   109 	 * @return The fully constructed object.
   110 	 **/			
   111 	static CCmsCertificateChoice* NewL(const TDesC8& aRawData);
   112 	
   113 	/**
   114 	Destructor
   115 	*/
   116 	virtual ~CCmsCertificateChoice();
   117 	
   118 	/**
   119 	Returns the type of the CertificateChoices object
   120 	@return The type of the certificate.
   121 	*/
   122 	IMPORT_C TCertificateType CertificateType();
   123 	
   124 	/**
   125 	Returns the x509 certificate reference if the certificate is a X509 certificate.
   126 	Callers need to check whether the certificate's type is X509 beforehand.
   127 	@return The x509 certificate reference.
   128 	*/
   129 	IMPORT_C const CX509Certificate& Certificate(void) const;
   130 
   131 	/**
   132 	Returns the encoded certificate's buffer. If the certificate is not an
   133 	attribute certificate, NULL is returned. Callers can also check whether 
   134 	the certificate's type is X509 beforehand.
   135 	@return A pointer to the encoded certificate buffer.
   136 	*/
   137 	IMPORT_C const HBufC8* AttributeCertificate() const;
   138 
   139 	/**
   140 	 * @internalComponent
   141 	 *
   142 	 * Creates the ASN1 DER sequence of the CertificateChoices object
   143 	 * and leaves it on the cleanup stack.
   144 	 * @return  ASN1 DER sequence of this object.
   145 	 **/		
   146 	CASN1EncEncoding* EncodeASN1DERLC() const;
   147 
   148 private:
   149 	/**
   150 	Default Constructor
   151 	*/
   152 	CCmsCertificateChoice();
   153 	
   154 	
   155 	/**
   156 	Second phase constructor for decoding.
   157 	@param aRawData the raw data to be decoded.
   158 	*/
   159 	void ConstructL(const TDesC8& aRawData);
   160 	
   161 	/**
   162 	Second phase constructor for encoding.
   163 	@param aCertificate the X509 certificate used to create the object
   164 	*/
   165 	void ConstructL(const CX509Certificate& aCertificate);
   166 
   167 	/**
   168 	Second phase constructor for encoding.
   169 	@param aCertType The encoded certificate type. ECertificateExtendedCerificate is not supported
   170 	@param aEncodedCertificate the encoded certificate used to create the object
   171 	*/	
   172 	void ConstructL(TCertificateType aCertType, const TDesC8& aEncodedCertificate);
   173 
   174 	
   175 private:
   176 	/**
   177 	The type the embedded certificate type
   178 	*/
   179 	TCertificateType iCertificateType;
   180 	
   181 	/**
   182 	The X509 certificate pointer
   183 	*/
   184 	CX509Certificate* iCertificate;
   185 	
   186 	/**
   187 	The attribute certificate buffer
   188 	*/	
   189 	HBufC8* iEncodedAttributeCertificate;
   190 	};
   191 	
   192 #endif