os/security/cryptoservices/certificateandkeymgmt/pkcs8recog/pkcs8recog.cpp
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) 1998-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 */
    22 
    23 #include <asnpkcs.h>
    24 #include <ecom/ecom.h>
    25 #include <ecom/implementationproxy.h>
    26 
    27 #include "pkcs8recog.h"
    28 
    29 const TInt KRecognizerValue = 0x1020361C;
    30 const TUid KUidMimeRecognizer = {KRecognizerValue};
    31 
    32 _LIT8(KDataTypePkcs8KeyPair, "application/pkcs8");
    33 _LIT8(KDataTypePkcs8EncryptedKeyPair, "application/pkcs8-encrypted");
    34 
    35 const TInt KSupportedDataTypesNumber = 2;
    36 
    37 
    38 // ----------------------------------------------------------------------------
    39 // CApaPkcs8Recognizer
    40 //
    41 
    42 CApaPkcs8Recognizer::CApaPkcs8Recognizer()
    43 	: CApaDataRecognizerType(KUidMimeRecognizer, CApaDataRecognizerType::ENormal)
    44 	{
    45 	iCountDataTypes = KSupportedDataTypesNumber;
    46 	}
    47 
    48 TUint CApaPkcs8Recognizer::PreferredBufSize()
    49 	{
    50 	return Max(KIsPKCS8DataMinLength, KIsEncryptedPKCS8DataMinLength);
    51 	}
    52 
    53 TDataType CApaPkcs8Recognizer::SupportedDataTypeL(TInt aIndex) const
    54 	{
    55 	__ASSERT_DEBUG(aIndex >= 0 && aIndex < KSupportedDataTypesNumber,
    56 					User::Panic(_L("PKCS8RECOG"), 0));
    57 	switch (aIndex)
    58 		{
    59 		case 0:
    60 			return TDataType(KDataTypePkcs8KeyPair);
    61 	
    62 		case 1:
    63 			return TDataType(KDataTypePkcs8EncryptedKeyPair);
    64 			
    65 		// Used to prevent warning about return paths not all returning a value
    66 		default:
    67 			return TDataType(KDataTypePkcs8KeyPair);
    68 		}
    69 	}
    70 
    71 void CApaPkcs8Recognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer)
    72 	{
    73 	// Ensure length is sufficient for checking type pkcs8
    74 	if (aBuffer.Size() >= KIsPKCS8DataMinLength)
    75 		{
    76 		if (TASN1DecPKCS8::IsPKCS8Data(aBuffer))
    77 			{
    78 			iDataType = TDataType(KDataTypePkcs8KeyPair);
    79 			iConfidence = ECertain;
    80 			return;
    81 			}
    82 		}
    83 		
    84 	// Ensure length is sufficient for checking type pkcs8-encrypted	
    85 	if (aBuffer.Size() >= KIsEncryptedPKCS8DataMinLength) 
    86 		{
    87 		if (TASN1DecPKCS8::IsEncryptedPKCS8Data(aBuffer))
    88 			{
    89 			iDataType = TDataType(KDataTypePkcs8EncryptedKeyPair);
    90 			iConfidence = ECertain;
    91 			return;
    92 			}
    93 		}
    94 				
    95 	// type not recognized
    96 	}
    97 
    98 CApaDataRecognizerType* CApaPkcs8Recognizer::CreateRecognizerL()
    99 	{
   100 	return new (ELeave) CApaPkcs8Recognizer();
   101 	}
   102 
   103 const TImplementationProxy ImplementationTable[] = 
   104 	{
   105 		IMPLEMENTATION_PROXY_ENTRY(0x1020361B, CApaPkcs8Recognizer::CreateRecognizerL)
   106 	};
   107 
   108 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   109 	{
   110 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   111 	return ImplementationTable;
   112 	}	
   113