sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Implementation of an attribute type and a value, as defined by the X.520 standard sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: sl@0: #if !defined(__X520AVA_H__) sl@0: #define __X520AVA_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: //these are for internal use only sl@0: //these are the only attribute types we handle at present sl@0: _LIT(KX520CountryName,"2.5.4.6"); sl@0: _LIT(KX520OrganizationName,"2.5.4.10"); sl@0: _LIT(KX520OrganizationalUnitName,"2.5.4.11"); sl@0: _LIT(KX520LocalityName,"2.5.4.7"); sl@0: _LIT(KX520StateOrProvinceName,"2.5.4.8"); sl@0: _LIT(KX520Title,"2.5.4.12"); sl@0: _LIT(KX520CommonName,"2.5.4.3"); sl@0: _LIT(KX520GivenName,"2.5.4.42"); sl@0: _LIT(KX520Surname,"2.5.4.4"); sl@0: _LIT(KX520Initials,"2.5.4.43"); sl@0: _LIT(KX520GenerationQualifier,"2.5.4.44"); sl@0: _LIT(KX520DNQualifier,"2.5.4.46"); sl@0: _LIT(KX520SerialNumber,"2.5.4.5"); sl@0: _LIT(KX520Description,"2.5.4.13"); sl@0: sl@0: //more attribute types we handle at present sl@0: _LIT(KX520PostalCode,"2.5.4.17"); sl@0: _LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25"); sl@0: _LIT(KRFC2256Street,"2.5.4.9"); sl@0: _LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2"); sl@0: sl@0: //email address is deprecated but we support it anyway... sl@0: _LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1"); sl@0: sl@0: /** The maximum length allowed for a country name. */ sl@0: const TInt KX520MaxCLength = 2; sl@0: /** The maximum length allowed for an organization name. */ sl@0: const TInt KX520MaxOLength = 64; sl@0: /** The maximum length allowed for an organizational unit name. */ sl@0: const TInt KX520MaxOULength = 64; sl@0: /** The maximum length allowed for a locality name. */ sl@0: const TInt KX520MaxLLength = 128; sl@0: /** The maximum length allowed for a state or province name. */ sl@0: const TInt KX520MaxSOPLength = 128; sl@0: /** The maximum length allowed for an title. */ sl@0: const TInt KX520MaxTLength = 64; sl@0: /** The maximum length allowed for a common name. */ sl@0: const TInt KX520MaxCNLength = 256; sl@0: /** The maximum length allowed for a given name. */ sl@0: const TInt KX520MaxGNLength = 16; sl@0: /** The maximum length allowed for a surname. */ sl@0: const TInt KX520MaxSLength = 40; sl@0: /** The maximum length allowed for initials. */ sl@0: const TInt KX520MaxILength = 5; sl@0: /** The maximum length allowed for a generation qualifier. */ sl@0: const TInt KX520MaxGQLength = 3; sl@0: /** The maximum length allowed for a serial number. */ sl@0: const TInt KX520MaxSNLength = 64; sl@0: /** The maximum length allowed for a postal code. */ sl@0: const TInt KX520MaxPostalCodeLength = 40; sl@0: /** The maximum length allowed for an email address. */ sl@0: const TInt KPKCS9MaxEmailAddressLength = 256; sl@0: /** The maximum length allowed for an unstructured name. */ sl@0: const TInt KPKCS9MaxUnstructuredNameLength = 256; sl@0: // No maximum was specified in the standard - 128 should be sufficient sl@0: /** The maximum length allowed for an RFC 2247 domain component. sl@0: * sl@0: * Each component of the domain name is a short string. */ sl@0: const TInt KRFC2247MaxDomainComponentLength = 128; sl@0: /** The maximum length allowed a for street. */ sl@0: const TInt KRFC2256StreetLength = 128; sl@0: /** The maximum length allowed for an Description field. */ sl@0: const TInt KX520MaxDescriptionLength = 1024; sl@0: sl@0: sl@0: /** The attribute type. sl@0: * sl@0: * @since v6.0 */ sl@0: enum TAttributeType sl@0: { sl@0: /** A common name */ sl@0: ECommonName, sl@0: /** A locality name */ sl@0: ELocalityName, sl@0: /** A state or province name */ sl@0: EStateOrProvinceName, sl@0: /** An organization name */ sl@0: EOrganizationName, sl@0: /** An organizational unit name */ sl@0: EOrganizationalUnitName, sl@0: /** A title */ sl@0: ETitle, sl@0: /** A qualifier */ sl@0: EDNQualifier, sl@0: /** The name of a country */ sl@0: ECountryName, sl@0: /** A given name */ sl@0: EGivenName, sl@0: /** A surname */ sl@0: ESurname, sl@0: /** Initials */ sl@0: EInitials, sl@0: /** A generation qualifier */ sl@0: EGenerationQualifier, sl@0: /** An email address. This is deprecated. */ sl@0: EPKCS9EmailAddress, sl@0: /** A postal code */ sl@0: EPostalCode, sl@0: /** A serial number */ sl@0: ESerialNumber, sl@0: /** An RFC 2247 domain component. sl@0: * sl@0: * A domain name is made up of an ordered set of components.*/ sl@0: ERFC2247DomainComponent, sl@0: /** RFC 2256 street component. sl@0: * sl@0: * A street */ sl@0: ERFC2256Street, sl@0: /** A name of the subject of a certificate as an unstructured ASCII string */ sl@0: EPKCS9UnstructuredName, sl@0: /** A Description */ sl@0: EX520Description, sl@0: }; sl@0: sl@0: sl@0: class CASN1EncSequence; sl@0: sl@0: class CX520AttributeTypeAndValue : public CBase sl@0: /** Contains an attribute type and a value, as defined by the X.520 standard. sl@0: * sl@0: * A Distinguished Name object, as defined by the X.500 standard, consists of sl@0: * a sequence of these objects. sl@0: * sl@0: * @since v6.0 sl@0: */ sl@0: // Attribute and value pair class. Attribute and value pairs sl@0: // are used in distinguished names and certificate attributes. sl@0: // Stores data in ASN.1 format internally. sl@0: { sl@0: public: sl@0: // Constructs a new object from ASN.1-encoded DER binary data sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing sl@0: * the encoded binary representation. sl@0: * sl@0: * Initialises the object from its encoded binary form into an internal representation. sl@0: * sl@0: * @param aBinaryData The encoded binary representation. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData); sl@0: sl@0: // Constructs a new object from ASN.1-encoded DER binary data sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing sl@0: * the encoded binary representation, and puts a pointer to the new object onto sl@0: * the cleanup stack. sl@0: * sl@0: * Initialises the object from its encoded binary form into an internal representation. sl@0: * sl@0: * @param aBinaryData The encoded binary representation. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData); sl@0: sl@0: // Constructs a new object from ASN.1-encoded DER binary data sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing sl@0: * the encoded binary representation, starting at the specified offset. sl@0: * sl@0: * Initialises the object from its encoded binary form into an internal representation. sl@0: * sl@0: * @param aBinaryData The encoded binary representation. sl@0: * @param aPos The offset position from which to start decoding. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData, TInt& aPos); sl@0: sl@0: // Constructs a new object from ASN.1-encoded DER binary data sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing sl@0: * the encoded binary representation, starting at the specified offset, and puts sl@0: * a pointer to the new object onto the cleanup stack. sl@0: * sl@0: * Initialises the object from its encoded binary form into an internal representation. sl@0: * sl@0: * @param aBinaryData The encoded binary representation. sl@0: * @param aPos The offset position from which to start decoding. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData, TInt& aPos); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from an existing object. sl@0: * sl@0: * This is equivalent to a copy constructor. sl@0: * sl@0: * @param aPair The CX520AttributeTypeAndValue object. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewL(const CX520AttributeTypeAndValue& aPair); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from an existing object, and sl@0: * puts a pointer to the new object onto the cleanup stack. sl@0: * sl@0: * This is equivalent to a copy constructor. sl@0: * sl@0: * @param aPair The CX520AttributeTypeAndValue object. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewLC(const CX520AttributeTypeAndValue& aPair); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified read stream. sl@0: * sl@0: * @param aStream Stream from which the object is to be internalised. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewL(RReadStream& aStream); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from the specified read stream, sl@0: * and puts a pointer to the new object onto the cleanup stack. sl@0: * sl@0: * @param aStream Stream from which the object is to be internalised. sl@0: * @return The new CX520AttributeTypeAndValue object. */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewLC(RReadStream& aStream); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value. sl@0: * sl@0: * @param aType Attribute type sl@0: * @param aValue Attribute value sl@0: * @return New CX520AttributeTypeAndValue object */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewL(TAttributeType aType, const TDesC8& aValue); sl@0: sl@0: /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value. sl@0: * sl@0: * @param aType Attribute type sl@0: * @param aValue Attribute value sl@0: * @return New CX520AttributeTypeAndValue object on the cleanup stack */ sl@0: IMPORT_C static CX520AttributeTypeAndValue* NewLC(TAttributeType aType, const TDesC8& aValue); sl@0: sl@0: /** Destructor. sl@0: * sl@0: * Frees all resources owned by the object, prior to its destruction. */ sl@0: IMPORT_C ~CX520AttributeTypeAndValue(); sl@0: sl@0: /** Gets the encoded attribute type of the object. sl@0: * sl@0: * @return A pointer descriptor representing the encoded attribute type. */ sl@0: IMPORT_C const TPtrC Type() const; sl@0: sl@0: /** Gets the encoded attribute value of the object. sl@0: * sl@0: * @return The pointer descriptor representing the encoded attribute value. */ sl@0: IMPORT_C const TPtrC8 EncodedValue() const; sl@0: sl@0: // Creates a copy of object's ASN.1 DER encoding. sl@0: // @return New buffer containing object's ASN.1 DER encoding. sl@0: /** Gets the decoded value. sl@0: * sl@0: * @return A heap descriptor containing the decoded value. */ sl@0: IMPORT_C virtual HBufC* ValueL() const; sl@0: sl@0: /** Encodes the contents into an ASN.1 sequence object. sl@0: * sl@0: * This is useful to insert attribute type/value pairs into other ASN.1 sl@0: * encoding trees. sl@0: * sl@0: * @return New ASN.1 sequence object containing attribute sl@0: * type/value pair in for of an OID and an octet string; sl@0: * leaves the returned object on the cleanup stack. */ sl@0: IMPORT_C CASN1EncSequence* EncodeASN1LC() const; sl@0: sl@0: /** Encodes the contents into an ASN.1 sequence object. sl@0: * sl@0: * Useful to insert attribute type/value pairs into other ASN.1 sl@0: * encoding trees. sl@0: * sl@0: * @return New ASN.1 sequence object containing attribute sl@0: * type/value pair in for of an OID and an octet string. */ sl@0: IMPORT_C CASN1EncSequence* EncodeASN1L() const; sl@0: sl@0: // This function compares the current element with aElement. sl@0: /** Compares the attribute type and decoded value of the specified object. sl@0: * sl@0: * @param aElement The CX520AttributeTypeAndValue object to be compared. sl@0: * @return ETrue, if the attribute types and the decoded values match; sl@0: * EFalse, otherwise. */ sl@0: IMPORT_C virtual TBool ExactMatchL(const CX520AttributeTypeAndValue& sl@0: aElement) const; sl@0: sl@0: /** Externalises an object of this class to a write stream. sl@0: * sl@0: * The presence of this function means that the standard templated operator<<() sl@0: * can be used to externalise objects of this class. sl@0: * sl@0: * @param aStream Stream to which the object should be externalised. */ sl@0: virtual void ExternalizeL(RWriteStream& aStream) const; sl@0: private: sl@0: virtual void InternalizeL(RReadStream& aStream); sl@0: CX520AttributeTypeAndValue(const TAttributeType aType); sl@0: CX520AttributeTypeAndValue(); ///< Protected default constructor sl@0: void ConstructL(const CX520AttributeTypeAndValue& aPair); sl@0: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); sl@0: void ConstructL(TAttributeType aType, const TDesC8& aValue); sl@0: /** sl@0: * This method finds out if case-insensitive comparisons must be done or not. sl@0: * Email Address is the exceptional case of 'IA5String' value type for which comparisons must be sl@0: * done case-insensitivly. sl@0: * sl@0: * @param aSource contains the encoded value of the attribute type. sl@0: * @return ETrue, if case-insensitive comparisons are to be done. sl@0: * This is only when value type is a Printable String OR if attribute type is an Email Address. sl@0: * EFalse, otherwise. sl@0: */ sl@0: TBool IsCaseInSensitiveL(const TDesC8& aSource) const; sl@0: HBufC* iType; ///< The encoded type sl@0: HBufC8* iValue; ///< The encoded value sl@0: }; sl@0: sl@0: #endif