1.1 --- a/epoc32/include/x520ava.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/x520ava.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,327 @@
1.4 -x520ava.h
1.5 +/*
1.6 +* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* under the terms of the License "Eclipse Public License v1.0"
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description:
1.19 +* Implementation of an attribute type and a value, as defined by the X.520 standard
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +
1.25 +
1.26 +/**
1.27 + @file
1.28 + @internalTechnology
1.29 +*/
1.30 +
1.31 +#if !defined(__X520AVA_H__)
1.32 +#define __X520AVA_H__
1.33 +
1.34 +#include <e32base.h>
1.35 +#include <e32std.h>
1.36 +#include <s32std.h>
1.37 +
1.38 +/** The attribute type.
1.39 +*
1.40 +* @publishedAll
1.41 +* @released
1.42 +* @since v6.0 */
1.43 +enum TAttributeType
1.44 + {
1.45 + /** A common name */
1.46 + ECommonName,
1.47 + /** A locality name */
1.48 + ELocalityName,
1.49 + /** A state or province name */
1.50 + EStateOrProvinceName,
1.51 + /** An organization name */
1.52 + EOrganizationName,
1.53 + /** An organizational unit name */
1.54 + EOrganizationalUnitName,
1.55 + /** A title */
1.56 + ETitle,
1.57 + /** A qualifier */
1.58 + EDNQualifier,
1.59 + /** The name of a country */
1.60 + ECountryName,
1.61 + /** A given name */
1.62 + EGivenName,
1.63 + /** A surname */
1.64 + ESurname,
1.65 + /** Initials */
1.66 + EInitials,
1.67 + /** A generation qualifier */
1.68 + EGenerationQualifier,
1.69 + /** An email address. This is deprecated. */
1.70 + EPKCS9EmailAddress,
1.71 + /** A postal code */
1.72 + EPostalCode,
1.73 + /** A serial number */
1.74 + ESerialNumber,
1.75 + /** An RFC 2247 domain component.
1.76 + *
1.77 + * A domain name is made up of an ordered set of components.*/
1.78 + ERFC2247DomainComponent,
1.79 + /** RFC 2256 street component.
1.80 + *
1.81 + * A street */
1.82 + ERFC2256Street,
1.83 + /** A name of the subject of a certificate as an unstructured ASCII string */
1.84 + EPKCS9UnstructuredName
1.85 + };
1.86 +
1.87 +//these are the only attribute types we handle at present
1.88 +_LIT(KX520CountryName,"2.5.4.6");
1.89 +_LIT(KX520OrganizationName,"2.5.4.10");
1.90 +_LIT(KX520OrganizationalUnitName,"2.5.4.11");
1.91 +_LIT(KX520LocalityName,"2.5.4.7");
1.92 +_LIT(KX520StateOrProvinceName,"2.5.4.8");
1.93 +_LIT(KX520Title,"2.5.4.12");
1.94 +_LIT(KX520CommonName,"2.5.4.3");
1.95 +_LIT(KX520GivenName,"2.5.4.42");
1.96 +_LIT(KX520Surname,"2.5.4.4");
1.97 +_LIT(KX520Initials,"2.5.4.43");
1.98 +_LIT(KX520GenerationQualifier,"2.5.4.44");
1.99 +_LIT(KX520DNQualifier,"2.5.4.46");
1.100 +_LIT(KX520SerialNumber,"2.5.4.5");
1.101 +_LIT(KX520PostalCode,"2.5.4.17");
1.102 +_LIT(KRFC2247DomainComponent, "0.9.2342.19200300.100.1.25");
1.103 +_LIT(KRFC2256Street,"2.5.4.9");
1.104 +_LIT(KPKCS9UnstructuredName, "1.2.840.113549.1.9.2");
1.105 +
1.106 +//email address is deprecated but we support it anyway...
1.107 +_LIT(KPKCS9EmailAddress, "1.2.840.113549.1.9.1");
1.108 +
1.109 +/** The maximum length allowed for a country name. */
1.110 +const TInt KX520MaxCLength = 2;
1.111 +/** The maximum length allowed for an organization name. */
1.112 +const TInt KX520MaxOLength = 64;
1.113 +/** The maximum length allowed for an organizational unit name. */
1.114 +const TInt KX520MaxOULength = 64;
1.115 +/** The maximum length allowed for a locality name. */
1.116 +const TInt KX520MaxLLength = 128;
1.117 +/** The maximum length allowed for a state or province name. */
1.118 +const TInt KX520MaxSOPLength = 128;
1.119 +/** The maximum length allowed for an title. */
1.120 +const TInt KX520MaxTLength = 64;
1.121 +/** The maximum length allowed for a common name. */
1.122 +const TInt KX520MaxCNLength = 256;
1.123 +/** The maximum length allowed for a given name. */
1.124 +const TInt KX520MaxGNLength = 16;
1.125 +/** The maximum length allowed for a surname. */
1.126 +const TInt KX520MaxSLength = 40;
1.127 +/** The maximum length allowed for initials. */
1.128 +const TInt KX520MaxILength = 5;
1.129 +/** The maximum length allowed for a generation qualifier. */
1.130 +const TInt KX520MaxGQLength = 3;
1.131 +/** The maximum length allowed for a serial number. */
1.132 +const TInt KX520MaxSNLength = 64;
1.133 +/** The maximum length allowed for a postal code. */
1.134 +const TInt KX520MaxPostalCodeLength = 40;
1.135 +/** The maximum length allowed for an email address. */
1.136 +const TInt KPKCS9MaxEmailAddressLength = 256;
1.137 +/** The maximum length allowed for an unstructured name. */
1.138 +const TInt KPKCS9MaxUnstructuredNameLength = 256;
1.139 +// No maximum was specified in the standard - 128 should be sufficient
1.140 +/** The maximum length allowed for an RFC 2247 domain component.
1.141 +*
1.142 +* Each component of the domain name is a short string. */
1.143 +const TInt KRFC2247MaxDomainComponentLength = 128;
1.144 +/** The maximum length allowed a for street. */
1.145 +const TInt KRFC2256StreetLength = 128;
1.146 +
1.147 +class CASN1EncSequence;
1.148 +
1.149 +class CX520AttributeTypeAndValue : public CBase
1.150 +/** Contains an attribute type and a value, as defined by the X.520 standard.
1.151 +*
1.152 +* A Distinguished Name object, as defined by the X.500 standard, consists of
1.153 +* a sequence of these objects.
1.154 +*
1.155 +* @publishedAll
1.156 +* @released
1.157 +* @since v6.0
1.158 +*/
1.159 +// Attribute and value pair class. Attribute and value pairs
1.160 +// are used in distinguished names and certificate attributes.
1.161 +// Stores data in ASN.1 format internally.
1.162 + {
1.163 +public:
1.164 + // Constructs a new object from ASN.1-encoded DER binary data
1.165 + /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
1.166 + * the encoded binary representation.
1.167 + *
1.168 + * Initialises the object from its encoded binary form into an internal representation.
1.169 + *
1.170 + * @param aBinaryData The encoded binary representation.
1.171 + * @return The new CX520AttributeTypeAndValue object. */
1.172 + IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData);
1.173 +
1.174 + // Constructs a new object from ASN.1-encoded DER binary data
1.175 + /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
1.176 + * the encoded binary representation, and puts a pointer to the new object onto
1.177 + * the cleanup stack.
1.178 + *
1.179 + * Initialises the object from its encoded binary form into an internal representation.
1.180 + *
1.181 + * @param aBinaryData The encoded binary representation.
1.182 + * @return The new CX520AttributeTypeAndValue object. */
1.183 + IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData);
1.184 +
1.185 + // Constructs a new object from ASN.1-encoded DER binary data
1.186 + /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
1.187 + * the encoded binary representation, starting at the specified offset.
1.188 + *
1.189 + * Initialises the object from its encoded binary form into an internal representation.
1.190 + *
1.191 + * @param aBinaryData The encoded binary representation.
1.192 + * @param aPos The offset position from which to start decoding.
1.193 + * @return The new CX520AttributeTypeAndValue object. */
1.194 + IMPORT_C static CX520AttributeTypeAndValue* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.195 +
1.196 + // Constructs a new object from ASN.1-encoded DER binary data
1.197 + /** Creates a new CX520AttributeTypeAndValue object from the specified buffer containing
1.198 + * the encoded binary representation, starting at the specified offset, and puts
1.199 + * a pointer to the new object onto the cleanup stack.
1.200 + *
1.201 + * Initialises the object from its encoded binary form into an internal representation.
1.202 + *
1.203 + * @param aBinaryData The encoded binary representation.
1.204 + * @param aPos The offset position from which to start decoding.
1.205 + * @return The new CX520AttributeTypeAndValue object. */
1.206 + IMPORT_C static CX520AttributeTypeAndValue* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.207 +
1.208 + /** Creates a new CX520AttributeTypeAndValue object from an existing object.
1.209 + *
1.210 + * This is equivalent to a copy constructor.
1.211 + *
1.212 + * @param aPair The CX520AttributeTypeAndValue object.
1.213 + * @return The new CX520AttributeTypeAndValue object. */
1.214 + IMPORT_C static CX520AttributeTypeAndValue* NewL(const CX520AttributeTypeAndValue& aPair);
1.215 +
1.216 + /** Creates a new CX520AttributeTypeAndValue object from an existing object, and
1.217 + * puts a pointer to the new object onto the cleanup stack.
1.218 + *
1.219 + * This is equivalent to a copy constructor.
1.220 + *
1.221 + * @param aPair The CX520AttributeTypeAndValue object.
1.222 + * @return The new CX520AttributeTypeAndValue object. */
1.223 + IMPORT_C static CX520AttributeTypeAndValue* NewLC(const CX520AttributeTypeAndValue& aPair);
1.224 +
1.225 + /** Creates a new CX520AttributeTypeAndValue object from the specified read stream.
1.226 + *
1.227 + * @param aStream Stream from which the object is to be internalised.
1.228 + * @return The new CX520AttributeTypeAndValue object. */
1.229 + IMPORT_C static CX520AttributeTypeAndValue* NewL(RReadStream& aStream);
1.230 +
1.231 + /** Creates a new CX520AttributeTypeAndValue object from the specified read stream,
1.232 + * and puts a pointer to the new object onto the cleanup stack.
1.233 + *
1.234 + * @param aStream Stream from which the object is to be internalised.
1.235 + * @return The new CX520AttributeTypeAndValue object. */
1.236 + IMPORT_C static CX520AttributeTypeAndValue* NewLC(RReadStream& aStream);
1.237 +
1.238 + /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
1.239 + *
1.240 + * @param aType Attribute type
1.241 + * @param aValue Attribute value
1.242 + * @return New CX520AttributeTypeAndValue object */
1.243 + IMPORT_C static CX520AttributeTypeAndValue* NewL(TAttributeType aType, const TDesC8& aValue);
1.244 +
1.245 + /** Creates a new CX520AttributeTypeAndValue object from an attribute type and value.
1.246 + *
1.247 + * @param aType Attribute type
1.248 + * @param aValue Attribute value
1.249 + * @return New CX520AttributeTypeAndValue object on the cleanup stack */
1.250 + IMPORT_C static CX520AttributeTypeAndValue* NewLC(TAttributeType aType, const TDesC8& aValue);
1.251 +
1.252 + /** Destructor.
1.253 + *
1.254 + * Frees all resources owned by the object, prior to its destruction. */
1.255 + IMPORT_C ~CX520AttributeTypeAndValue();
1.256 +
1.257 + /** Gets the encoded attribute type of the object.
1.258 + *
1.259 + * @return A pointer descriptor representing the encoded attribute type. */
1.260 + IMPORT_C const TPtrC Type() const;
1.261 +
1.262 + /** Gets the encoded attribute value of the object.
1.263 + *
1.264 + * @return The pointer descriptor representing the encoded attribute value. */
1.265 + IMPORT_C const TPtrC8 EncodedValue() const;
1.266 +
1.267 + // Creates a copy of object's ASN.1 DER encoding.
1.268 + // @return New buffer containing object's ASN.1 DER encoding.
1.269 + /** Gets the decoded value.
1.270 + *
1.271 + * @return A heap descriptor containing the decoded value. */
1.272 + IMPORT_C virtual HBufC* ValueL() const;
1.273 +
1.274 + /** Encodes the contents into an ASN.1 sequence object.
1.275 + *
1.276 + * This is useful to insert attribute type/value pairs into other ASN.1
1.277 + * encoding trees.
1.278 + *
1.279 + * @return New ASN.1 sequence object containing attribute
1.280 + * type/value pair in for of an OID and an octet string;
1.281 + * leaves the returned object on the cleanup stack. */
1.282 + IMPORT_C CASN1EncSequence* EncodeASN1LC() const;
1.283 +
1.284 + /** Encodes the contents into an ASN.1 sequence object.
1.285 + *
1.286 + * Useful to insert attribute type/value pairs into other ASN.1
1.287 + * encoding trees.
1.288 + *
1.289 + * @return New ASN.1 sequence object containing attribute
1.290 + * type/value pair in for of an OID and an octet string. */
1.291 + IMPORT_C CASN1EncSequence* EncodeASN1L() const;
1.292 +
1.293 + // This function compares the current element with aElement.
1.294 + /** Compares the attribute type and decoded value of the specified object.
1.295 + *
1.296 + * @param aElement The CX520AttributeTypeAndValue object to be compared.
1.297 + * @return ETrue, if the attribute types and the decoded values match;
1.298 + * EFalse, otherwise. */
1.299 + IMPORT_C virtual TBool ExactMatchL(const CX520AttributeTypeAndValue&
1.300 + aElement) const;
1.301 +
1.302 + /** Externalises an object of this class to a write stream.
1.303 + *
1.304 + * The presence of this function means that the standard templated operator<<()
1.305 + * can be used to externalise objects of this class.
1.306 + *
1.307 + * @param aStream Stream to which the object should be externalised. */
1.308 + virtual void ExternalizeL(RWriteStream& aStream) const;
1.309 +private:
1.310 + virtual void InternalizeL(RReadStream& aStream);
1.311 + CX520AttributeTypeAndValue(const TAttributeType aType);
1.312 + CX520AttributeTypeAndValue(); ///< Protected default constructor
1.313 + void ConstructL(const CX520AttributeTypeAndValue& aPair);
1.314 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.315 + void ConstructL(TAttributeType aType, const TDesC8& aValue);
1.316 + /**
1.317 + * This method finds out if case-insensitive comparisons must be done or not.
1.318 + * Email Address is the exceptional case of 'IA5String' value type for which comparisons must be
1.319 + * done case-insensitivly.
1.320 + *
1.321 + * @param aSource contains the encoded value of the attribute type.
1.322 + * @return ETrue, if case-insensitive comparisons are to be done.
1.323 + * This is only when value type is a Printable String OR if attribute type is an Email Address.
1.324 + * EFalse, otherwise.
1.325 + */
1.326 + TBool IsCaseInSensitive(const TDesC8& aSource) const;
1.327 + HBufC* iType; ///< The encoded type
1.328 + HBufC8* iValue; ///< The encoded value
1.329 + };
1.330 +
1.331 +#endif