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