First public contribution.
2 * Copyright (c) 1998-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.
15 * Implementation of an attribute type and a value, as defined by the X.520 standard
26 #if !defined(__X520AVA_H__)
33 //these are for internal use only
34 //these are the only attribute types we handle at present
35 _LIT(KX520CountryName,"2.5.4.6");
36 _LIT(KX520OrganizationName,"2.5.4.10");
37 _LIT(KX520OrganizationalUnitName,"2.5.4.11");
38 _LIT(KX520LocalityName,"2.5.4.7");
39 _LIT(KX520StateOrProvinceName,"2.5.4.8");
40 _LIT(KX520Title,"2.5.4.12");
41 _LIT(KX520CommonName,"2.5.4.3");
42 _LIT(KX520GivenName,"2.5.4.42");
43 _LIT(KX520Surname,"2.5.4.4");
44 _LIT(KX520Initials,"2.5.4.43");
45 _LIT(KX520GenerationQualifier,"2.5.4.44");
46 _LIT(KX520DNQualifier,"2.5.4.46");
47 _LIT(KX520SerialNumber,"2.5.4.5");
48 _LIT(KX520Description,"2.5.4.13");
50 //more attribute types we handle at present
51 _LIT(KX520PostalCode,"2.5.4.17");
52 _LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25");
53 _LIT(KRFC2256Street,"2.5.4.9");
54 _LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2");
56 //email address is deprecated but we support it anyway...
57 _LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1");
59 /** The maximum length allowed for a country name. */
60 const TInt KX520MaxCLength = 2;
61 /** The maximum length allowed for an organization name. */
62 const TInt KX520MaxOLength = 64;
63 /** The maximum length allowed for an organizational unit name. */
64 const TInt KX520MaxOULength = 64;
65 /** The maximum length allowed for a locality name. */
66 const TInt KX520MaxLLength = 128;
67 /** The maximum length allowed for a state or province name. */
68 const TInt KX520MaxSOPLength = 128;
69 /** The maximum length allowed for an title. */
70 const TInt KX520MaxTLength = 64;
71 /** The maximum length allowed for a common name. */
72 const TInt KX520MaxCNLength = 256;
73 /** The maximum length allowed for a given name. */
74 const TInt KX520MaxGNLength = 16;
75 /** The maximum length allowed for a surname. */
76 const TInt KX520MaxSLength = 40;
77 /** The maximum length allowed for initials. */
78 const TInt KX520MaxILength = 5;
79 /** The maximum length allowed for a generation qualifier. */
80 const TInt KX520MaxGQLength = 3;
81 /** The maximum length allowed for a serial number. */
82 const TInt KX520MaxSNLength = 64;
83 /** The maximum length allowed for a postal code. */
84 const TInt KX520MaxPostalCodeLength = 40;
85 /** The maximum length allowed for an email address. */
86 const TInt KPKCS9MaxEmailAddressLength = 256;
87 /** The maximum length allowed for an unstructured name. */
88 const TInt KPKCS9MaxUnstructuredNameLength = 256;
89 // No maximum was specified in the standard - 128 should be sufficient
90 /** The maximum length allowed for an RFC 2247 domain component.
92 * Each component of the domain name is a short string. */
93 const TInt KRFC2247MaxDomainComponentLength = 128;
94 /** The maximum length allowed a for street. */
95 const TInt KRFC2256StreetLength = 128;
96 /** The maximum length allowed for an Description field. */
97 const TInt KX520MaxDescriptionLength = 1024;
100 /** The attribute type.
107 /** A locality name */
109 /** A state or province name */
110 EStateOrProvinceName,
111 /** An organization name */
113 /** An organizational unit name */
114 EOrganizationalUnitName,
119 /** The name of a country */
127 /** A generation qualifier */
128 EGenerationQualifier,
129 /** An email address. This is deprecated. */
133 /** A serial number */
135 /** An RFC 2247 domain component.
137 * A domain name is made up of an ordered set of components.*/
138 ERFC2247DomainComponent,
139 /** RFC 2256 street component.
143 /** A name of the subject of a certificate as an unstructured ASCII string */
144 EPKCS9UnstructuredName,
150 class CASN1EncSequence;
152 class CX520AttributeTypeAndValue : public CBase
153 /** Contains an attribute type and a value, as defined by the X.520 standard.
155 * A Distinguished Name object, as defined by the X.500 standard, consists of
156 * a sequence of these objects.
160 // Attribute and value pair class. Attribute and value pairs
161 // are used in distinguished names and certificate attributes.
162 // Stores data in ASN.1 format internally.
165 // Constructs a new object from ASN.1-encoded DER binary data
166 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
167 * the encoded binary representation.
169 * Initialises the object from its encoded binary form into an internal representation.
171 * @param aBinaryData The encoded binary representation.
172 * @return The new CX520AttributeTypeAndValue object. */
173 IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData);
175 // Constructs a new object from ASN.1-encoded DER binary data
176 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
177 * the encoded binary representation, and puts a pointer to the new object onto
180 * Initialises the object from its encoded binary form into an internal representation.
182 * @param aBinaryData The encoded binary representation.
183 * @return The new CX520AttributeTypeAndValue object. */
184 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData);
186 // Constructs a new object from ASN.1-encoded DER binary data
187 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
188 * the encoded binary representation, starting at the specified offset.
190 * Initialises the object from its encoded binary form into an internal representation.
192 * @param aBinaryData The encoded binary representation.
193 * @param aPos The offset position from which to start decoding.
194 * @return The new CX520AttributeTypeAndValue object. */
195 IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData, TInt& aPos);
197 // Constructs a new object from ASN.1-encoded DER binary data
198 /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
199 * the encoded binary representation, starting at the specified offset, and puts
200 * a pointer to the new object onto the cleanup stack.
202 * Initialises the object from its encoded binary form into an internal representation.
204 * @param aBinaryData The encoded binary representation.
205 * @param aPos The offset position from which to start decoding.
206 * @return The new CX520AttributeTypeAndValue object. */
207 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData, TInt& aPos);
209 /** Creates a new CX520AttributeTypeAndValue object from an existing object.
211 * This is equivalent to a copy constructor.
213 * @param aPair The CX520AttributeTypeAndValue object.
214 * @return The new CX520AttributeTypeAndValue object. */
215 IMPORT_C static CX520AttributeTypeAndValue* NewL(const CX520AttributeTypeAndValue& aPair);
217 /** Creates a new CX520AttributeTypeAndValue object from an existing object, and
218 * puts a pointer to the new object onto the cleanup stack.
220 * This is equivalent to a copy constructor.
222 * @param aPair The CX520AttributeTypeAndValue object.
223 * @return The new CX520AttributeTypeAndValue object. */
224 IMPORT_C static CX520AttributeTypeAndValue* NewLC(const CX520AttributeTypeAndValue& aPair);
226 /** Creates a new CX520AttributeTypeAndValue object from the specified read stream.
228 * @param aStream Stream from which the object is to be internalised.
229 * @return The new CX520AttributeTypeAndValue object. */
230 IMPORT_C static CX520AttributeTypeAndValue* NewL(RReadStream& aStream);
232 /** Creates a new CX520AttributeTypeAndValue object from the specified read stream,
233 * and puts a pointer to the new object onto the cleanup stack.
235 * @param aStream Stream from which the object is to be internalised.
236 * @return The new CX520AttributeTypeAndValue object. */
237 IMPORT_C static CX520AttributeTypeAndValue* NewLC(RReadStream& aStream);
239 /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
241 * @param aType Attribute type
242 * @param aValue Attribute value
243 * @return New CX520AttributeTypeAndValue object */
244 IMPORT_C static CX520AttributeTypeAndValue* NewL(TAttributeType aType, const TDesC8& aValue);
246 /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
248 * @param aType Attribute type
249 * @param aValue Attribute value
250 * @return New CX520AttributeTypeAndValue object on the cleanup stack */
251 IMPORT_C static CX520AttributeTypeAndValue* NewLC(TAttributeType aType, const TDesC8& aValue);
255 * Frees all resources owned by the object, prior to its destruction. */
256 IMPORT_C ~CX520AttributeTypeAndValue();
258 /** Gets the encoded attribute type of the object.
260 * @return A pointer descriptor representing the encoded attribute type. */
261 IMPORT_C const TPtrC Type() const;
263 /** Gets the encoded attribute value of the object.
265 * @return The pointer descriptor representing the encoded attribute value. */
266 IMPORT_C const TPtrC8 EncodedValue() const;
268 // Creates a copy of object's ASN.1 DER encoding.
269 // @return New buffer containing object's ASN.1 DER encoding.
270 /** Gets the decoded value.
272 * @return A heap descriptor containing the decoded value. */
273 IMPORT_C virtual HBufC* ValueL() const;
275 /** Encodes the contents into an ASN.1 sequence object.
277 * This is useful to insert attribute type/value pairs into other ASN.1
280 * @return New ASN.1 sequence object containing attribute
281 * type/value pair in for of an OID and an octet string;
282 * leaves the returned object on the cleanup stack. */
283 IMPORT_C CASN1EncSequence* EncodeASN1LC() const;
285 /** Encodes the contents into an ASN.1 sequence object.
287 * Useful to insert attribute type/value pairs into other ASN.1
290 * @return New ASN.1 sequence object containing attribute
291 * type/value pair in for of an OID and an octet string. */
292 IMPORT_C CASN1EncSequence* EncodeASN1L() const;
294 // This function compares the current element with aElement.
295 /** Compares the attribute type and decoded value of the specified object.
297 * @param aElement The CX520AttributeTypeAndValue object to be compared.
298 * @return ETrue, if the attribute types and the decoded values match;
299 * EFalse, otherwise. */
300 IMPORT_C virtual TBool ExactMatchL(const CX520AttributeTypeAndValue&
303 /** Externalises an object of this class to a write stream.
305 * The presence of this function means that the standard templated operator<<()
306 * can be used to externalise objects of this class.
308 * @param aStream Stream to which the object should be externalised. */
309 virtual void ExternalizeL(RWriteStream& aStream) const;
311 virtual void InternalizeL(RReadStream& aStream);
312 CX520AttributeTypeAndValue(const TAttributeType aType);
313 CX520AttributeTypeAndValue(); ///< Protected default constructor
314 void ConstructL(const CX520AttributeTypeAndValue& aPair);
315 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
316 void ConstructL(TAttributeType aType, const TDesC8& aValue);
318 * This method finds out if case-insensitive comparisons must be done or not.
319 * Email Address is the exceptional case of 'IA5String' value type for which comparisons must be
320 * done case-insensitivly.
322 * @param aSource contains the encoded value of the attribute type.
323 * @return ETrue, if case-insensitive comparisons are to be done.
324 * This is only when value type is a Printable String OR if attribute type is an Email Address.
327 TBool IsCaseInSensitiveL(const TDesC8& aSource) const;
328 HBufC* iType; ///< The encoded type
329 HBufC8* iValue; ///< The encoded value