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