os/security/cryptoservices/certificateandkeymgmt/inc/cmsutils.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/inc/cmsutils.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,172 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalComponent
    1.25 + @released
    1.26 +*/
    1.27 +
    1.28 +#ifndef CMSUTILS_H
    1.29 +#define CMSUTILS_H
    1.30 +
    1.31 +#include <signed.h>
    1.32 +#include <hash.h>
    1.33 +#include <cmscertchoice.h>
    1.34 +
    1.35 +class CCmsCertificateChoice;
    1.36 +class CX509AlgorithmIdentifier;
    1.37 +class CX509Certificate;
    1.38 +class CMessageDigest;
    1.39 +class CRSAPrivateKey;
    1.40 +class CDSAPrivateKey;
    1.41 +class TASN1DecGeneric;
    1.42 +class CASN1EncObjectIdentifier;
    1.43 +class CASN1EncBase;
    1.44 +
    1.45 +/**
    1.46 +A utility class contains a set of static functions for encoding and decoding the 
    1.47 +CMS signed data relevant CMS structures.
    1.48 +*/
    1.49 +class CmsUtils
    1.50 +	{
    1.51 +public:
    1.52 +	/**
    1.53 +	Decode the content type in CMS content info and encapsulated info.
    1.54 +	@param aASN1DecGeneric the ASN decoded structure of the content info
    1.55 +	@return the type of the content info.
    1.56 +	*/
    1.57 +	static TInt DecodeContentTypeL(const TASN1DecGeneric* aASN1DecGeneric);
    1.58 +
    1.59 +	/**
    1.60 +	Encode the content type in CMS content info and encapsulated info.
    1.61 +	@param aContentType the type of the content info
    1.62 +	@return the ASN.1 oid instance of the content type.
    1.63 +	*/
    1.64 +	static CASN1EncObjectIdentifier* EncodeContentTypeLC(TInt aContentType);
    1.65 +	
    1.66 +	/**
    1.67 +	Add an encoded attribute certificate in the certificate set if it is not in the list already.
    1.68 +	@param aCertList the certificate list to which the certificate is added
    1.69 +	@param aCert the encoded certificate to be added.
    1.70 +	@param aType the type of the encoded certificate.
    1.71 +	*/
    1.72 +	static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const TDesC8& aCert, CCmsCertificateChoice::TCertificateType aType);
    1.73 +	
    1.74 +	/**
    1.75 +	Add an X509 certificate in the certificate set if it is not in the list already.
    1.76 +	@param aCertList the certificate list to which the certificate is added
    1.77 +	@param aCert the x509 certificate to be added.
    1.78 +	*/	
    1.79 +	static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const CX509Certificate& aCert);
    1.80 +	
    1.81 +	/**
    1.82 +	Add an algorithm in the algorithm set if it is not in the list already.
    1.83 +	@param aAlgorithmIdList the algorithm list to which the algorithm is added
    1.84 +	@param aDigestAlgorithm the digest algorithm identifier
    1.85 +	*/		
    1.86 +	static void AddAlgorithmIdentifierL(RPointerArray<CX509AlgorithmIdentifier>& aAlgorithmIdList, TAlgorithmId aDigestAlgorithm);
    1.87 +
    1.88 +	/**
    1.89 +	Decode the algorithm identifier set
    1.90 +	@param aDigestAlgorithms the algorithm list to which the decoded algorithms is added
    1.91 +	@param aRawData the encoded algorithm identifier set
    1.92 +	*/			
    1.93 +	static void DecodeDigestAlgorithmsL(RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms, const TDesC8& aRawData);
    1.94 +	
    1.95 +	/**
    1.96 +	Decode the certificate set
    1.97 +	@param aDigestAlgorithms the certficate list to which the decoded certificates is added
    1.98 +	@param aRawData the encoded certficate set
    1.99 +	*/
   1.100 +	static void DecodeCertificatesL(RPointerArray<CCmsCertificateChoice>& aCertificates, const TDesC8& aRawData);
   1.101 +	
   1.102 +	/**
   1.103 +	Encode the certficate set and put the encoding on the cleanup stack
   1.104 +	@param aCertList the certificates list to be encoded.
   1.105 +	@return the ASN.1 DER encoding of certificate set
   1.106 +	*/
   1.107 +	static CASN1EncBase* EncodeCertificatesLC(const RPointerArray<CCmsCertificateChoice>& aCertList);
   1.108 +	
   1.109 +	/**
   1.110 +	Encode the digest algorithm set and put the encoding on the cleanup stack.
   1.111 +	@param aCertList the certificates list to be encoded.
   1.112 +	@return the ASN.1 DER encoding of certificate set
   1.113 +	*/	
   1.114 +	static CASN1EncBase* EncodeDigestAlgorithmsLC(const RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms);
   1.115 +	
   1.116 +	/**
   1.117 +	Dncode the octet string
   1.118 +	@param aRawData the certificates list to be encoded.
   1.119 +	@param aBuf the buffer to hold the octet string.
   1.120 +	*/		
   1.121 +	static void DecodeOctetStringL(const TDesC8& aRawData, HBufC8*& aBuf);
   1.122 +	
   1.123 +	/**
   1.124 +	Create a hash from the given algorithm identifier and put it on the cleanup stack.
   1.125 +	@param aAlgorithm the hash identifier.
   1.126 +	@return the hash
   1.127 +	*/			
   1.128 +	static CMessageDigest* CreateHashLC(TAlgorithmId aAlgorithm);
   1.129 +	
   1.130 +	/**
   1.131 +	Create the DSA signature of the given hash.
   1.132 +	@param aHash the hash used to create signature.
   1.133 +	@param aKey the DSA private key used to create signature
   1.134 +	@return the descriptor holds the signature.
   1.135 +	*/
   1.136 +	static HBufC8* CreateSignatureL(const TDesC8& aHash, const CDSAPrivateKey& aKey);
   1.137 +	
   1.138 +	/**
   1.139 +	Create the RSA signature of the given hash.
   1.140 +	@param aHash the hash used to create signature.
   1.141 +	@param aKey the RSA private key used to create signature
   1.142 +	@return the descriptor holds the signature.
   1.143 +	*/	
   1.144 +	static HBufC8* CreateSignatureL(const TDesC8& aHash, const CRSAPrivateKey& aKey);
   1.145 +	
   1.146 +	/**
   1.147 +	Create the RSA signature of the given data, algorithm and private key.
   1.148 +	@param aDataToBeSigned the data content to be signed.
   1.149 +	@param aIsHash if the first paramter is a hash
   1.150 +	@param aAlgorithm the digest algorithm used to create hash
   1.151 +	@param aKey the RSA private key.
   1.152 +	@return the descriptor holds the signature.
   1.153 +	*/		
   1.154 +	static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CRSAPrivateKey& aKey);
   1.155 +	
   1.156 +	/**
   1.157 +	Create the DSA signature of the given data, algorithm and private key.
   1.158 +	@param aDataToBeSigned the data content to be signed.
   1.159 +	@param aIsHash if the first paramter is a hash
   1.160 +	@param aAlgorithm the digest algorithm used to create hash
   1.161 +	@param aKey the DSA private key.
   1.162 +	@return the descriptor holds the signature.
   1.163 +	*/			
   1.164 +	static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CDSAPrivateKey& aKey);
   1.165 +	
   1.166 +	/**
   1.167 +	Create the raw data from the ASN.1 class.
   1.168 +	@param aEncoding the reference of the ASN.1 class
   1.169 +	@return the descritor holds the raw data.
   1.170 +	*/				
   1.171 +	static HBufC8* CreateDEREncodingLC(const CASN1EncBase& aEncoding);
   1.172 +	};
   1.173 +
   1.174 +#endif // CMSUTILS_H
   1.175 +