First public contribution.
2 * Copyright (c) 1997-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.
20 #if !defined (__WTLSNAMES_H__)
21 #define __WTLSNAMES_H__
29 This file contains the definition for class CWTLSName.
34 enum { null(0), text(1), binary(2), key_hash_sha(254), x509_name(255)}
37 We only support text and x509_name as these are the only meaningful identifiers..
38 x509_name is X.500 Distinguished Name, and should use our existing X.500 DN implementation.
41 IdentifierType identifier_type;
42 select (identifier_type) {
45 CharacterSet character_set;
46 opaque name<1.. 2^8-1>;
47 case binary: opaque identifier<1..2^8-1>;
48 case key_hash_sha: opaque key_hash[20];
49 case x509_name: opaque distinguished_name<1..2^8-1>;
55 This maps on to one of the IANA defined character sets. There are rather a lot
56 of these. We just support the text type, with either Latin1 or UTF8 encoding.
60 * Enumerates the types of WTLS certificate name forms/identifiers.
62 * Only text strings and X.500 Distinguished Names are currently supported.
69 /* Text string (Latin-1 or Unicode).
71 * A text identifier consists of a 16-bit character set identifier;
72 * this represents the IANA-assigned character set number. */
76 * Certificates of this type will be rejected.*/
80 * Certificates of this type will be rejected.*/
81 EWTLSKeyHashSha = 0xfe,
82 /* X.500 Distinguished Name. */
86 typedef TUint8 TWTLSNameType;
88 typedef TInt TWTLSCharSet;
90 // MIBenum constants from the IANA list of character sets.
91 // See http://www.iana.org/assignments/character-sets for more info.
93 /** MIBenum constant for the Latin1 IANA character set */
94 const TInt KWTLSLatin1CharSet = 4;
96 /** MIBenum constant for the UTF-8 IANA character set */
97 const TInt KWTLSUTF8CharSet = 106;
99 class CWTLSName : public CBase
101 * Stores the type of a WTLS name and the underlying encoding of the type.
107 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation.
109 * @param aBinaryData The encoded binary representation.
110 * @return The new CWTLSName object.
112 IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData);
115 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
116 * and puts a pointer to it onto the cleanup stack.
118 * @param aBinaryData The encoded binary representation.
119 * @return The new CWTLSName object.
121 IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData);
124 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
125 * starting at the specified offset.
127 * @param aBinaryData The encoded binary representation.
128 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
129 * and is updated to the position at the end of the object.
130 * @return The new CWTLSName object.
132 IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData, TInt& aPos);
135 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
136 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
138 * @param aBinaryData The encoded binary representation.
139 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
140 * and is updated to the position at the end of the object.
141 * @return The new CWTLSName object.
143 IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
146 * Creates a new CWTLSName object from an existing one.
148 * @param aName An existing CWTLSName object.
149 * @return The new CWTLSName object.
151 IMPORT_C static CWTLSName* NewL(const CWTLSName& aName);
154 * Creates a new CWTLSName object from an existing one,
155 * and puts a pointer to it onto the cleanup stack.
157 * @param aName An existing CWTLSName object.
158 * @return The new CWTLSName object.
160 IMPORT_C static CWTLSName* NewLC(const CWTLSName& aName);
165 * Frees all resources owned by the object, prior to its destruction.
167 IMPORT_C ~CWTLSName();
170 * Performs a simple byte compare between this WTLS name and a specified WTLS name.
172 * Needed for the constructing/validating of certificate chains.
174 * @param aName An existing CWTLSName object.
175 * @return ETrue, if the WTLS names match; EFalse, otherwise.
177 IMPORT_C TBool ExactMatchL(const CWTLSName& aName) const;
180 * Gets the type of the WTLS name.
182 * @return Type of WTLS name form.
184 IMPORT_C TWTLSNameType NameType() const;
187 * Gets the encoding of the underlying type of WTLS name.
189 * @return Pointer descriptor representing the encoding of the WTLS name type.
191 IMPORT_C TPtrC8 NameData() const;
194 * Gets the decoded value for the common or organisation name.
196 * Provides the functionality required by the CCertificate::IssuerL() and SubjectL() functions.
198 * @return A heap descriptor containing the decoded value of the common or organisation name.
200 IMPORT_C HBufC* DisplayNameL() const;
203 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
204 void ConstructL(const CWTLSName& aName);
205 void AllocNameDataL(const TDesC8& aBinaryData, TInt& aPos);
206 void AllocTextDataL(const TDesC8& aBinaryData, TInt& aPos);
207 TWTLSNameType iNameType;
211 class CWTLSText : public CBase
215 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation.
217 * @param aBinaryData The encoded binary representation.
218 * @return The new CWTLSText object.
220 IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData);
223 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
224 * and puts a pointer to it onto the cleanup stack.
226 * @param aBinaryData The encoded binary representation.
227 * @return The new CWTLSText object.
229 IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData);
232 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
233 * starting at the specified offset.
235 * @param aBinaryData The encoded binary representation.
236 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
237 * and is updated to the position at the end of the object.
238 * @return The new CWTLSText object.
240 IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData, TInt& aPos);
243 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
244 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
246 * @param aBinaryData The encoded binary representation.
247 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
248 * and is updated to the position at the end of the object.
249 * @return The new CWTLSText object.
251 IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData, TInt& aPos);
256 * Frees all resources owned by the object, prior to its destruction.
258 IMPORT_C ~CWTLSText();
261 * Performs a simple byte compare between this CWTLSText object and a specified CWTLSText object.
263 * There is a subtle difference between this byte-match and CWTLSName::ExactMatchL().
264 * As opposed to the latter, this function should successfully match two names that
265 * are the same that were encoded using different character sets.
267 * @param aName An existing CWTLSText object.
268 * @return ETrue, if the CWTLSText objects match; EFalse, otherwise.
270 IMPORT_C TBool ExactMatchL(const CWTLSText& aName) const;
273 * Gets the name of the CWTLSText object.
275 * @return A pointer to the name of the CWTLSText object.
277 IMPORT_C TPtrC Name() const;
280 * Gets the character set of the CWTLSText object.
282 * @return The character set
284 IMPORT_C TWTLSCharSet CharacterSet() const;
293 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
299 //this class implements the 'structured' variant of the text type defined in the WTLS spec, section 10.5.2:
300 //<servicename>; <organization>; <country>[; <commonname>[; <extension>[; <extension>[ …. ]]]]
301 _LIT(KWTLSCountryName,"C");
302 _LIT(KWTLSOrganizationName,"O");
303 _LIT(KWTLSServiceName,"OU");
304 _LIT(KWTLSTitle,"T");
305 _LIT(KWTLSCommonName,"CN");
307 class TWTLSStructuredTextField
313 TWTLSStructuredTextField(const TDesC& aType, const TDesC& aValue);
319 IMPORT_C TPtrC Type() const;
325 IMPORT_C TPtrC Value() const;
332 class CWTLSStructuredText : public CWTLSText
336 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation.
338 * @param aBinaryData The encoded binary representation.
339 * @return The new CWTLSStructuredText object.
341 IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData);
344 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
345 * and puts a pointer to it onto the cleanup stack.
347 * @param aBinaryData The encoded binary representation.
348 * @return The new CWTLSStructuredText object.
350 IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData);
353 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
354 * starting at the specified offset.
356 * @param aBinaryData The encoded binary representation.
357 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
358 * and is updated to the position at the end of the object.
359 * @return The new CWTLSStructuredText object.
361 IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData, TInt& aPos);
364 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
365 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
367 * @param aBinaryData The encoded binary representation.
368 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
369 * and is updated to the position at the end of the object.
370 * @return The new CWTLSStructuredText object.
372 IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData, TInt& aPos);
377 * Frees all resources owned by the object, prior to its destruction.
379 IMPORT_C ~CWTLSStructuredText();
386 IMPORT_C HBufC* DisplayNameL() const;
388 //accessors for defined fields
395 IMPORT_C TPtrC ServiceName() const;
402 IMPORT_C TPtrC Organization() const;
409 IMPORT_C TPtrC Country() const;
416 IMPORT_C TInt Count() const;
425 * @return A pointer to a TWTLSStructuredTextField object; NULL if field not found.
426 * The returned object remains the property of the structured text object
427 * (so don't delete it).
429 IMPORT_C const TWTLSStructuredTextField* FieldByName(const TDesC& aType) const;
436 IMPORT_C const TWTLSStructuredTextField& FieldByIndex(TInt aIndex) const;
438 CWTLSStructuredText();
439 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
440 void AddFieldValueL(const TDesC& aFieldName, TInt& aPos);
441 void AddFieldL(TInt& aPos);
442 TPtrC GetFieldL(TDesC& aString, TInt& aPos);
443 TBool GetSubFieldL(TDesC& aString, TInt& aPos);
444 CArrayFixFlat<TWTLSStructuredTextField>* iFields;