cryptoservices/certificateandkeymgmt/inc/cmsutils.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 
       
    21 /**
       
    22  @file
       
    23  @internalComponent
       
    24  @released
       
    25 */
       
    26 
       
    27 #ifndef CMSUTILS_H
       
    28 #define CMSUTILS_H
       
    29 
       
    30 #include <signed.h>
       
    31 #include <hash.h>
       
    32 #include <cmscertchoice.h>
       
    33 
       
    34 class CCmsCertificateChoice;
       
    35 class CX509AlgorithmIdentifier;
       
    36 class CX509Certificate;
       
    37 class CMessageDigest;
       
    38 class CRSAPrivateKey;
       
    39 class CDSAPrivateKey;
       
    40 class TASN1DecGeneric;
       
    41 class CASN1EncObjectIdentifier;
       
    42 class CASN1EncBase;
       
    43 
       
    44 /**
       
    45 A utility class contains a set of static functions for encoding and decoding the 
       
    46 CMS signed data relevant CMS structures.
       
    47 */
       
    48 class CmsUtils
       
    49 	{
       
    50 public:
       
    51 	/**
       
    52 	Decode the content type in CMS content info and encapsulated info.
       
    53 	@param aASN1DecGeneric the ASN decoded structure of the content info
       
    54 	@return the type of the content info.
       
    55 	*/
       
    56 	static TInt DecodeContentTypeL(const TASN1DecGeneric* aASN1DecGeneric);
       
    57 
       
    58 	/**
       
    59 	Encode the content type in CMS content info and encapsulated info.
       
    60 	@param aContentType the type of the content info
       
    61 	@return the ASN.1 oid instance of the content type.
       
    62 	*/
       
    63 	static CASN1EncObjectIdentifier* EncodeContentTypeLC(TInt aContentType);
       
    64 	
       
    65 	/**
       
    66 	Add an encoded attribute certificate in the certificate set if it is not in the list already.
       
    67 	@param aCertList the certificate list to which the certificate is added
       
    68 	@param aCert the encoded certificate to be added.
       
    69 	@param aType the type of the encoded certificate.
       
    70 	*/
       
    71 	static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const TDesC8& aCert, CCmsCertificateChoice::TCertificateType aType);
       
    72 	
       
    73 	/**
       
    74 	Add an X509 certificate in the certificate set if it is not in the list already.
       
    75 	@param aCertList the certificate list to which the certificate is added
       
    76 	@param aCert the x509 certificate to be added.
       
    77 	*/	
       
    78 	static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const CX509Certificate& aCert);
       
    79 	
       
    80 	/**
       
    81 	Add an algorithm in the algorithm set if it is not in the list already.
       
    82 	@param aAlgorithmIdList the algorithm list to which the algorithm is added
       
    83 	@param aDigestAlgorithm the digest algorithm identifier
       
    84 	*/		
       
    85 	static void AddAlgorithmIdentifierL(RPointerArray<CX509AlgorithmIdentifier>& aAlgorithmIdList, TAlgorithmId aDigestAlgorithm);
       
    86 
       
    87 	/**
       
    88 	Decode the algorithm identifier set
       
    89 	@param aDigestAlgorithms the algorithm list to which the decoded algorithms is added
       
    90 	@param aRawData the encoded algorithm identifier set
       
    91 	*/			
       
    92 	static void DecodeDigestAlgorithmsL(RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms, const TDesC8& aRawData);
       
    93 	
       
    94 	/**
       
    95 	Decode the certificate set
       
    96 	@param aDigestAlgorithms the certficate list to which the decoded certificates is added
       
    97 	@param aRawData the encoded certficate set
       
    98 	*/
       
    99 	static void DecodeCertificatesL(RPointerArray<CCmsCertificateChoice>& aCertificates, const TDesC8& aRawData);
       
   100 	
       
   101 	/**
       
   102 	Encode the certficate set and put the encoding on the cleanup stack
       
   103 	@param aCertList the certificates list to be encoded.
       
   104 	@return the ASN.1 DER encoding of certificate set
       
   105 	*/
       
   106 	static CASN1EncBase* EncodeCertificatesLC(const RPointerArray<CCmsCertificateChoice>& aCertList);
       
   107 	
       
   108 	/**
       
   109 	Encode the digest algorithm set and put the encoding on the cleanup stack.
       
   110 	@param aCertList the certificates list to be encoded.
       
   111 	@return the ASN.1 DER encoding of certificate set
       
   112 	*/	
       
   113 	static CASN1EncBase* EncodeDigestAlgorithmsLC(const RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms);
       
   114 	
       
   115 	/**
       
   116 	Dncode the octet string
       
   117 	@param aRawData the certificates list to be encoded.
       
   118 	@param aBuf the buffer to hold the octet string.
       
   119 	*/		
       
   120 	static void DecodeOctetStringL(const TDesC8& aRawData, HBufC8*& aBuf);
       
   121 	
       
   122 	/**
       
   123 	Create a hash from the given algorithm identifier and put it on the cleanup stack.
       
   124 	@param aAlgorithm the hash identifier.
       
   125 	@return the hash
       
   126 	*/			
       
   127 	static CMessageDigest* CreateHashLC(TAlgorithmId aAlgorithm);
       
   128 	
       
   129 	/**
       
   130 	Create the DSA signature of the given hash.
       
   131 	@param aHash the hash used to create signature.
       
   132 	@param aKey the DSA private key used to create signature
       
   133 	@return the descriptor holds the signature.
       
   134 	*/
       
   135 	static HBufC8* CreateSignatureL(const TDesC8& aHash, const CDSAPrivateKey& aKey);
       
   136 	
       
   137 	/**
       
   138 	Create the RSA signature of the given hash.
       
   139 	@param aHash the hash used to create signature.
       
   140 	@param aKey the RSA private key used to create signature
       
   141 	@return the descriptor holds the signature.
       
   142 	*/	
       
   143 	static HBufC8* CreateSignatureL(const TDesC8& aHash, const CRSAPrivateKey& aKey);
       
   144 	
       
   145 	/**
       
   146 	Create the RSA signature of the given data, algorithm and private key.
       
   147 	@param aDataToBeSigned the data content to be signed.
       
   148 	@param aIsHash if the first paramter is a hash
       
   149 	@param aAlgorithm the digest algorithm used to create hash
       
   150 	@param aKey the RSA private key.
       
   151 	@return the descriptor holds the signature.
       
   152 	*/		
       
   153 	static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CRSAPrivateKey& aKey);
       
   154 	
       
   155 	/**
       
   156 	Create the DSA signature of the given data, algorithm and private key.
       
   157 	@param aDataToBeSigned the data content to be signed.
       
   158 	@param aIsHash if the first paramter is a hash
       
   159 	@param aAlgorithm the digest algorithm used to create hash
       
   160 	@param aKey the DSA private key.
       
   161 	@return the descriptor holds the signature.
       
   162 	*/			
       
   163 	static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CDSAPrivateKey& aKey);
       
   164 	
       
   165 	/**
       
   166 	Create the raw data from the ASN.1 class.
       
   167 	@param aEncoding the reference of the ASN.1 class
       
   168 	@return the descritor holds the raw data.
       
   169 	*/				
       
   170 	static HBufC8* CreateDEREncodingLC(const CASN1EncBase& aEncoding);
       
   171 	};
       
   172 
       
   173 #endif // CMSUTILS_H