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