epoc32/include/x509gn.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     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 * X509 general name class
    16 *
    17 */
    18 
    19 
    20 
    21 
    22 /**
    23  @file 
    24  @publishedAll
    25  @released
    26 */
    27 
    28 #ifndef __X509GN_H__
    29 #define __X509GN_H__
    30 
    31 #include <e32std.h>
    32 #include <badesca.h>
    33 
    34 /** A general name type.
    35  * 
    36  * @publishedAll
    37  * @released
    38  */
    39 typedef TUint TGNType;
    40 
    41 /**
    42  * @publishedAll
    43  * @released
    44  */
    45 enum 
    46 	{
    47 	EX509RFC822Name = 1,
    48 	EX509DNSName = 2,
    49 	EX509DirectoryName = 4,
    50 	EX509URI = 6,
    51 	EX509IPAddress = 7
    52 	};
    53 //specific name forms we support...
    54 //we should probably put these in a file of their own,
    55 //but they can stay here for now
    56 
    57 //superclass
    58 
    59 class CX509DomainName : public CBase
    60 /** An X.509 domain name.
    61 * 
    62 * Base class for email address and DNS names. 
    63 * 
    64 * @publishedAll
    65 * @released
    66 * @since v6.0 */
    67 	{
    68 public:
    69 	/** Destructor.
    70 	* 
    71 	* Frees all resources owned by the object, prior to its destruction. */
    72 	IMPORT_C ~CX509DomainName();
    73 	
    74 	/** Tests whether every sub domain in the specified domain name is the same as 
    75 	* the corresponding sub domain in this object, starting at the end.
    76 	* 
    77 	* For example, 'john.doe@symbian.com' is within the subtree 'symbian.com' but 
    78 	* is not within the subtree 'john' or 'symbian'.
    79 	* 
    80 	* @param aName	The domain name.
    81 	* @return		ETrue, if every sub domain in the specified domain name is the same 
    82 					as the corresponding sub domain in this object; EFalse, otherwise. */
    83 	IMPORT_C TBool IsWithinSubtree(const CX509DomainName& aName) const;
    84 	
    85 	/** Gets the full domain name.
    86 	* 
    87 	* @return	A pointer descriptor representing the full domain name. */
    88 	IMPORT_C TPtrC Name() const;
    89 protected:
    90 	/** Adds a domain by its subdomains to an array of pointer descriptors.
    91 	* 
    92 	* @param aPos	The position within the domain name.
    93 	* @return		ETrue if the domain has been added; EFalse, otherwise. 
    94 	* @internalAll
    95 	*/
    96 	TBool AddDomainL(TInt& aPos);
    97 	
    98 	/** Adds a subdomain to an array of pointer descriptors.
    99 	* 
   100 	* @param aPos	The position within the domain name.
   101 	* @return		ETrue if the subdomain has been added; EFalse, otherwise. 
   102 	* @internalAll
   103 	*/
   104 	TBool AddSubdomainL(TInt& aPos);
   105 	
   106 	/** Adds a subdomain separator after each subdomain entry in an array of pointer 
   107 	* descriptors that represent the subdomains of the domain name.
   108 	* 
   109 	* @param aPos	The position within the domain name.
   110 	* @return		ETrue if the subdomain separator has been added; EFalse, otherwise. 
   111 	* @internalAll
   112 	*/
   113 	TBool AddSubdomainSeparatorL(TInt& aPos);
   114 	
   115 	/** Validates a string.
   116 	* 
   117 	* @param aStr	The string to be verified.
   118 	* @return		ETrue if the string is valid; EFalse, otherwise.*/
   119 	virtual TBool IsValidString(const TDesC& aStr) const;
   120 	
   121 	/** Validates a character.
   122 	* 
   123 	* @param aChar	The character to be validated.
   124 	* @return		ETrue if the character is valid; EFalse, otherwise. */
   125 	virtual TBool IsValidChar(const TChar& aChar) const;
   126 	
   127 	/** Tests whether a character is a letter or a numeral.
   128 	* 
   129 	* @param aChar	The character to be tested.
   130 	* @return		ETrue if the character is a letter or a numeral; EFalse, otherwise. 
   131 	* @internalAll
   132 	*/
   133 	TBool IsAlphaOrNum(const TChar& aChar) const;
   134 	
   135 	/** Tests whether the character is a letter.
   136 	* 
   137 	* @param aChar	The character to be tested.
   138 	* @return		ETrue if the character is a letter; EFalse, otherwise. 
   139 	* @internalAll
   140 	*/
   141 	TBool IsAlpha(const TChar& aChar) const;
   142 	
   143 	/** Default constructor. 
   144 	 * @internalAll
   145 	 */
   146 	CX509DomainName();
   147 protected:
   148 	/** An array of pointer descriptors representing the subdomains of the DSN name. */
   149 	RArray<TPtrC> iRep;
   150 	/** A heap descriptor representing the full domain name. */
   151 	HBufC* iName;
   152 	};
   153 
   154 //rfc822 email address has the form localpart@domain
   155 
   156 class CX509RFC822NameSubtree : public CX509DomainName
   157 /** A full or partial RFC 822 email address.
   158 * 
   159 * The address may not contain the local host name as this is optional.
   160 * 
   161 * The object is initialised with 8-bit encoded binary data, which is parsed 
   162 * into a series of sub domains and an optional local host. 
   163 *
   164 * @publishedAll
   165 * @released */
   166 	{
   167 public:
   168 	/** Creates an RFC 822 email address object from the specified buffer containing 
   169 	* the binary coded representation.
   170 	* 
   171 	* The data is parsed into a series of sub domains and an optional local host.
   172 	* 
   173 	* @param aBinaryData	The encoded binary representation.
   174 	* @return				The new RFC 822 email address object. */
   175 	IMPORT_C static CX509RFC822NameSubtree* NewL(const TDesC8& aBinaryData);
   176 	
   177 	/** Creates an RFC 822 email address object from the specified buffer containing 
   178 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
   179 	* The data is parsed into a series of sub domains and an optional local host.
   180 	* 
   181 	* @param aBinaryData	The encoded binary representation.
   182 	* @return				The new RFC 822 email address object. */
   183 	IMPORT_C static CX509RFC822NameSubtree* NewLC(const TDesC8& aBinaryData);
   184 	
   185 	/** Gets a reference to the array of pointer descriptors representing the subdomains 
   186 	* of the RFC 822 email address.
   187 	* 
   188 	* @return	The array of pointer descriptors. */
   189 	IMPORT_C const RArray<TPtrC>& Rep() const;
   190 
   191 protected:
   192 	/** Second-phase constructor.
   193 	* 
   194 	* @param aBinaryData	The encoded binary representation. */
   195 	virtual void ConstructL(const TDesC8& aBinaryData);
   196 	
   197 	/** Adds a local host.
   198 	* 
   199 	* @param aPos	The position from which to start decoding.
   200 	* @return		ETrue, if the host has been found and added; EFalse, otherwise. 
   201 	* @internalAll
   202 	*/
   203 	TBool AddLocalHostL(TInt& aPos);
   204 	
   205 	/** Tests whether the character is valid.
   206 	* 
   207 	* @param aChar	The character to be tested.
   208 	* @return		ETrue, if the character is valid; EFalse, otherwise. 
   209 	* @internalAll
   210 	*/
   211 	TBool IsValidChar(const TChar& aChar) const;
   212 	};
   213 
   214 class CX509RFC822Name : public CX509RFC822NameSubtree
   215 /** A full RFC 822 email address.
   216 * 
   217 * Exactly as subtree, but requires local host and full domain name. 
   218 *
   219 * @publishedAll
   220 * @released */
   221 	{
   222 public:
   223 	/** Creates a full RFC 822 email address object from the specified buffer containing 
   224 	* the binary coded representation.
   225 	* 
   226 	* The data is parsed into a series of sub domains.
   227 	* 
   228 	* The data must represent a full RFC 822 email address, otherwise this function leaves.
   229 	* 
   230 	* @param aBinaryData	The encoded binary representation.
   231 	* @return				The new full RFC 822 email address object. */
   232 	IMPORT_C static CX509RFC822Name* NewL(const TDesC8& aBinaryData);
   233 	
   234 	/** Creates a full RFC 822 email address object from the specified buffer containing 
   235 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
   236 	* 
   237 	* The data is parsed into a series of sub domains.
   238 	* 
   239 	* The data must represent a full RFC 822 email address, otherwise this function leaves.
   240 	* 
   241 	* @param aBinaryData	The encoded binary representation.
   242 	* @return				The new full RFC 822 email address object. */
   243 	IMPORT_C static CX509RFC822Name* NewLC(const TDesC8& aBinaryData);
   244 private:
   245 	virtual void ConstructL(const TDesC8& aBinaryData);
   246 	};
   247 
   248 class CX509DNSNameSubtree : public CX509DomainName
   249 /** A Domain Name System (DNS) name subtree.
   250 * 
   251 * Initialised with 8-bit encoded binary data, which is parsed into a series 
   252 * of sub domains.
   253 * 
   254 * Because it is a subtree it may start with a period. For example, '.symbian.com', 
   255 * indicating that 'symbian.com' does not lie within the subtree. 
   256 *
   257 * @publishedAll
   258 * @released */
   259 	{
   260 public:
   261 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   262 	* representation.
   263 	* 
   264 	* The data is parsed into a series of sub domains.
   265 	* 
   266 	* @param aBinaryData	The encoded binary representation.
   267 	* @return				The new DNS name object. */
   268 	IMPORT_C static CX509DNSNameSubtree* NewL(const TDesC8& aBinaryData);
   269 	
   270 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   271 	* representation, and puts a pointer to it onto the cleanup stack.
   272 	* 
   273 	* The data is parsed into a series of sub domains.
   274 	* 
   275 	* @param aBinaryData	The encoded binary representation.
   276 	* @return				The new DNS name object. */
   277 	IMPORT_C static CX509DNSNameSubtree* NewLC(const TDesC8& aBinaryData);
   278 
   279 //	IMPORT_C static CX509DNSNameSubtree* NewL(const CX509DNSNameSubtree& aName);
   280 //	IMPORT_C static CX509DNSNameSubtree* NewLC(const CX509DNSNameSubtree& aName);
   281 	
   282 	/** Gets a reference to the array of pointer descriptors representing the subdomains 
   283 	* of the DSN name.
   284 	* 
   285 	* @return	The array of pointer descriptors. */
   286 	IMPORT_C const RArray<TPtrC>& Rep() const;
   287 	
   288 private:
   289 	void ConstructL(const CX509DNSNameSubtree& aName);
   290 	void ConstructL(const TDesC8& aBinaryData);
   291 	TBool IsValidString(const TDesC& aStr) const;
   292 	};
   293 
   294 class CX509DNSName : public CX509DNSNameSubtree
   295 /** A Domain Name System (DNS) name.
   296 * 
   297 * The name must begin with a valid sub domain and not a period. 
   298 *
   299 * @publishedAll
   300 * @released */
   301 	{
   302 public:
   303 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   304 	* representation.
   305 	* 
   306 	* @param aBinaryData	The encoded binary representation.
   307 	* @return				The new DNS name object. */
   308 	IMPORT_C static CX509DNSName* NewL(const TDesC8& aBinaryData);
   309 	
   310 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   311 	* representation, and puts a pointer to it onto the cleanup stack.
   312 	* 
   313 	* @param aBinaryData	The encoded binary representation.
   314 	* @return				The new DSN name object. */
   315 	IMPORT_C static CX509DNSName* NewLC(const TDesC8& aBinaryData);
   316 	
   317 	/** Creates a new DSN name object from an existing object.
   318 	* 
   319 	* This is equivalent to a copy constructor.
   320 	* 
   321 	* @param aName	The DSN name object to be copied.
   322 	* @return		The DSN name object. */
   323 	IMPORT_C static CX509DNSName* NewL(const CX509DNSName& aName);
   324 	
   325 	/** Creates a new DSN name object from an existing object, and puts a pointer to 
   326 	* it onto the clean up stack.
   327 	* 
   328 	* This is equivalent to a copy constructor.
   329 	* 
   330 	* @param aName	The DNS name object to be copied.
   331 	* @return		The new DSN name object. */
   332 	IMPORT_C static CX509DNSName* NewLC(const CX509DNSName& aName);
   333 	
   334 	/** Constructs a new DSN name object from a name string.
   335 	* 
   336 	* @param aNameString	The name string.
   337 	* @return				The new DSN name object. */
   338 	IMPORT_C static CX509DNSName* NewL(const TDesC& aNameString);
   339 	
   340 	/** Creates a DSN name object from a name string, and puts a pointer to it onto 
   341 	* the cleanup stack.
   342 	* 
   343 	* @param aNameString	The name string.
   344 	* @return				The new DSN name object. */
   345 	IMPORT_C static CX509DNSName* NewLC(const TDesC& aNameString);
   346 private:
   347 	void ConstructL(const TDesC8& aBinaryData);
   348 	void ConstructL(const TDesC& aNameString);
   349 	void ConstructL(const CX509DNSName& aName);
   350 	void ParseNameL();
   351 	};
   352 
   353 class CX509IPBasedURI : public CBase
   354 /** A URI.
   355 * 
   356 * The class extracts a DNS name, i.e. the host part of the URI.
   357 * 
   358 * Note that it must be of 'ip-based' form (see RFC 1738 section 3.1) and contain 
   359 * a domain name (not an IP address). 
   360 *
   361 * @publishedAll
   362 * @released */
   363 	{
   364 public:
   365 	/** Creates an IP based URI name object from the specified buffer containing the 
   366 	* binary coded representation.
   367 	* 
   368 	* @param aBinaryData	The encoded binary representation.
   369 	* @return				The new URI name object. */
   370 	IMPORT_C static CX509IPBasedURI* NewL(const TDesC8& aBinaryData);
   371 	
   372 	/** Creates a URI name object from the specified buffer containing the binary coded 
   373 	* representation, and puts a pointer to it onto the clean up stack.
   374 	* 
   375 	* @param aBinaryData	The encoded binary representation.
   376 	* @return				The new URI name object. */
   377 	IMPORT_C static CX509IPBasedURI* NewLC(const TDesC8& aBinaryData);
   378 	
   379 	/** Destructor.
   380 	* 
   381 	* Frees all resources owned by the object, prior to its destruction. */
   382 	IMPORT_C ~CX509IPBasedURI();
   383 	
   384 	/** Gets the host part.
   385 	* 
   386 	* @return	The host part. */
   387 	IMPORT_C const CX509DNSName& Host() const;
   388 	
   389 	/** Gets the whole name.
   390 	* 
   391 	* @return	A pointer descriptor representing the whole name. */
   392 	IMPORT_C TPtrC Name() const;
   393 	
   394 	/** Default constructor.
   395 	 * @internalAll
   396 	 */
   397 	CX509IPBasedURI();
   398 private:
   399 	void ConstructL(const TDesC8& aBinaryData);
   400 	TPtrC ExtractHostNameL() const;
   401 	CX509DNSName* iHost;
   402 	HBufC* iName;
   403 	};
   404 
   405 class CX509IPSubnetMask : public CBase
   406 /** An IP subnet mask.
   407 * 
   408 * Input data is parsed into an 8-bit base address and an 8-bit mask. 
   409 *
   410 * @publishedAll
   411 * @released */
   412 	{
   413 	friend class CX509IPAddress;
   414 public:
   415 	/** Creates an IP subnet mask object from the specified buffer containing the binary 
   416 	* coded representation.
   417 	* 
   418 	* The data is parsed into an 8-bit base address and an 8-bit mask.
   419 	* 
   420 	* @param aBinaryData	The encoded binary representation.
   421 	* @return				The new IP subnet mask object. */
   422 	IMPORT_C static CX509IPSubnetMask* NewL(const TDesC8& aBinaryData);
   423 	
   424 	/** Creates an IP subnet mask object from the specified buffer containing the binary 
   425 	* coded representation, and puts a pointer to it onto the cleanup stack.
   426 	* 
   427 	* The data is parsed into an 8-bit base address and an 8-bit mask.
   428 	* 
   429 	* @param aBinaryData	The encoded binary representation.
   430 	* @return				The new IP subnet mask object. */
   431 	IMPORT_C static CX509IPSubnetMask* NewLC(const TDesC8& aBinaryData);
   432 	
   433 	/** Destructor.
   434 	* 
   435 	* Frees all resources owned by the object, prior to its destruction. */
   436 	IMPORT_C ~CX509IPSubnetMask();
   437 	
   438 	/** Gets the base IP address.
   439 	* 
   440 	* @return	A pointer descriptor representing the base IP address. */
   441 	IMPORT_C TPtrC8 BaseAddress() const;
   442 	
   443 	/** Gets the subnet mask.
   444 	* 
   445 	* @return	A pointer descriptor representing the subnet mask. */
   446 	IMPORT_C TPtrC8 Mask() const;
   447 	
   448 	/** Constructor. 
   449 	 * @internalAll
   450 	 */
   451 	CX509IPSubnetMask();
   452 private:
   453 	void ConstructL(const TDesC8& aBinaryData);
   454 	HBufC8* iName;
   455 	};
   456 
   457 class CX509IPAddress : public CBase
   458 /** A single IP address. 
   459 *
   460 * @publishedAll
   461 * @released */
   462 	{
   463 public:
   464 	/** Creates a single IP address object from the specified buffer containing the 
   465 	* binary coded representation.
   466 	* 
   467 	* @param aBinaryData	The encoded binary representation.
   468 	* @return				The new single IP addres. */
   469 	IMPORT_C static CX509IPAddress* NewL(const TDesC8& aBinaryData);
   470 	
   471 	/** Creates a single IP address object from the specified buffer containing the 
   472 	* binary coded representation, and puts a pointer to it onto the cleanup stack.
   473 	* 
   474 	* @param aBinaryData	The encoded binary representation.
   475 	* @return				The new single IP addres object. */
   476 	IMPORT_C static CX509IPAddress* NewLC(const TDesC8& aBinaryData);
   477 	
   478 	/** Tests whether the IP address lies within the specified subnet address.
   479 	* 
   480 	* @param aName	The subnet mask name.
   481 	* @return		ETrue, if the IP address lies within the specified subnet address; 
   482 	* EFalse, otherwise. */
   483 	IMPORT_C TBool IsWithinSubtree(const CX509IPSubnetMask& aName) const;
   484 	
   485 	/** Destructor.
   486 	* 
   487 	* Frees all resources owned by the object, prior to its destruction. */
   488 	IMPORT_C ~CX509IPAddress();
   489 	
   490 	/** Gets the IP address.
   491 	* 
   492 	* @return	A pointer descriptor representing the single IP address. */
   493 	IMPORT_C TPtrC8 Address() const;
   494 	
   495 	/** Constructor. 
   496 	 * @internalAll
   497 	 */
   498 	CX509IPAddress();
   499 private:
   500 	void ConstructL(const TDesC8& aBinaryData);
   501 	HBufC8* iName;//4 octets for v4, 16 for v6
   502 	};
   503 
   504 //general name...
   505 
   506 class CX509GeneralName : public CBase
   507 /** Defines a general name.
   508 * 
   509 * The class contains a tag and a name whose form depends on the value of that tag.
   510 * 
   511 * When a General Name is included as part of a Name Constraints Extension, the 
   512 * values need not be complete names but may be simply subtrees.
   513 * 
   514 * For example, 'symbian.com' instead of john.doe@symbian.com'. Both names are 
   515 * valid subtrees but only the second is a valid RFC822 name. 
   516 *
   517 * @publishedAll
   518 * @released */
   519 	{
   520 public:
   521 	/** Creates a new general name object from the specified buffer containing the 
   522 	* binary coded representation.	
   523 	* 
   524 	* @param aBinaryData	The encoded binary representation.
   525 	* @return				The new general name object. */
   526 	IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData);
   527 	
   528 	/** Creates a new general name object from the specified buffer containing the 
   529 	* binary coded representation, and puts a pointer to it onto the cleanup stack.
   530 	* 
   531 	* Initialises the object from its encoded binary form into an internal representation.
   532 	* 
   533 	* @param aBinaryData	The encoded binary representation.
   534 	* @return				The new general name object. */
   535 	IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData);
   536 	
   537 	/** Creates a new general name object from the specified buffer containing the 
   538 	* binary coded representation,starting at the specified offset.
   539 	* 
   540 	* @param aBinaryData	The encoded binary representation.
   541 	* @param aPos			The offset position from which to start decoding.
   542 	* @return				The new general name object. */
   543 	IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData, TInt& aPos);
   544 	
   545 	/** Creates a new general name object from the specified buffer containing the 
   546 	* binary coded representation, starting at the specified offset, and puts a 
   547 	* pointer to it onto the cleanup stack.
   548 	* 
   549 	* Initialises the object from its encoded binary form into an internal representation.
   550 	* 
   551 	* @param aBinaryData	The encoded binary representation.
   552 	* @param aPos			The offset position from which to start decoding.
   553 	* @return				The new general name object. */
   554 	IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
   555 
   556 	/** Creates a new general name object from an existing object.
   557 	* 
   558 	* This is equivalent to a copy constructor.
   559 	* 
   560 	* @param aName			The general name object to be copied.
   561 	* @return				The new general name object. */
   562 	IMPORT_C static CX509GeneralName* NewL(const CX509GeneralName& aName);
   563 	
   564 	/** Creates a new general name object from an existing object, and puts a pointer 
   565 	* to it onto the cleanup stack.
   566 	* 
   567 	* This is equivalent to a copy constructor.
   568 	* 
   569 	* @param aName			The general name object to be copied.
   570 	* @return				The new general name object. */
   571 	IMPORT_C static CX509GeneralName* NewLC(const CX509GeneralName& aName);
   572 
   573 	/** Gets the type tag.
   574 	* 
   575 	* @return	The type tag. */
   576 	IMPORT_C TGNType Tag() const;
   577 	
   578 	/** Gets the name.
   579 	* 
   580 	* @return	A pointer descriptor representing the name. */
   581 	IMPORT_C TPtrC8 Data() const;
   582 	
   583 	/** Destructor.
   584 	* 
   585 	* Frees all resources owned by the object, prior to its destruction. */
   586 	IMPORT_C ~CX509GeneralName(); 
   587 	
   588 	/** Dummy Function which always returns EFalse.
   589 	* @param aName	The general name object to be copied.
   590 	* @return		EFalse.
   591 	*/
   592 	IMPORT_C TBool ExactMatch(const CX509GeneralName& aName) const;
   593 private:
   594 	CX509GeneralName();
   595 	CX509GeneralName(TGNType aType);
   596 	void ConstructL();
   597 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   598 	void ConstructL(const TDesC8& aData);
   599 	TGNType iTag;
   600 	HBufC8* iData;
   601 	};
   602 
   603 #endif