sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Implementation of the class that holds the Distinguished Name of a subject
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@publishedAll
|
sl@0
|
23 |
@released
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
#if !defined (__X500DN_H__)
|
sl@0
|
26 |
#define __X500DN_H__
|
sl@0
|
27 |
|
sl@0
|
28 |
#include <e32base.h>
|
sl@0
|
29 |
#include <e32std.h>
|
sl@0
|
30 |
#include <s32file.h>
|
sl@0
|
31 |
#include <x520ava.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
class CX500DistinguishedName : public CBase
|
sl@0
|
34 |
/** Holds the Distinguished Name of a subject.
|
sl@0
|
35 |
*
|
sl@0
|
36 |
* A collection of 'attribute type and value' objects, as defined by the X.520
|
sl@0
|
37 |
* standard.
|
sl@0
|
38 |
*
|
sl@0
|
39 |
* The name used in X.509 certificates is the X.500 Distinguished Name, which
|
sl@0
|
40 |
* describes a path through an X.500 Directory Information Tree.
|
sl@0
|
41 |
*
|
sl@0
|
42 |
* A Distinguished Name is a series of name-value pairs that uniquely identify
|
sl@0
|
43 |
* an entity, i.e. the certificate subject.
|
sl@0
|
44 |
*
|
sl@0
|
45 |
* @publishedAll
|
sl@0
|
46 |
* @released
|
sl@0
|
47 |
*
|
sl@0
|
48 |
* <!--
|
sl@0
|
49 |
* This is necessary when working with certificates, certificate requests, directories, etc.
|
sl@0
|
50 |
* -->
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
{
|
sl@0
|
53 |
public:
|
sl@0
|
54 |
/** Creates a new Distinguished Name object from the specified buffer containing
|
sl@0
|
55 |
* the encoded binary representation, starting at the specified offset.
|
sl@0
|
56 |
*
|
sl@0
|
57 |
* @param aBinaryData The encoded binary representation.
|
sl@0
|
58 |
* @param aPos The position from which to start decoding.
|
sl@0
|
59 |
* @return The new Distinguished Name object. */
|
sl@0
|
60 |
IMPORT_C static CX500DistinguishedName* NewL(const TDesC8& aBinaryData, TInt& aPos);
|
sl@0
|
61 |
|
sl@0
|
62 |
/** Creates a new Distinguished Name object from the specified buffer containing
|
sl@0
|
63 |
* the encoded binary representation, starting at the specified offset, and puts
|
sl@0
|
64 |
* a pointer to it onto the cleanup stack.
|
sl@0
|
65 |
*
|
sl@0
|
66 |
* @param aBinaryData The encoded binary representation.
|
sl@0
|
67 |
* @param aPos The position from which to start decoding.
|
sl@0
|
68 |
* @return The new Distinguished Name object. */
|
sl@0
|
69 |
IMPORT_C static CX500DistinguishedName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
|
sl@0
|
70 |
|
sl@0
|
71 |
/** Creates a new Distinguished Name object from the specified buffer containing
|
sl@0
|
72 |
* the encoded binary representation.
|
sl@0
|
73 |
*
|
sl@0
|
74 |
* Initialises the object from its encoded binary form into an internal representation.
|
sl@0
|
75 |
*
|
sl@0
|
76 |
* @param aBinaryData The encoded binary representation.
|
sl@0
|
77 |
* @return The new Distinguished Name object. */
|
sl@0
|
78 |
IMPORT_C static CX500DistinguishedName* NewL(const TDesC8& aBinaryData);
|
sl@0
|
79 |
|
sl@0
|
80 |
/** Creates a new Distinguished Name object from the specified buffer containing
|
sl@0
|
81 |
* the encoded binary representation, and puts a pointer to it onto the cleanup stack.
|
sl@0
|
82 |
*
|
sl@0
|
83 |
* Initialises the object from its encoded binary form into an internal representation.
|
sl@0
|
84 |
*
|
sl@0
|
85 |
* @param aBinaryData The encoded binary representation.
|
sl@0
|
86 |
* @return The new Distinguished Name object. */
|
sl@0
|
87 |
IMPORT_C static CX500DistinguishedName* NewLC(const TDesC8& aBinaryData);
|
sl@0
|
88 |
|
sl@0
|
89 |
/** Creates a new Distinguished Name object from the specified read stream.
|
sl@0
|
90 |
*
|
sl@0
|
91 |
* Construction is from a stream.
|
sl@0
|
92 |
*
|
sl@0
|
93 |
* @param aStream Stream from which the contents should be internalised.
|
sl@0
|
94 |
* @return The newDistinguished Name object. */
|
sl@0
|
95 |
IMPORT_C static CX500DistinguishedName* NewL(RReadStream& aStream);
|
sl@0
|
96 |
|
sl@0
|
97 |
/** Creates a new Distinguished Name object from the specified read stream, and
|
sl@0
|
98 |
* puts a pointer to it onto the cleanup stack.
|
sl@0
|
99 |
*
|
sl@0
|
100 |
* @param aStream Stream from which the contents should be internalised.
|
sl@0
|
101 |
* @return The new Distinguished Name object. */
|
sl@0
|
102 |
IMPORT_C static CX500DistinguishedName* NewLC(RReadStream& aStream);
|
sl@0
|
103 |
|
sl@0
|
104 |
/** Creates a new Distinguished Name object from the specified array of 'attribute
|
sl@0
|
105 |
* type and value' objects.
|
sl@0
|
106 |
*
|
sl@0
|
107 |
* The elements of the specified array are copied into this object.
|
sl@0
|
108 |
*
|
sl@0
|
109 |
* @param aElements The array of 'attribute type and value' objects to be copied.
|
sl@0
|
110 |
* @return The new Distinguished Name object. */
|
sl@0
|
111 |
IMPORT_C static CX500DistinguishedName* NewL(const CArrayPtr<CX520AttributeTypeAndValue>& aElements);
|
sl@0
|
112 |
|
sl@0
|
113 |
/** Creates a new Distinguished Name object from the specified array of 'attribute
|
sl@0
|
114 |
* type and value' objects, and puts a pointer to it onto the cleanup stack.
|
sl@0
|
115 |
*
|
sl@0
|
116 |
* The elements of the specified array are copied into this object.
|
sl@0
|
117 |
*
|
sl@0
|
118 |
* @param aElements The array of 'attribute type and value' objects to be copied.
|
sl@0
|
119 |
* @return The new Distinguished Name object. */
|
sl@0
|
120 |
IMPORT_C static CX500DistinguishedName* NewLC(const CArrayPtr<CX520AttributeTypeAndValue>& aElements);
|
sl@0
|
121 |
|
sl@0
|
122 |
/** Creates a new Distinguished Name object from an existing object.
|
sl@0
|
123 |
*
|
sl@0
|
124 |
* This is equivalent to a copy constructor.
|
sl@0
|
125 |
*
|
sl@0
|
126 |
* @param aName The Distinguished Name object to be copied.
|
sl@0
|
127 |
* @return The new Distinguished Name object. */
|
sl@0
|
128 |
IMPORT_C static CX500DistinguishedName* NewL(const CX500DistinguishedName& aName);
|
sl@0
|
129 |
|
sl@0
|
130 |
/** Creates a new Distinguished Name object from an existing object, and puts a
|
sl@0
|
131 |
* pointer to it onto the cleanup stack.
|
sl@0
|
132 |
*
|
sl@0
|
133 |
* This is equivalent to a copy constructor.
|
sl@0
|
134 |
*
|
sl@0
|
135 |
* @param aName The Distinguished Name object to be copied.
|
sl@0
|
136 |
* @return The new Distinguished Name object. */
|
sl@0
|
137 |
IMPORT_C static CX500DistinguishedName* NewLC(const CX500DistinguishedName& aName);
|
sl@0
|
138 |
|
sl@0
|
139 |
/** Externalises an object of this class to a write stream.
|
sl@0
|
140 |
*
|
sl@0
|
141 |
* The presence of this function means that the standard templated operator<<()
|
sl@0
|
142 |
* can be used to externalise objects of this class.
|
sl@0
|
143 |
*
|
sl@0
|
144 |
* @param aStream Stream to which the object should be externalised. */
|
sl@0
|
145 |
IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
146 |
|
sl@0
|
147 |
/** Gets the number of 'attribute type and value' objects contained by this Distinguished
|
sl@0
|
148 |
* Name object.
|
sl@0
|
149 |
*
|
sl@0
|
150 |
* @return The number of 'attribute type and value' objects. */
|
sl@0
|
151 |
IMPORT_C TInt Count() const;
|
sl@0
|
152 |
|
sl@0
|
153 |
/** Gets a reference to specific 'attribute type and value' object as identified
|
sl@0
|
154 |
* by the specified index.
|
sl@0
|
155 |
*
|
sl@0
|
156 |
* @param aIndex The index number identifying the specific 'attribute type and
|
sl@0
|
157 |
* value' object. This number is relative to zero. This value must be non-negative
|
sl@0
|
158 |
* and less than the number of objects currently contained by this Distinguished
|
sl@0
|
159 |
* Name object.
|
sl@0
|
160 |
* @return The referenced 'attribute type and value' object. */
|
sl@0
|
161 |
IMPORT_C const CX520AttributeTypeAndValue& Element(TInt aIndex) const;
|
sl@0
|
162 |
|
sl@0
|
163 |
/** Destructor.
|
sl@0
|
164 |
*
|
sl@0
|
165 |
* Frees all resources owned by the object, prior to its destruction. */
|
sl@0
|
166 |
IMPORT_C ~CX500DistinguishedName();
|
sl@0
|
167 |
|
sl@0
|
168 |
/** Compares the specified Distinguished Name object with this Distinguished Name
|
sl@0
|
169 |
* object.
|
sl@0
|
170 |
*
|
sl@0
|
171 |
* @param aName The Distinguished Name object to be compared.
|
sl@0
|
172 |
* @return ETrue, if the Distinguished Name objects contain exactly the same 'attribute
|
sl@0
|
173 |
* type and value' objects; EFalse, otherwise.
|
sl@0
|
174 |
* @see CX520AttributeTypeAndValue::ExactMatchL()
|
sl@0
|
175 |
*
|
sl@0
|
176 |
* <!-- This function checks if all the fields of aName and
|
sl@0
|
177 |
* iElements are the same but not necessarily in the same order. -->
|
sl@0
|
178 |
*/
|
sl@0
|
179 |
IMPORT_C TBool ExactMatchL(const CX500DistinguishedName& aName) const;
|
sl@0
|
180 |
|
sl@0
|
181 |
/** <!--
|
sl@0
|
182 |
// This function checks if the elements of iElements are a superset of
|
sl@0
|
183 |
// the fields in aName.
|
sl@0
|
184 |
// @param aName We want to check that the fields in aName are present in iElements.
|
sl@0
|
185 |
// @return
|
sl@0
|
186 |
// <UL>
|
sl@0
|
187 |
// <LI>ETrue if all the fields in aName have a corresponding field in iElements.</LI>
|
sl@0
|
188 |
// <LI>EFalse otherwise</LI>
|
sl@0
|
189 |
// </UL>
|
sl@0
|
190 |
-->
|
sl@0
|
191 |
* Tests whether all 'attribute type and value' objects contained in the specified
|
sl@0
|
192 |
* Distinguished Name object are also contained within this Distinguished Name object.
|
sl@0
|
193 |
*
|
sl@0
|
194 |
* This function checks if the elements of iElements are a superset of the fields in aName.
|
sl@0
|
195 |
*
|
sl@0
|
196 |
* @param aName The Distinguished Name object to be compared.
|
sl@0
|
197 |
* @return ETrue, if all 'attribute type and value' objects contained in the specified
|
sl@0
|
198 |
* Distinguished Name object are also contained within this Distinguished Name
|
sl@0
|
199 |
* object; EFalse, otherwise. */
|
sl@0
|
200 |
IMPORT_C TBool IsWithinSubtreeL(const CX500DistinguishedName& aName) const;
|
sl@0
|
201 |
|
sl@0
|
202 |
/** <!--
|
sl@0
|
203 |
// This function compares each of the elements in iElements with aElement. The comparison
|
sl@0
|
204 |
// is made by the CX520AttributeTypeAndValue::ExactMatchL function.
|
sl@0
|
205 |
// @param aElement The element which we want to compare the elements of iElements with.
|
sl@0
|
206 |
// @return
|
sl@0
|
207 |
// <UL>
|
sl@0
|
208 |
// <LI>ETrue if one of the elements in iElements is equal to aElement.</LI>
|
sl@0
|
209 |
// <LI>EFalse otherwise</LI>
|
sl@0
|
210 |
// </UL>
|
sl@0
|
211 |
-->
|
sl@0
|
212 |
* Tests whether this Distinguished Name object contains the specified 'attribute
|
sl@0
|
213 |
* type and value' object.
|
sl@0
|
214 |
*
|
sl@0
|
215 |
* This function compares each of the elements in iElements with aElement. The comparison
|
sl@0
|
216 |
* is made by the CX520AttributeTypeAndValue::ExactMatchL() function.
|
sl@0
|
217 |
*
|
sl@0
|
218 |
* @param aElement The 'attribute type and value' object to be checked.
|
sl@0
|
219 |
* @return ETrue, if the specified 'attribute type and value' object is contained
|
sl@0
|
220 |
* in this Distinguished Name object; EFalse otherwise. */
|
sl@0
|
221 |
IMPORT_C TBool MatchElementL(const CX520AttributeTypeAndValue& aElement) const;
|
sl@0
|
222 |
|
sl@0
|
223 |
/** Gets the decoded value associated with the specified field/attribute name,
|
sl@0
|
224 |
* from the Distinguished Name.
|
sl@0
|
225 |
*
|
sl@0
|
226 |
* @param aFieldName The field name.
|
sl@0
|
227 |
* @return A heap descriptor containing the decoded value associated with the
|
sl@0
|
228 |
* specified field name. */
|
sl@0
|
229 |
IMPORT_C HBufC* ExtractFieldL(const TDesC& aFieldName) const;
|
sl@0
|
230 |
|
sl@0
|
231 |
/** Gets the decoded value for the common or organisation name.
|
sl@0
|
232 |
*
|
sl@0
|
233 |
* @return A heap descriptor containing the decoded value of the common or organisation name. */
|
sl@0
|
234 |
IMPORT_C HBufC* DisplayNameL() const;
|
sl@0
|
235 |
|
sl@0
|
236 |
/** Encodes a DN into an ASN.1 object tree.
|
sl@0
|
237 |
*
|
sl@0
|
238 |
* Note that the tree has the following format:
|
sl@0
|
239 |
* @code
|
sl@0
|
240 |
* SEQUENCE-OF
|
sl@0
|
241 |
* SET-OF
|
sl@0
|
242 |
* SEQUENCE-OF
|
sl@0
|
243 |
* OID
|
sl@0
|
244 |
* value (usually OCTET STRING)
|
sl@0
|
245 |
* ...
|
sl@0
|
246 |
* @endcode
|
sl@0
|
247 |
*
|
sl@0
|
248 |
* A SEQUENCE-OF object with a changed tag is used instead of
|
sl@0
|
249 |
* a SET-OF object. This should be all right as long as it
|
sl@0
|
250 |
* contains only one child, because otherwise child order in
|
sl@0
|
251 |
* a SET-OF becomes important.
|
sl@0
|
252 |
*
|
sl@0
|
253 |
* This function does not introduce an additional dependency
|
sl@0
|
254 |
* on ASN1 library because X500 library already depends on
|
sl@0
|
255 |
* it -- the attribute type/value class stores and manipulated
|
sl@0
|
256 |
* ASN.1 encodings as its values.
|
sl@0
|
257 |
*
|
sl@0
|
258 |
* @return ASN.1 sequence object containing the DN,
|
sl@0
|
259 |
* pushed on the cleanup stack.
|
sl@0
|
260 |
*/
|
sl@0
|
261 |
IMPORT_C CASN1EncSequence* EncodeASN1LC() const;
|
sl@0
|
262 |
|
sl@0
|
263 |
/** Encodes a DN into an ASN.1 object tree.
|
sl@0
|
264 |
*
|
sl@0
|
265 |
* See note in the description of #EncodeASN1LC for the explanation of
|
sl@0
|
266 |
* the resulting encoding tree format.
|
sl@0
|
267 |
*
|
sl@0
|
268 |
* @return ASN.1 sequence object containing the DN. */
|
sl@0
|
269 |
IMPORT_C CASN1EncSequence* EncodeASN1L() const;
|
sl@0
|
270 |
|
sl@0
|
271 |
private:
|
sl@0
|
272 |
CX500DistinguishedName();
|
sl@0
|
273 |
void ConstructL(const CArrayPtr<CX520AttributeTypeAndValue>& aElements);
|
sl@0
|
274 |
void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
|
sl@0
|
275 |
void ConstructL(RReadStream& aStream);
|
sl@0
|
276 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
277 |
CArrayPtrFlat<CX520AttributeTypeAndValue>* iElements;
|
sl@0
|
278 |
};
|
sl@0
|
279 |
|
sl@0
|
280 |
#endif
|