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