First public contribution.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #ifndef __PKCS12RECOG_H__
29 A recogniser that recognises the following MIME types:
32 class CPkcs12Recognizer : public CApaDataRecognizerType
34 /** PKCS#12 recognizer panic codes */
35 enum TPkcs12RecogPanic
37 /** Data type index does not correspond to a mime-type */
49 Returns the preferred buffer size for PKCS#12 recognition
50 @return preferred buffer size in bytes
52 TUint PreferredBufSize();
55 Allows a client to enumerate the supported mime-types.
56 @param aIndex index of the mimetype to return
57 @return mime-type corresponding to aIndex
59 TDataType SupportedDataTypeL(TInt aIndex) const;
61 static CApaDataRecognizerType* CreateRecognizerL();
64 // Implementation CApaDataRecognizerType::DoRecognizeL
65 void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
68 Checks whether the file name has a known PKCS#12 extension
69 @param aName the file name to examine
70 @return ETrue if the file extension looks is .pfx or .p12;
71 otherwise, EFalse is returned.
73 TBool HasPkcs12Extension(const TDesC& aName);
76 Checks whether the buffer contains a valid PKCS#12 header.
77 aBuffer buffer to recognise
79 Expected ASN.1 sequence
81 INTEGER // Version = 3
82 SEQ // authSafe - PKCS#7 ContentInfo
83 OID // ContentType (data or signed data)
85 It is not practical to check further than this because the content
86 field within the ContentInfo objects is optional and could be absent.
87 @param aBuffer the buffer to check
88 @return ETrue if the buffer contains a PKCS#12 header;
89 otherwise, EFalse is returned.
91 TBool DoRecognizeBufferL(const TDesC8& aBuffer);
93 // There is no need to validate the lengths because the recogniser
94 // checks the buffer size is at least as large as the minimum header
98 Checks that the data at the specified offset is a DER sequence tag
99 and advances past the tag and it's length.
101 @param aBuffer the buffer containing the DER sequence to validate
102 @param aOffset the offset of the current byte within the buffer. This
103 is undefined if an error occurs.
104 @return ETrue if a valid sequence tag & length is encountered;
105 otherwise, EFalse is returned.
107 TBool ConsumeSequenceL(const TDesC8& aBuffer, TUint& aOffset) const;
110 Decodes a DER encoded integer at the specified offset and advances
112 Signed integers greater than 32 bits in length are not supported.
114 @param aBuffer the buffer containing the DER intger to decode
115 @param aOffset the offset of the current byte within the buffer. This
116 is undefined if an error occurs.
117 @param aIntVal the decoded integer value. This is undefined if an error occurs.
118 @return ETrue if a valid integer is encountered;
119 otherwise, EFalse is returned.
121 TBool ConsumeIntegerL(const TDesC8& aBuffer, TUint& aOffset, TInt& aIntVal) const;
124 Decodes a DER encoded length at the specified offset and advances
125 to the start of the value.
126 Lengths greater than 32 bits in length are not supported.
128 @param aBuffer the buffer containing the length to decode.
129 @param aOffset the offset of the current byte within the buffer. This
130 is undefined if an error occurs.
131 @param aLength the decoded length value in octets. This is undefined if an error occurs.
132 @return ETrue if the length is valid; otherwise, EFalse is returned.
134 TBool ConsumeLengthL(const TDesC8& aBuffer, TUint& aOffset, TInt& aLengthOctets) const;
137 Decodes base256 encoded integer up to 4 bytes in length and advances
139 Signed integers greater than 32 bits in length are not supported.
141 @param aBuffer the buffer containing the octets to decode.
142 @param aOffset the offset of the current byte within the buffer. This
143 is undefined if an error occurs.
144 @param aLength the number of octets to decode (must be <= 4)
145 @param aIntVal the decoded integer. This is undefined if an error occurs.
147 TBool ConsumeBase256L(const TDesC8& aBuffer, TUint& aOffset, TInt aLengthOctets, TInt& aIntVal) const;
150 Calls panic with PKCS#12 recognizer category with the supplied panic code.
151 @param aReason the panic code
153 void Panic(TPkcs12RecogPanic aReason) const;