pkiutilities/PKCS12/PKCS12Recognizer/src/PKCS12Recognizer.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2004 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 "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:   Recogniser of application/x-pkcs12 mime type
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "PKCS12Recognizer.h"
       
    22 #include <apmrec.h>
       
    23 #include <apmstd.h>
       
    24 #include <e32svr.h>
       
    25 #include <ecom/implementationproxy.h>
       
    26 #include <mpkcs12.h>
       
    27 
       
    28 _LIT8(KPKCS12MimeType, "application/x-pkcs12");
       
    29 const TInt KMimeTypesSupported(1);
       
    30 const TUid KUidMimePKCS12Recognizer = { 0x101F8714 };
       
    31 
       
    32 // ---------------------------------------------------------
       
    33 // CPKCS12Recognizer::CPKCS12Recognizer
       
    34 // ---------------------------------------------------------
       
    35 //
       
    36 CPKCS12Recognizer::CPKCS12Recognizer()
       
    37     :CApaDataRecognizerType(
       
    38     KUidMimePKCS12Recognizer, 
       
    39         CApaDataRecognizerType::ELow )
       
    40     {
       
    41     iCountDataTypes = KMimeTypesSupported;
       
    42     #ifdef _DEBUG
       
    43     RDebug::Print(_L("CPKCS12Recognizer constructed"));
       
    44     #endif
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CPKCS12Recognizer::~CPKCS12Recognizer()
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CPKCS12Recognizer::~CPKCS12Recognizer()
       
    52     {
       
    53     if (iPKCS12)
       
    54         {
       
    55         iPKCS12->Release();
       
    56         }
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CPKCS12Recognizer::PreferredBufSize
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 TUint CPKCS12Recognizer::PreferredBufSize()
       
    64     {
       
    65     return KPKCS12DataMinLength; // we don't need bigger
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CPKCS12Recognizer::SupportedDataTypeL
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 TDataType CPKCS12Recognizer::SupportedDataTypeL(TInt /*aIndex*/) const
       
    73     {
       
    74     return TDataType(KPKCS12MimeType);
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CPKCS12Recognizer::DoRecognizeL
       
    79 // Checks if aBuffer contains a PKCS#12.
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CPKCS12Recognizer::DoRecognizeL(
       
    83     const TDesC& /*aName*/, 
       
    84     const TDesC8& aBuffer)
       
    85     {   
       
    86       
       
    87     if (aBuffer.Size() >= KPKCS12DataMinLength)
       
    88 		{	
       
    89 		if (iPKCS12 == NULL)
       
    90 		    {
       
    91 		    iPKCS12 = PKCS12Factory::CreateL();
       
    92 		    }
       
    93 		if (iPKCS12->IsPKCS12Data(aBuffer))
       
    94 			{
       
    95 			iDataType = TDataType(KPKCS12MimeType);
       
    96 			iConfidence = EProbable;			
       
    97 			}		
       
    98 		}
       
    99    }
       
   100     
       
   101 // ---------------------------------------------------------
       
   102 // CPKCS12Recognizer::CreateRecognizerL
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 CApaDataRecognizerType* CPKCS12Recognizer::CreateRecognizerL()
       
   106 	{
       
   107 	return new (ELeave) CPKCS12Recognizer();
       
   108 	}
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // ImplementationTable
       
   112 // ---------------------------------------------------------
       
   113 //
       
   114 const TImplementationProxy ImplementationTable[] = 
       
   115     {    
       
   116 	IMPLEMENTATION_PROXY_ENTRY(0x101F8803,CPKCS12Recognizer::CreateRecognizerL)
       
   117 	};
       
   118 	
       
   119 // ---------------------------------------------------------
       
   120 // ImplementationGroupProxy
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   124     {
       
   125     #ifdef _DEBUG    	
       
   126     RDebug::Print(_L("CPKCS12Recognizer ImplementationGroupProxy"));
       
   127     #endif        
       
   128     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   129     return ImplementationTable;
       
   130     }
       
   131 
       
   132 // End of File
       
   133