sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "pkcs8recog.h" sl@0: sl@0: const TInt KRecognizerValue = 0x1020361C; sl@0: const TUid KUidMimeRecognizer = {KRecognizerValue}; sl@0: sl@0: _LIT8(KDataTypePkcs8KeyPair, "application/pkcs8"); sl@0: _LIT8(KDataTypePkcs8EncryptedKeyPair, "application/pkcs8-encrypted"); sl@0: sl@0: const TInt KSupportedDataTypesNumber = 2; sl@0: sl@0: sl@0: // ---------------------------------------------------------------------------- sl@0: // CApaPkcs8Recognizer sl@0: // sl@0: sl@0: CApaPkcs8Recognizer::CApaPkcs8Recognizer() sl@0: : CApaDataRecognizerType(KUidMimeRecognizer, CApaDataRecognizerType::ENormal) sl@0: { sl@0: iCountDataTypes = KSupportedDataTypesNumber; sl@0: } sl@0: sl@0: TUint CApaPkcs8Recognizer::PreferredBufSize() sl@0: { sl@0: return Max(KIsPKCS8DataMinLength, KIsEncryptedPKCS8DataMinLength); sl@0: } sl@0: sl@0: TDataType CApaPkcs8Recognizer::SupportedDataTypeL(TInt aIndex) const sl@0: { sl@0: __ASSERT_DEBUG(aIndex >= 0 && aIndex < KSupportedDataTypesNumber, sl@0: User::Panic(_L("PKCS8RECOG"), 0)); sl@0: switch (aIndex) sl@0: { sl@0: case 0: sl@0: return TDataType(KDataTypePkcs8KeyPair); sl@0: sl@0: case 1: sl@0: return TDataType(KDataTypePkcs8EncryptedKeyPair); sl@0: sl@0: // Used to prevent warning about return paths not all returning a value sl@0: default: sl@0: return TDataType(KDataTypePkcs8KeyPair); sl@0: } sl@0: } sl@0: sl@0: void CApaPkcs8Recognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer) sl@0: { sl@0: // Ensure length is sufficient for checking type pkcs8 sl@0: if (aBuffer.Size() >= KIsPKCS8DataMinLength) sl@0: { sl@0: if (TASN1DecPKCS8::IsPKCS8Data(aBuffer)) sl@0: { sl@0: iDataType = TDataType(KDataTypePkcs8KeyPair); sl@0: iConfidence = ECertain; sl@0: return; sl@0: } sl@0: } sl@0: sl@0: // Ensure length is sufficient for checking type pkcs8-encrypted sl@0: if (aBuffer.Size() >= KIsEncryptedPKCS8DataMinLength) sl@0: { sl@0: if (TASN1DecPKCS8::IsEncryptedPKCS8Data(aBuffer)) sl@0: { sl@0: iDataType = TDataType(KDataTypePkcs8EncryptedKeyPair); sl@0: iConfidence = ECertain; sl@0: return; sl@0: } sl@0: } sl@0: sl@0: // type not recognized sl@0: } sl@0: sl@0: CApaDataRecognizerType* CApaPkcs8Recognizer::CreateRecognizerL() sl@0: { sl@0: return new (ELeave) CApaPkcs8Recognizer(); sl@0: } sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: IMPLEMENTATION_PROXY_ENTRY(0x1020361B, CApaPkcs8Recognizer::CreateRecognizerL) sl@0: }; sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: return ImplementationTable; sl@0: } sl@0: