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