os/security/cryptoservices/certificateandkeymgmt/inc/x520ava.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 an attribute type and a value, as defined by the X.520 standard
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @publishedAll
    23  @released
    24 */
    25  
    26 #if !defined(__X520AVA_H__)
    27 #define __X520AVA_H__
    28 
    29 #include <e32base.h>
    30 #include <e32std.h>
    31 #include <s32std.h>
    32 
    33 //these are for internal use only
    34 //these are the only attribute types we handle at present
    35 _LIT(KX520CountryName,"2.5.4.6");
    36 _LIT(KX520OrganizationName,"2.5.4.10");
    37 _LIT(KX520OrganizationalUnitName,"2.5.4.11");
    38 _LIT(KX520LocalityName,"2.5.4.7");
    39 _LIT(KX520StateOrProvinceName,"2.5.4.8");
    40 _LIT(KX520Title,"2.5.4.12");
    41 _LIT(KX520CommonName,"2.5.4.3");
    42 _LIT(KX520GivenName,"2.5.4.42");
    43 _LIT(KX520Surname,"2.5.4.4");
    44 _LIT(KX520Initials,"2.5.4.43");
    45 _LIT(KX520GenerationQualifier,"2.5.4.44");
    46 _LIT(KX520DNQualifier,"2.5.4.46");
    47 _LIT(KX520SerialNumber,"2.5.4.5");
    48 _LIT(KX520Description,"2.5.4.13");
    49 
    50 //more attribute types we handle at present
    51 _LIT(KX520PostalCode,"2.5.4.17");
    52 _LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25");
    53 _LIT(KRFC2256Street,"2.5.4.9");
    54 _LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2");
    55 
    56 //email address is deprecated but we support it anyway...
    57 _LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1");
    58 
    59 /** The maximum length allowed for a country name. */
    60 const TInt KX520MaxCLength = 2;
    61 /** The maximum length allowed for an organization name. */
    62 const TInt KX520MaxOLength = 64;
    63 /** The maximum length allowed for an organizational unit name. */
    64 const TInt KX520MaxOULength = 64;
    65 /** The maximum length allowed for a locality name. */
    66 const TInt KX520MaxLLength = 128;
    67 /** The maximum length allowed for a state or province name. */
    68 const TInt KX520MaxSOPLength = 128;
    69 /** The maximum length allowed for an title. */
    70 const TInt KX520MaxTLength = 64;
    71 /** The maximum length allowed for a common name. */
    72 const TInt KX520MaxCNLength = 256;
    73 /** The maximum length allowed for a given name. */
    74 const TInt KX520MaxGNLength = 16;
    75 /** The maximum length allowed for a surname. */
    76 const TInt KX520MaxSLength = 40;
    77 /** The maximum length allowed for initials. */
    78 const TInt KX520MaxILength = 5;
    79 /** The maximum length allowed for a generation qualifier. */
    80 const TInt KX520MaxGQLength = 3;
    81 /** The maximum length allowed for a serial number. */
    82 const TInt KX520MaxSNLength = 64;
    83 /** The maximum length allowed for a postal code. */
    84 const TInt KX520MaxPostalCodeLength = 40;
    85 /** The maximum length allowed for an email address. */
    86 const TInt KPKCS9MaxEmailAddressLength = 256;
    87 /** The maximum length allowed for an unstructured name. */
    88 const TInt KPKCS9MaxUnstructuredNameLength = 256;
    89 // No maximum was specified in the standard - 128 should be sufficient
    90 /** The maximum length allowed for an RFC 2247 domain component. 
    91 * 
    92 * Each component of the domain name is a short string. */
    93 const TInt KRFC2247MaxDomainComponentLength = 128;
    94 /** The maximum length allowed a for street. */
    95 const TInt KRFC2256StreetLength = 128;
    96 /** The maximum length allowed for an Description field. */
    97 const TInt KX520MaxDescriptionLength = 1024;
    98 
    99 
   100 /** The attribute type. 
   101 * 
   102 * @since v6.0 */
   103 enum TAttributeType
   104 	{
   105 	/** A common name */
   106 	ECommonName,
   107 	/** A locality name */
   108 	ELocalityName,
   109 	/** A state or province name */
   110 	EStateOrProvinceName,
   111 	/** An organization name */
   112 	EOrganizationName,
   113 	/** An organizational unit name */
   114 	EOrganizationalUnitName,
   115 	/** A title */
   116 	ETitle,
   117 	/** A qualifier */
   118 	EDNQualifier,
   119 	/** The name of a country */
   120 	ECountryName,
   121 	/** A given name */
   122 	EGivenName,
   123 	/** A surname */
   124 	ESurname,
   125 	/** Initials */
   126 	EInitials,
   127 	/** A generation qualifier */
   128 	EGenerationQualifier,
   129 	/** An email address. This is deprecated. */
   130 	EPKCS9EmailAddress,
   131 	/** A postal code */
   132 	EPostalCode,
   133 	/** A serial number */
   134 	ESerialNumber,
   135 	/** An RFC 2247 domain component.
   136 	* 
   137 	* A domain name is made up of an ordered set of components.*/
   138 	ERFC2247DomainComponent,
   139 	/** RFC 2256 street component.
   140 	* 
   141 	* A street */
   142 	ERFC2256Street,
   143 	/** A name of the subject of a certificate as an unstructured ASCII string */
   144 	EPKCS9UnstructuredName,
   145 	/** A Description */
   146 	EX520Description,
   147 	};
   148 
   149 
   150 class CASN1EncSequence;
   151 
   152 class CX520AttributeTypeAndValue : public CBase
   153 /** Contains an attribute type and a value, as defined by the X.520 standard.
   154 * 
   155 * A Distinguished Name object, as defined by the X.500 standard, consists of 
   156 * a sequence of these objects. 
   157 * 
   158 * @since v6.0 
   159 */
   160 // Attribute and value pair class. Attribute and value pairs 
   161 //	are used in distinguished names and certificate attributes. 
   162 //	Stores data in ASN.1 format internally.
   163 	{
   164 public:
   165 	// Constructs a new object from ASN.1-encoded DER binary data
   166 	/** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing 
   167 	* the encoded binary representation.
   168 	* 
   169 	* Initialises the object from its encoded binary form into an internal representation.	
   170 	* 
   171 	* @param aBinaryData	The encoded binary representation.
   172 	* @return				The new CX520AttributeTypeAndValue object. */
   173 	IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData);
   174 
   175 	// Constructs a new object from ASN.1-encoded DER binary data
   176 	/** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing 
   177 	* the encoded binary representation, and puts a pointer to the new object onto 
   178 	* the cleanup stack.
   179 	* 
   180 	* Initialises the object from its encoded binary form into an internal representation.	
   181 	* 
   182 	* @param aBinaryData	The encoded binary representation.
   183 	* @return				The new CX520AttributeTypeAndValue object. */
   184 	IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData);
   185 
   186 	// Constructs a new object from ASN.1-encoded DER binary data
   187 	/** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing 
   188 	* the encoded binary representation, starting at the specified offset.
   189 	* 
   190 	* Initialises the object from its encoded binary form into an internal representation.
   191 	* 
   192 	* @param aBinaryData	The encoded binary representation.
   193 	* @param aPos			The offset position from which to start decoding.
   194 	* @return				The new CX520AttributeTypeAndValue object. */
   195 	IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData, TInt& aPos);
   196 
   197 	// Constructs a new object from ASN.1-encoded DER binary data
   198 	/** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing 
   199 	* the encoded binary representation, starting at the specified offset, and puts 
   200 	* a pointer to the new object onto the cleanup stack.
   201 	* 
   202 	* Initialises the object from its encoded binary form into an internal representation.
   203 	* 
   204 	* @param aBinaryData	The encoded binary representation.
   205 	* @param aPos			The offset position from which to start decoding.
   206 	* @return				The new CX520AttributeTypeAndValue object. */
   207 	IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData, TInt& aPos);
   208 	
   209 	/** Creates a new CX520AttributeTypeAndValue object from an existing object.
   210 	* 
   211 	* This is equivalent to a copy constructor.
   212 	* 
   213 	* @param aPair	The CX520AttributeTypeAndValue object.
   214 	* @return		The new CX520AttributeTypeAndValue object. */
   215 	IMPORT_C static CX520AttributeTypeAndValue* NewL(const CX520AttributeTypeAndValue& aPair);
   216 	
   217 	/** Creates a new CX520AttributeTypeAndValue object from an existing object, and 
   218 	* puts a pointer to the new object onto the cleanup stack.
   219 	* 
   220 	* This is equivalent to a copy constructor.
   221 	* 
   222 	* @param aPair	The CX520AttributeTypeAndValue object.
   223 	* @return		The new CX520AttributeTypeAndValue object. */
   224 	IMPORT_C static CX520AttributeTypeAndValue* NewLC(const CX520AttributeTypeAndValue& aPair);
   225 	
   226 	/** Creates a new CX520AttributeTypeAndValue object from the specified read stream.
   227 	* 
   228 	* @param aStream	Stream from which the object is to be internalised.
   229 	* @return			The new CX520AttributeTypeAndValue object. */
   230 	IMPORT_C static CX520AttributeTypeAndValue* NewL(RReadStream& aStream);
   231 	
   232 	/** Creates a new CX520AttributeTypeAndValue object from the specified read stream, 
   233 	* and puts a pointer to the new object onto the cleanup stack.
   234 	* 
   235 	* @param aStream	Stream from which the object is to be internalised.
   236 	* @return			The new CX520AttributeTypeAndValue object. */
   237 	IMPORT_C static CX520AttributeTypeAndValue* NewLC(RReadStream& aStream);
   238 
   239 	/** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
   240 	* 
   241 	* @param aType	Attribute type
   242 	* @param aValue	Attribute value
   243 	* @return		New CX520AttributeTypeAndValue object */
   244 	IMPORT_C static CX520AttributeTypeAndValue* NewL(TAttributeType aType, const TDesC8& aValue);
   245 
   246 	/** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
   247 	* 
   248 	* @param aType	Attribute type
   249 	* @param aValue Attribute value
   250 	* @return		New CX520AttributeTypeAndValue object on the cleanup stack */
   251 	IMPORT_C static CX520AttributeTypeAndValue* NewLC(TAttributeType aType, const TDesC8& aValue);
   252 
   253 	/** Destructor.
   254 	* 
   255 	* Frees all resources owned by the object, prior to its destruction. */
   256 	IMPORT_C ~CX520AttributeTypeAndValue();
   257 
   258 	/** Gets the encoded attribute type of the object.
   259 	* 
   260 	* @return	A pointer descriptor representing the encoded attribute type. */
   261 	IMPORT_C const TPtrC Type() const;
   262 
   263 	/** Gets the encoded attribute value of the object.
   264 	* 
   265 	* @return	The pointer descriptor representing the encoded attribute value. */
   266 	IMPORT_C const TPtrC8 EncodedValue() const;
   267 
   268 	// Creates a copy of object's ASN.1 DER encoding.
   269 	// @return	New buffer containing object's ASN.1 DER encoding.
   270 	/** Gets the decoded value.
   271 	* 
   272 	* @return	A heap descriptor containing the decoded value. */
   273 	IMPORT_C virtual HBufC* ValueL() const;
   274 
   275 	/** Encodes the contents into an ASN.1 sequence object.
   276 	* 
   277 	* This is useful to insert attribute type/value pairs into other ASN.1 
   278 	* encoding trees.
   279 	* 
   280 	* @return	New ASN.1 sequence object containing attribute 
   281 	* 			type/value pair in for of an OID and an octet string; 
   282 	*			leaves the returned object on the cleanup stack. */
   283 	IMPORT_C CASN1EncSequence* EncodeASN1LC() const;
   284 
   285 	/** Encodes the contents into an ASN.1 sequence object.
   286 	* 
   287 	* Useful to insert attribute type/value pairs into other ASN.1 
   288 	* encoding trees.
   289 	* 
   290 	* @return 	New ASN.1 sequence object containing attribute 
   291 	* 			type/value pair in for of an OID and an octet string. */
   292 	IMPORT_C CASN1EncSequence* EncodeASN1L() const;
   293 
   294 	// This function compares the current element with aElement.
   295 	/** Compares the attribute type and decoded value of the specified object.
   296 	* 
   297 	* @param aElement	The CX520AttributeTypeAndValue object to be compared.
   298 	* @return 			ETrue, if the attribute types and the decoded values match; 
   299 	* 					EFalse, otherwise. */
   300 	IMPORT_C virtual TBool ExactMatchL(const CX520AttributeTypeAndValue& 
   301 		aElement) const;
   302 		
   303 	/** Externalises an object of this class to a write stream.
   304 	* 
   305 	* The presence of this function means that the standard templated operator<<() 
   306 	* can be used to externalise objects of this class.
   307 	* 
   308 	* @param aStream	Stream to which the object should be externalised. */
   309 	virtual void ExternalizeL(RWriteStream& aStream) const;
   310 private:
   311 	virtual void InternalizeL(RReadStream& aStream);
   312 	CX520AttributeTypeAndValue(const TAttributeType aType);
   313 	CX520AttributeTypeAndValue(); ///< Protected default constructor
   314 	void ConstructL(const CX520AttributeTypeAndValue& aPair);
   315 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   316 	void ConstructL(TAttributeType aType, const TDesC8& aValue);
   317 	/**
   318      * This method finds out if case-insensitive comparisons must be done or not.
   319 	 * Email Address is the exceptional case of 'IA5String' value type for which comparisons must be
   320 	 * done case-insensitivly.
   321 	 * 
   322 	 * @param aSource	contains the encoded value of the attribute type.
   323  	 * @return	    	ETrue, if case-insensitive comparisons are to be done. 
   324 	 * 		        	This is only when value type is a Printable String OR if attribute type is an Email Address. 
   325 	 * 		        	EFalse, otherwise.
   326  	 */ 
   327  	TBool IsCaseInSensitiveL(const TDesC8& aSource) const;
   328 	HBufC* iType; ///< The encoded type
   329 	HBufC8* iValue; ///< The encoded value
   330 	};
   331 
   332 #endif