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