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