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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file 
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include <asnpkcs.h>
sl@0
    24
#include <ecom/ecom.h>
sl@0
    25
#include <ecom/implementationproxy.h>
sl@0
    26
sl@0
    27
#include "pkcs8recog.h"
sl@0
    28
sl@0
    29
const TInt KRecognizerValue = 0x1020361C;
sl@0
    30
const TUid KUidMimeRecognizer = {KRecognizerValue};
sl@0
    31
sl@0
    32
_LIT8(KDataTypePkcs8KeyPair, "application/pkcs8");
sl@0
    33
_LIT8(KDataTypePkcs8EncryptedKeyPair, "application/pkcs8-encrypted");
sl@0
    34
sl@0
    35
const TInt KSupportedDataTypesNumber = 2;
sl@0
    36
sl@0
    37
sl@0
    38
// ----------------------------------------------------------------------------
sl@0
    39
// CApaPkcs8Recognizer
sl@0
    40
//
sl@0
    41
sl@0
    42
CApaPkcs8Recognizer::CApaPkcs8Recognizer()
sl@0
    43
	: CApaDataRecognizerType(KUidMimeRecognizer, CApaDataRecognizerType::ENormal)
sl@0
    44
	{
sl@0
    45
	iCountDataTypes = KSupportedDataTypesNumber;
sl@0
    46
	}
sl@0
    47
sl@0
    48
TUint CApaPkcs8Recognizer::PreferredBufSize()
sl@0
    49
	{
sl@0
    50
	return Max(KIsPKCS8DataMinLength, KIsEncryptedPKCS8DataMinLength);
sl@0
    51
	}
sl@0
    52
sl@0
    53
TDataType CApaPkcs8Recognizer::SupportedDataTypeL(TInt aIndex) const
sl@0
    54
	{
sl@0
    55
	__ASSERT_DEBUG(aIndex >= 0 && aIndex < KSupportedDataTypesNumber,
sl@0
    56
					User::Panic(_L("PKCS8RECOG"), 0));
sl@0
    57
	switch (aIndex)
sl@0
    58
		{
sl@0
    59
		case 0:
sl@0
    60
			return TDataType(KDataTypePkcs8KeyPair);
sl@0
    61
	
sl@0
    62
		case 1:
sl@0
    63
			return TDataType(KDataTypePkcs8EncryptedKeyPair);
sl@0
    64
			
sl@0
    65
		// Used to prevent warning about return paths not all returning a value
sl@0
    66
		default:
sl@0
    67
			return TDataType(KDataTypePkcs8KeyPair);
sl@0
    68
		}
sl@0
    69
	}
sl@0
    70
sl@0
    71
void CApaPkcs8Recognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer)
sl@0
    72
	{
sl@0
    73
	// Ensure length is sufficient for checking type pkcs8
sl@0
    74
	if (aBuffer.Size() >= KIsPKCS8DataMinLength)
sl@0
    75
		{
sl@0
    76
		if (TASN1DecPKCS8::IsPKCS8Data(aBuffer))
sl@0
    77
			{
sl@0
    78
			iDataType = TDataType(KDataTypePkcs8KeyPair);
sl@0
    79
			iConfidence = ECertain;
sl@0
    80
			return;
sl@0
    81
			}
sl@0
    82
		}
sl@0
    83
		
sl@0
    84
	// Ensure length is sufficient for checking type pkcs8-encrypted	
sl@0
    85
	if (aBuffer.Size() >= KIsEncryptedPKCS8DataMinLength) 
sl@0
    86
		{
sl@0
    87
		if (TASN1DecPKCS8::IsEncryptedPKCS8Data(aBuffer))
sl@0
    88
			{
sl@0
    89
			iDataType = TDataType(KDataTypePkcs8EncryptedKeyPair);
sl@0
    90
			iConfidence = ECertain;
sl@0
    91
			return;
sl@0
    92
			}
sl@0
    93
		}
sl@0
    94
				
sl@0
    95
	// type not recognized
sl@0
    96
	}
sl@0
    97
sl@0
    98
CApaDataRecognizerType* CApaPkcs8Recognizer::CreateRecognizerL()
sl@0
    99
	{
sl@0
   100
	return new (ELeave) CApaPkcs8Recognizer();
sl@0
   101
	}
sl@0
   102
sl@0
   103
const TImplementationProxy ImplementationTable[] = 
sl@0
   104
	{
sl@0
   105
		IMPLEMENTATION_PROXY_ENTRY(0x1020361B, CApaPkcs8Recognizer::CreateRecognizerL)
sl@0
   106
	};
sl@0
   107
sl@0
   108
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
   109
	{
sl@0
   110
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
   111
	return ImplementationTable;
sl@0
   112
	}	
sl@0
   113