os/security/cryptoservices/certificateandkeymgmt/inc/pkcs7encrypteddataobject.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-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 #ifndef __PKCS7_ENCRYPTED_DATA_OBJECT_H__
    26 #define __PKCS7_ENCRYPTED_DATA_OBJECT_H__
    27 
    28 #include <asn1dec.h>
    29 #include <signed.h>
    30 #include <pbedata.h>
    31 #include <asnpkcs.h>
    32 #include <pkcs7contentinfo_v2.h>
    33 #include <pkcs12kdf.h>
    34 
    35 /**
    36  A representation of a PKCS7 (Encrypted data) entity
    37  This class decodes the PKCS7 Encrypted Data content. 
    38  It provides various exported methods which will 
    39  return the values present in the EncryptedData ::= SEQUENCE.
    40  */
    41 class CPKCS7EncryptedDataObject : public CBase
    42 	{
    43 public:
    44 	enum TContentType
    45 	/**
    46 	 Identifies the type of ContentType present in the EncryptedContentInfo ::= SEQUENCE
    47 	 */
    48 		{
    49 	    EPkcs7Data = 1
    50 		};  
    51 		
    52    	/**
    53 	 Creates a new PKCS#7 EncryptedData object. 
    54 	 @param     aContentInfo contains a reference to CPKCS7ContentInfo.
    55 	 @return    A pointer to the newly allocated object.
    56 	 */
    57 	IMPORT_C static CPKCS7EncryptedDataObject* NewL(const CPKCS7ContentInfo& aContentInfo);
    58 	
    59 	/**
    60 	 Destructor.
    61 	 */
    62 	virtual ~CPKCS7EncryptedDataObject();
    63     /**
    64      Provides access to the version number within the EncryptedData SEQUENCE.
    65      Version is the syntax version number.It shall be 0 for this version of the standard
    66 	 @return    The version number
    67 	 */ 
    68     IMPORT_C TInt Version() const;
    69     
    70 	/**
    71 	 Provides access to the ContentType present within the EncryptedContentInfo. 
    72 	 ContentType indicates the type of content.This is represented using the OID.
    73      @return    ContentType present in the EncryptedContentInfo structure.
    74      */ 
    75     IMPORT_C CPKCS7EncryptedDataObject::TContentType ContentType() const;
    76     
    77     /**
    78      Provides access to the encryptedContent within the EncryptedContentInfo SEQUENCE.
    79      encryptedContent is OPTIONAL in EncryptedContentInfo SEQUENCE
    80      This will return a NULL pointer in case there is no encryptedContent
    81 	 @return    The encryptedContent
    82      */
    83 	IMPORT_C const TDesC8& EncryptedContentInfoData() const;
    84 	
    85     /**
    86      Provides access to the contentEncryptionAlgorithm within the 
    87      EncryptedContentInfo SEQUENCE.
    88 	 @return    A CPBEncryptParms object which has the Encrypt Parameters 
    89      			EncryptedContent present in EncryptedContentInfo Sequence
    90      */
    91     IMPORT_C const CPBEncryptParms& EncryptParams() const;
    92     
    93     /**
    94 	 This method decrypts the encrypted information. The caller assumes 
    95 	 ownership of the returned object.
    96 	 @param     aPassword is the password used for decryption.
    97 	 @return    The plaintext data obtained after decryption.
    98 	 @leave     KErrNotSupported if otherthan pkcs12 pbeIds used.
    99 	 @leave     KErrGeneral if decrypt descriptor length is less than 0.
   100 	 @see		PKCS12KDF, TPBPassword, CPBEncryptElement, CPBDecryptor.
   101 	 */
   102 	IMPORT_C HBufC8* DecryptDataL(const TDesC& aPassword) const;
   103 	
   104 private:
   105 	/**
   106 	 Constructor.
   107 	 */
   108     CPKCS7EncryptedDataObject(void);
   109     
   110     /**
   111      Copy Constructor.
   112      @param aEncryptedDataObject A CPKCS7EncryptedDataObject object.
   113      */
   114     CPKCS7EncryptedDataObject(const CPKCS7EncryptedDataObject& aEncryptedDataObject);
   115     
   116     /**
   117 	 Assignment operator.
   118 	 @param aEncryptedDataObject A CPKCS7EncryptedDataObject object.
   119 	 @return A reference to CPKCS7EncryptedDataObject class.
   120 	 */
   121 	CPKCS7EncryptedDataObject& operator=(const CPKCS7EncryptedDataObject& aEncryptedDataObject);
   122     
   123     /**    	
   124      This decrypt the encrypted data. Below is the ASN1 syntax.
   125 	 
   126 	 EncryptedData ::= SEQUENCE
   127 	  	 {
   128 	     version                Version,
   129 	     encryptedContentInfo   EncryptedContentInfo
   130 	  	 } 
   131 	 EncryptedContentInfo ::= SEQUENCE 
   132 	  	 {
   133 	     contentType                 PKCS7-CONTENT-TYPE.&id({PKCS7ContentTable}),
   134 	     contentEncryptionAlgorithm  ContentEncryptionAlgorithmIdentifier,
   135 	     encryptedContent            [0]  ENCRYPTED{PKCS7-CONTENT-TYPE.&Type({PKCS7ContentTable}{@.contentType})} OPTIONAL
   136 	  	 }
   137 	 EncryptedContent ::= OCTET STRING
   138 	 
   139 	 ContentInfo ::= SEQUENCE 
   140 	  	{
   141 	    contentType ContentType,
   142 	    content[0] EXPLICIT ANY DEFINED BY contentType OPTIONAL 
   143 	  	}
   144 	 ContentType ::= OBJECT IDENTIFIER
   145 	 
   146 	 @param 	aContentInfo Contains a reference to  CPKCS7ContentInfo
   147 	 @leave		KErrArgument if the data is not valid PKCS#7 EncryptedData Structure.
   148 	 @see       CPKCS7ContentInfo
   149      */
   150 	void ConstructL(const CPKCS7ContentInfo& aContentInfo);
   151 	
   152 	/**
   153      Provides access to the Encrypt Parameters present within the 
   154      ContentEncryptionAlgorithm Sequence. Below is the ASN1 Syntax.
   155      
   156      ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
   157      AlgorithmIdentifier: A type that identifies an algorithm (by object identifier) and associated parameters
   158      AlgorithmIdentifier ::= SEQUENCE 
   159                {
   160                algorithm   ALGORITHM.&id({SupportedAlgorithms}),
   161                parameters  ALGORITHM.&Type({SupportedAlgorithms}{@ algorithm}) OPTIONAL
   162                }
   163 
   164 	 @param     aBinaryData  which is the ContentEncryptionAlgorithmIdentifier
   165 	            and is AlgorithIdentifier Type.
   166 	            AlgorithmIdentifier: A type that identifies an 
   167 	            algorithm (by object identifier) and associated parameters.
   168      @return    Encrypt Parameters. This Identifies the 
   169 	            content-encryption algorithm (and any associated parameters) 
   170 	            under which the content is encrypted.
   171 	 @leave     KErrArgument if the data is not valid PKCS#7 ContentEncryptionAlgorithm 
   172 	 			sequence.
   173 	 @see 	    CPBEncryptParms, TASN1DecPKCS5.
   174      */ 
   175     CPBEncryptParms* DecodeContentEncryptionAlgorithmL(const TDesC8& aBinaryData) const;
   176     
   177 	
   178 private:
   179      /** version is the syntax version number in PKCS#7 EncryptedData ::= SEQUENCE*/
   180      TInt iVersion;
   181      
   182 	 /** Indicates the type of content in PKCS7 EncryptedContentInfo Sequence */
   183 	 TContentType iContentType;
   184 	 
   185 	 /** Identifies the content-encryption algorithm (and any associated parameters) 
   186 	     under which the content is encrypted */
   187      CPBEncryptParms* iEncryptParams;
   188           
   189 	 /** Contains the encrypted content */
   190 	 TPtrC8 iEncryptedContent;
   191 };
   192  
   193 #endif //__PKCS7_ENCRYPTED_DATA_OBJECT_H__