|
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 * Implementation of an attribute type and a value, as defined by the X.520 standard |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalTechnology |
|
25 */ |
|
26 |
|
27 #if !defined(__X520AVA_H__) |
|
28 #define __X520AVA_H__ |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <e32std.h> |
|
32 #include <s32std.h> |
|
33 |
|
34 /** The attribute type. |
|
35 * |
|
36 * @publishedAll |
|
37 * @released |
|
38 * @since v6.0 */ |
|
39 enum TAttributeType |
|
40 { |
|
41 /** A common name */ |
|
42 ECommonName, |
|
43 /** A locality name */ |
|
44 ELocalityName, |
|
45 /** A state or province name */ |
|
46 EStateOrProvinceName, |
|
47 /** An organization name */ |
|
48 EOrganizationName, |
|
49 /** An organizational unit name */ |
|
50 EOrganizationalUnitName, |
|
51 /** A title */ |
|
52 ETitle, |
|
53 /** A qualifier */ |
|
54 EDNQualifier, |
|
55 /** The name of a country */ |
|
56 ECountryName, |
|
57 /** A given name */ |
|
58 EGivenName, |
|
59 /** A surname */ |
|
60 ESurname, |
|
61 /** Initials */ |
|
62 EInitials, |
|
63 /** A generation qualifier */ |
|
64 EGenerationQualifier, |
|
65 /** An email address. This is deprecated. */ |
|
66 EPKCS9EmailAddress, |
|
67 /** A postal code */ |
|
68 EPostalCode, |
|
69 /** A serial number */ |
|
70 ESerialNumber, |
|
71 /** An RFC 2247 domain component. |
|
72 * |
|
73 * A domain name is made up of an ordered set of components.*/ |
|
74 ERFC2247DomainComponent, |
|
75 /** RFC 2256 street component. |
|
76 * |
|
77 * A street */ |
|
78 ERFC2256Street, |
|
79 /** A name of the subject of a certificate as an unstructured ASCII string */ |
|
80 EPKCS9UnstructuredName |
|
81 }; |
|
82 |
|
83 //these are the only attribute types we handle at present |
|
84 _LIT(KX520CountryName,"2.5.4.6"); |
|
85 _LIT(KX520OrganizationName,"2.5.4.10"); |
|
86 _LIT(KX520OrganizationalUnitName,"2.5.4.11"); |
|
87 _LIT(KX520LocalityName,"2.5.4.7"); |
|
88 _LIT(KX520StateOrProvinceName,"2.5.4.8"); |
|
89 _LIT(KX520Title,"2.5.4.12"); |
|
90 _LIT(KX520CommonName,"2.5.4.3"); |
|
91 _LIT(KX520GivenName,"2.5.4.42"); |
|
92 _LIT(KX520Surname,"2.5.4.4"); |
|
93 _LIT(KX520Initials,"2.5.4.43"); |
|
94 _LIT(KX520GenerationQualifier,"2.5.4.44"); |
|
95 _LIT(KX520DNQualifier,"2.5.4.46"); |
|
96 _LIT(KX520SerialNumber,"2.5.4.5"); |
|
97 _LIT(KX520PostalCode,"2.5.4.17"); |
|
98 _LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25"); |
|
99 _LIT(KRFC2256Street,"2.5.4.9"); |
|
100 _LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2"); |
|
101 |
|
102 //email address is deprecated but we support it anyway... |
|
103 _LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1"); |
|
104 |
|
105 /** The maximum length allowed for a country name. */ |
|
106 const TInt KX520MaxCLength = 2; |
|
107 /** The maximum length allowed for an organization name. */ |
|
108 const TInt KX520MaxOLength = 64; |
|
109 /** The maximum length allowed for an organizational unit name. */ |
|
110 const TInt KX520MaxOULength = 64; |
|
111 /** The maximum length allowed for a locality name. */ |
|
112 const TInt KX520MaxLLength = 128; |
|
113 /** The maximum length allowed for a state or province name. */ |
|
114 const TInt KX520MaxSOPLength = 128; |
|
115 /** The maximum length allowed for an title. */ |
|
116 const TInt KX520MaxTLength = 64; |
|
117 /** The maximum length allowed for a common name. */ |
|
118 const TInt KX520MaxCNLength = 256; |
|
119 /** The maximum length allowed for a given name. */ |
|
120 const TInt KX520MaxGNLength = 16; |
|
121 /** The maximum length allowed for a surname. */ |
|
122 const TInt KX520MaxSLength = 40; |
|
123 /** The maximum length allowed for initials. */ |
|
124 const TInt KX520MaxILength = 5; |
|
125 /** The maximum length allowed for a generation qualifier. */ |
|
126 const TInt KX520MaxGQLength = 3; |
|
127 /** The maximum length allowed for a serial number. */ |
|
128 const TInt KX520MaxSNLength = 64; |
|
129 /** The maximum length allowed for a postal code. */ |
|
130 const TInt KX520MaxPostalCodeLength = 40; |
|
131 /** The maximum length allowed for an email address. */ |
|
132 const TInt KPKCS9MaxEmailAddressLength = 256; |
|
133 /** The maximum length allowed for an unstructured name. */ |
|
134 const TInt KPKCS9MaxUnstructuredNameLength = 256; |
|
135 // No maximum was specified in the standard - 128 should be sufficient |
|
136 /** The maximum length allowed for an RFC 2247 domain component. |
|
137 * |
|
138 * Each component of the domain name is a short string. */ |
|
139 const TInt KRFC2247MaxDomainComponentLength = 128; |
|
140 /** The maximum length allowed a for street. */ |
|
141 const TInt KRFC2256StreetLength = 128; |
|
142 |
|
143 class CASN1EncSequence; |
|
144 |
|
145 class CX520AttributeTypeAndValue : public CBase |
|
146 /** Contains an attribute type and a value, as defined by the X.520 standard. |
|
147 * |
|
148 * A Distinguished Name object, as defined by the X.500 standard, consists of |
|
149 * a sequence of these objects. |
|
150 * |
|
151 * @publishedAll |
|
152 * @released |
|
153 * @since v6.0 |
|
154 */ |
|
155 // Attribute and value pair class. Attribute and value pairs |
|
156 // are used in distinguished names and certificate attributes. |
|
157 // Stores data in ASN.1 format internally. |
|
158 { |
|
159 public: |
|
160 // Constructs a new object from ASN.1-encoded DER binary data |
|
161 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing |
|
162 * the encoded binary representation. |
|
163 * |
|
164 * Initialises the object from its encoded binary form into an internal representation. |
|
165 * |
|
166 * @param aBinaryData The encoded binary representation. |
|
167 * @return The new CX520AttributeTypeAndValue object. */ |
|
168 IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData); |
|
169 |
|
170 // Constructs a new object from ASN.1-encoded DER binary data |
|
171 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing |
|
172 * the encoded binary representation, and puts a pointer to the new object onto |
|
173 * the cleanup stack. |
|
174 * |
|
175 * Initialises the object from its encoded binary form into an internal representation. |
|
176 * |
|
177 * @param aBinaryData The encoded binary representation. |
|
178 * @return The new CX520AttributeTypeAndValue object. */ |
|
179 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData); |
|
180 |
|
181 // Constructs a new object from ASN.1-encoded DER binary data |
|
182 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing |
|
183 * the encoded binary representation, starting at the specified offset. |
|
184 * |
|
185 * Initialises the object from its encoded binary form into an internal representation. |
|
186 * |
|
187 * @param aBinaryData The encoded binary representation. |
|
188 * @param aPos The offset position from which to start decoding. |
|
189 * @return The new CX520AttributeTypeAndValue object. */ |
|
190 IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
191 |
|
192 // Constructs a new object from ASN.1-encoded DER binary data |
|
193 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing |
|
194 * the encoded binary representation, starting at the specified offset, and puts |
|
195 * a pointer to the new object onto the cleanup stack. |
|
196 * |
|
197 * Initialises the object from its encoded binary form into an internal representation. |
|
198 * |
|
199 * @param aBinaryData The encoded binary representation. |
|
200 * @param aPos The offset position from which to start decoding. |
|
201 * @return The new CX520AttributeTypeAndValue object. */ |
|
202 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
203 |
|
204 /** Creates a new CX520AttributeTypeAndValue object from an existing object. |
|
205 * |
|
206 * This is equivalent to a copy constructor. |
|
207 * |
|
208 * @param aPair The CX520AttributeTypeAndValue object. |
|
209 * @return The new CX520AttributeTypeAndValue object. */ |
|
210 IMPORT_C static CX520AttributeTypeAndValue* NewL(const CX520AttributeTypeAndValue& aPair); |
|
211 |
|
212 /** Creates a new CX520AttributeTypeAndValue object from an existing object, and |
|
213 * puts a pointer to the new object onto the cleanup stack. |
|
214 * |
|
215 * This is equivalent to a copy constructor. |
|
216 * |
|
217 * @param aPair The CX520AttributeTypeAndValue object. |
|
218 * @return The new CX520AttributeTypeAndValue object. */ |
|
219 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const CX520AttributeTypeAndValue& aPair); |
|
220 |
|
221 /** Creates a new CX520AttributeTypeAndValue object from the specified read stream. |
|
222 * |
|
223 * @param aStream Stream from which the object is to be internalised. |
|
224 * @return The new CX520AttributeTypeAndValue object. */ |
|
225 IMPORT_C static CX520AttributeTypeAndValue* NewL(RReadStream& aStream); |
|
226 |
|
227 /** Creates a new CX520AttributeTypeAndValue object from the specified read stream, |
|
228 * and puts a pointer to the new object onto the cleanup stack. |
|
229 * |
|
230 * @param aStream Stream from which the object is to be internalised. |
|
231 * @return The new CX520AttributeTypeAndValue object. */ |
|
232 IMPORT_C static CX520AttributeTypeAndValue* NewLC(RReadStream& aStream); |
|
233 |
|
234 /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value. |
|
235 * |
|
236 * @param aType Attribute type |
|
237 * @param aValue Attribute value |
|
238 * @return New CX520AttributeTypeAndValue object */ |
|
239 IMPORT_C static CX520AttributeTypeAndValue* NewL(TAttributeType aType, const TDesC8& aValue); |
|
240 |
|
241 /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value. |
|
242 * |
|
243 * @param aType Attribute type |
|
244 * @param aValue Attribute value |
|
245 * @return New CX520AttributeTypeAndValue object on the cleanup stack */ |
|
246 IMPORT_C static CX520AttributeTypeAndValue* NewLC(TAttributeType aType, const TDesC8& aValue); |
|
247 |
|
248 /** Destructor. |
|
249 * |
|
250 * Frees all resources owned by the object, prior to its destruction. */ |
|
251 IMPORT_C ~CX520AttributeTypeAndValue(); |
|
252 |
|
253 /** Gets the encoded attribute type of the object. |
|
254 * |
|
255 * @return A pointer descriptor representing the encoded attribute type. */ |
|
256 IMPORT_C const TPtrC Type() const; |
|
257 |
|
258 /** Gets the encoded attribute value of the object. |
|
259 * |
|
260 * @return The pointer descriptor representing the encoded attribute value. */ |
|
261 IMPORT_C const TPtrC8 EncodedValue() const; |
|
262 |
|
263 // Creates a copy of object's ASN.1 DER encoding. |
|
264 // @return New buffer containing object's ASN.1 DER encoding. |
|
265 /** Gets the decoded value. |
|
266 * |
|
267 * @return A heap descriptor containing the decoded value. */ |
|
268 IMPORT_C virtual HBufC* ValueL() const; |
|
269 |
|
270 /** Encodes the contents into an ASN.1 sequence object. |
|
271 * |
|
272 * This is useful to insert attribute type/value pairs into other ASN.1 |
|
273 * encoding trees. |
|
274 * |
|
275 * @return New ASN.1 sequence object containing attribute |
|
276 * type/value pair in for of an OID and an octet string; |
|
277 * leaves the returned object on the cleanup stack. */ |
|
278 IMPORT_C CASN1EncSequence* EncodeASN1LC() const; |
|
279 |
|
280 /** Encodes the contents into an ASN.1 sequence object. |
|
281 * |
|
282 * Useful to insert attribute type/value pairs into other ASN.1 |
|
283 * encoding trees. |
|
284 * |
|
285 * @return New ASN.1 sequence object containing attribute |
|
286 * type/value pair in for of an OID and an octet string. */ |
|
287 IMPORT_C CASN1EncSequence* EncodeASN1L() const; |
|
288 |
|
289 // This function compares the current element with aElement. |
|
290 /** Compares the attribute type and decoded value of the specified object. |
|
291 * |
|
292 * @param aElement The CX520AttributeTypeAndValue object to be compared. |
|
293 * @return ETrue, if the attribute types and the decoded values match; |
|
294 * EFalse, otherwise. */ |
|
295 IMPORT_C virtual TBool ExactMatchL(const CX520AttributeTypeAndValue& |
|
296 aElement) const; |
|
297 |
|
298 /** Externalises an object of this class to a write stream. |
|
299 * |
|
300 * The presence of this function means that the standard templated operator<<() |
|
301 * can be used to externalise objects of this class. |
|
302 * |
|
303 * @param aStream Stream to which the object should be externalised. */ |
|
304 virtual void ExternalizeL(RWriteStream& aStream) const; |
|
305 private: |
|
306 virtual void InternalizeL(RReadStream& aStream); |
|
307 CX520AttributeTypeAndValue(const TAttributeType aType); |
|
308 CX520AttributeTypeAndValue(); ///< Protected default constructor |
|
309 void ConstructL(const CX520AttributeTypeAndValue& aPair); |
|
310 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
311 void ConstructL(TAttributeType aType, const TDesC8& aValue); |
|
312 /** |
|
313 * This method finds out if case-insensitive comparisons must be done or not. |
|
314 * Email Address is the exceptional case of 'IA5String' value type for which comparisons must be |
|
315 * done case-insensitivly. |
|
316 * |
|
317 * @param aSource contains the encoded value of the attribute type. |
|
318 * @return ETrue, if case-insensitive comparisons are to be done. |
|
319 * This is only when value type is a Printable String OR if attribute type is an Email Address. |
|
320 * EFalse, otherwise. |
|
321 */ |
|
322 TBool IsCaseInSensitive(const TDesC8& aSource) const; |
|
323 HBufC* iType; ///< The encoded type |
|
324 HBufC8* iValue; ///< The encoded value |
|
325 }; |
|
326 |
|
327 #endif |