os/security/cryptoservices/certificateandkeymgmt/pkcs8recog/pkcs8recog.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs8recog/pkcs8recog.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,113 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 +*/
    1.25 +
    1.26 +#include <asnpkcs.h>
    1.27 +#include <ecom/ecom.h>
    1.28 +#include <ecom/implementationproxy.h>
    1.29 +
    1.30 +#include "pkcs8recog.h"
    1.31 +
    1.32 +const TInt KRecognizerValue = 0x1020361C;
    1.33 +const TUid KUidMimeRecognizer = {KRecognizerValue};
    1.34 +
    1.35 +_LIT8(KDataTypePkcs8KeyPair, "application/pkcs8");
    1.36 +_LIT8(KDataTypePkcs8EncryptedKeyPair, "application/pkcs8-encrypted");
    1.37 +
    1.38 +const TInt KSupportedDataTypesNumber = 2;
    1.39 +
    1.40 +
    1.41 +// ----------------------------------------------------------------------------
    1.42 +// CApaPkcs8Recognizer
    1.43 +//
    1.44 +
    1.45 +CApaPkcs8Recognizer::CApaPkcs8Recognizer()
    1.46 +	: CApaDataRecognizerType(KUidMimeRecognizer, CApaDataRecognizerType::ENormal)
    1.47 +	{
    1.48 +	iCountDataTypes = KSupportedDataTypesNumber;
    1.49 +	}
    1.50 +
    1.51 +TUint CApaPkcs8Recognizer::PreferredBufSize()
    1.52 +	{
    1.53 +	return Max(KIsPKCS8DataMinLength, KIsEncryptedPKCS8DataMinLength);
    1.54 +	}
    1.55 +
    1.56 +TDataType CApaPkcs8Recognizer::SupportedDataTypeL(TInt aIndex) const
    1.57 +	{
    1.58 +	__ASSERT_DEBUG(aIndex >= 0 && aIndex < KSupportedDataTypesNumber,
    1.59 +					User::Panic(_L("PKCS8RECOG"), 0));
    1.60 +	switch (aIndex)
    1.61 +		{
    1.62 +		case 0:
    1.63 +			return TDataType(KDataTypePkcs8KeyPair);
    1.64 +	
    1.65 +		case 1:
    1.66 +			return TDataType(KDataTypePkcs8EncryptedKeyPair);
    1.67 +			
    1.68 +		// Used to prevent warning about return paths not all returning a value
    1.69 +		default:
    1.70 +			return TDataType(KDataTypePkcs8KeyPair);
    1.71 +		}
    1.72 +	}
    1.73 +
    1.74 +void CApaPkcs8Recognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer)
    1.75 +	{
    1.76 +	// Ensure length is sufficient for checking type pkcs8
    1.77 +	if (aBuffer.Size() >= KIsPKCS8DataMinLength)
    1.78 +		{
    1.79 +		if (TASN1DecPKCS8::IsPKCS8Data(aBuffer))
    1.80 +			{
    1.81 +			iDataType = TDataType(KDataTypePkcs8KeyPair);
    1.82 +			iConfidence = ECertain;
    1.83 +			return;
    1.84 +			}
    1.85 +		}
    1.86 +		
    1.87 +	// Ensure length is sufficient for checking type pkcs8-encrypted	
    1.88 +	if (aBuffer.Size() >= KIsEncryptedPKCS8DataMinLength) 
    1.89 +		{
    1.90 +		if (TASN1DecPKCS8::IsEncryptedPKCS8Data(aBuffer))
    1.91 +			{
    1.92 +			iDataType = TDataType(KDataTypePkcs8EncryptedKeyPair);
    1.93 +			iConfidence = ECertain;
    1.94 +			return;
    1.95 +			}
    1.96 +		}
    1.97 +				
    1.98 +	// type not recognized
    1.99 +	}
   1.100 +
   1.101 +CApaDataRecognizerType* CApaPkcs8Recognizer::CreateRecognizerL()
   1.102 +	{
   1.103 +	return new (ELeave) CApaPkcs8Recognizer();
   1.104 +	}
   1.105 +
   1.106 +const TImplementationProxy ImplementationTable[] = 
   1.107 +	{
   1.108 +		IMPLEMENTATION_PROXY_ENTRY(0x1020361B, CApaPkcs8Recognizer::CreateRecognizerL)
   1.109 +	};
   1.110 +
   1.111 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   1.112 +	{
   1.113 +	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   1.114 +	return ImplementationTable;
   1.115 +	}	
   1.116 +