williamr@2: /* williamr@2: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * Implementation of the class that holds the Distinguished Name of a subject williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: #if !defined (__X500DN_H__) williamr@2: #define __X500DN_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: class CX500DistinguishedName : public CBase williamr@2: /** Holds the Distinguished Name of a subject. williamr@2: * williamr@2: * A collection of 'attribute type and value' objects, as defined by the X.520 williamr@2: * standard. williamr@2: * williamr@2: * The name used in X.509 certificates is the X.500 Distinguished Name, which williamr@2: * describes a path through an X.500 Directory Information Tree. williamr@2: * williamr@2: * A Distinguished Name is a series of name-value pairs that uniquely identify williamr@2: * an entity, i.e. the certificate subject. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * williamr@2: * williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new Distinguished Name object from the specified buffer containing williamr@2: * the encoded binary representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The position from which to start decoding. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified buffer containing williamr@2: * the encoded binary representation, starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The position from which to start decoding. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified buffer containing williamr@2: * the encoded binary representation. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified buffer containing williamr@2: * the encoded binary representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified read stream. williamr@2: * williamr@2: * Construction is from a stream. williamr@2: * williamr@2: * @param aStream Stream from which the contents should be internalised. williamr@2: * @return The newDistinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewL(RReadStream& aStream); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified read stream, and williamr@2: * puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aStream Stream from which the contents should be internalised. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewLC(RReadStream& aStream); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified array of 'attribute williamr@2: * type and value' objects. williamr@2: * williamr@2: * The elements of the specified array are copied into this object. williamr@2: * williamr@2: * @param aElements The array of 'attribute type and value' objects to be copied. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewL(const CArrayPtr& aElements); williamr@2: williamr@2: /** Creates a new Distinguished Name object from the specified array of 'attribute williamr@2: * type and value' objects, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * The elements of the specified array are copied into this object. williamr@2: * williamr@2: * @param aElements The array of 'attribute type and value' objects to be copied. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewLC(const CArrayPtr& aElements); williamr@2: williamr@2: /** Creates a new Distinguished Name object from an existing object. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aName The Distinguished Name object to be copied. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewL(const CX500DistinguishedName& aName); williamr@2: williamr@2: /** Creates a new Distinguished Name object from an existing object, and puts a williamr@2: * pointer to it onto the cleanup stack. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aName The Distinguished Name object to be copied. williamr@2: * @return The new Distinguished Name object. */ williamr@2: IMPORT_C static CX500DistinguishedName* NewLC(const CX500DistinguishedName& aName); williamr@2: williamr@2: /** Externalises an object of this class to a write stream. williamr@2: * williamr@2: * The presence of this function means that the standard templated operator<<() williamr@2: * can be used to externalise objects of this class. williamr@2: * williamr@2: * @param aStream Stream to which the object should be externalised. */ williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: /** Gets the number of 'attribute type and value' objects contained by this Distinguished williamr@2: * Name object. williamr@2: * williamr@2: * @return The number of 'attribute type and value' objects. */ williamr@2: IMPORT_C TInt Count() const; williamr@2: williamr@2: /** Gets a reference to specific 'attribute type and value' object as identified williamr@2: * by the specified index. williamr@2: * williamr@2: * @param aIndex The index number identifying the specific 'attribute type and williamr@2: * value' object. This number is relative to zero. This value must be non-negative williamr@2: * and less than the number of objects currently contained by this Distinguished williamr@2: * Name object. williamr@2: * @return The referenced 'attribute type and value' object. */ williamr@2: IMPORT_C const CX520AttributeTypeAndValue& Element(TInt aIndex) const; williamr@2: williamr@2: /** Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. */ williamr@2: IMPORT_C ~CX500DistinguishedName(); williamr@2: williamr@2: /** Compares the specified Distinguished Name object with this Distinguished Name williamr@2: * object. williamr@2: * williamr@2: * @param aName The Distinguished Name object to be compared. williamr@2: * @return ETrue, if the Distinguished Name objects contain exactly the same 'attribute williamr@2: * type and value' objects; EFalse, otherwise. williamr@2: * @see CX520AttributeTypeAndValue::ExactMatchL() williamr@2: * williamr@2: * williamr@2: */ williamr@2: IMPORT_C TBool ExactMatchL(const CX500DistinguishedName& aName) const; williamr@2: williamr@2: /** williamr@2: * Tests whether all 'attribute type and value' objects contained in the specified williamr@2: * Distinguished Name object are also contained within this Distinguished Name object. williamr@2: * williamr@2: * This function checks if the elements of iElements are a superset of the fields in aName. williamr@2: * williamr@2: * @param aName The Distinguished Name object to be compared. williamr@2: * @return ETrue, if all 'attribute type and value' objects contained in the specified williamr@2: * Distinguished Name object are also contained within this Distinguished Name williamr@2: * object; EFalse, otherwise. */ williamr@2: IMPORT_C TBool IsWithinSubtreeL(const CX500DistinguishedName& aName) const; williamr@2: williamr@2: /** williamr@2: * Tests whether this Distinguished Name object contains the specified 'attribute williamr@2: * type and value' object. williamr@2: * williamr@2: * This function compares each of the elements in iElements with aElement. The comparison williamr@2: * is made by the CX520AttributeTypeAndValue::ExactMatchL() function. williamr@2: * williamr@2: * @param aElement The 'attribute type and value' object to be checked. williamr@2: * @return ETrue, if the specified 'attribute type and value' object is contained williamr@2: * in this Distinguished Name object; EFalse otherwise. */ williamr@2: IMPORT_C TBool MatchElementL(const CX520AttributeTypeAndValue& aElement) const; williamr@2: williamr@2: /** Gets the decoded value associated with the specified field/attribute name, williamr@2: * from the Distinguished Name. williamr@2: * williamr@2: * @param aFieldName The field name. williamr@2: * @return A heap descriptor containing the decoded value associated with the williamr@2: * specified field name. */ williamr@2: IMPORT_C HBufC* ExtractFieldL(const TDesC& aFieldName) const; williamr@2: williamr@2: /** Gets the decoded value for the common or organisation name. williamr@2: * williamr@2: * @return A heap descriptor containing the decoded value of the common or organisation name. */ williamr@2: IMPORT_C HBufC* DisplayNameL() const; williamr@2: williamr@2: /** Encodes a DN into an ASN.1 object tree. williamr@2: * williamr@2: * Note that the tree has the following format: williamr@2: * @code williamr@2: * SEQUENCE-OF williamr@2: * SET-OF williamr@2: * SEQUENCE-OF williamr@2: * OID williamr@2: * value (usually OCTET STRING) williamr@2: * ... williamr@2: * @endcode williamr@2: * williamr@2: * A SEQUENCE-OF object with a changed tag is used instead of williamr@2: * a SET-OF object. This should be all right as long as it williamr@2: * contains only one child, because otherwise child order in williamr@2: * a SET-OF becomes important. williamr@2: * williamr@2: * This function does not introduce an additional dependency williamr@2: * on ASN1 library because X500 library already depends on williamr@2: * it -- the attribute type/value class stores and manipulated williamr@2: * ASN.1 encodings as its values. williamr@2: * williamr@2: * @return ASN.1 sequence object containing the DN, williamr@2: * pushed on the cleanup stack. williamr@2: */ williamr@2: IMPORT_C CASN1EncSequence* EncodeASN1LC() const; williamr@2: williamr@2: /** Encodes a DN into an ASN.1 object tree. williamr@2: * williamr@2: * See note in the description of #EncodeASN1LC for the explanation of williamr@2: * the resulting encoding tree format. williamr@2: * williamr@2: * @return ASN.1 sequence object containing the DN. */ williamr@2: IMPORT_C CASN1EncSequence* EncodeASN1L() const; williamr@2: williamr@2: private: williamr@2: CX500DistinguishedName(); williamr@2: void ConstructL(const CArrayPtr& aElements); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void ConstructL(RReadStream& aStream); williamr@2: void InternalizeL(RReadStream& aStream); williamr@2: CArrayPtrFlat* iElements; williamr@2: }; williamr@2: williamr@2: #endif