First public contribution.
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * X509 general name class
32 /** A general name type.
37 typedef TUint TGNType;
47 EX509DirectoryName = 4,
51 //specific name forms we support...
52 //we should probably put these in a file of their own,
53 //but they can stay here for now
57 class CX509DomainName : public CBase
58 /** An X.509 domain name.
60 * Base class for email address and DNS names.
69 * Frees all resources owned by the object, prior to its destruction. */
70 IMPORT_C ~CX509DomainName();
72 /** Tests whether every sub domain in the specified domain name is the same as
73 * the corresponding sub domain in this object, starting at the end.
75 * For example, 'john.doe@symbian.com' is within the subtree 'symbian.com' but
76 * is not within the subtree 'john' or 'symbian'.
78 * @param aName The domain name.
79 * @return ETrue, if every sub domain in the specified domain name is the same
80 as the corresponding sub domain in this object; EFalse, otherwise. */
81 IMPORT_C TBool IsWithinSubtree(const CX509DomainName& aName) const;
83 /** Gets the full domain name.
85 * @return A pointer descriptor representing the full domain name. */
86 IMPORT_C TPtrC Name() const;
88 /** Adds a domain by its subdomains to an array of pointer descriptors.
90 * @param aPos The position within the domain name.
91 * @return ETrue if the domain has been added; EFalse, otherwise.
94 TBool AddDomainL(TInt& aPos);
96 /** Adds a subdomain to an array of pointer descriptors.
98 * @param aPos The position within the domain name.
99 * @return ETrue if the subdomain has been added; EFalse, otherwise.
102 TBool AddSubdomainL(TInt& aPos);
104 /** Adds a subdomain separator after each subdomain entry in an array of pointer
105 * descriptors that represent the subdomains of the domain name.
107 * @param aPos The position within the domain name.
108 * @return ETrue if the subdomain separator has been added; EFalse, otherwise.
111 TBool AddSubdomainSeparatorL(TInt& aPos);
113 /** Validates a string.
115 * @param aStr The string to be verified.
116 * @return ETrue if the string is valid; EFalse, otherwise.*/
117 virtual TBool IsValidString(const TDesC& aStr) const;
119 /** Validates a character.
121 * @param aChar The character to be validated.
122 * @return ETrue if the character is valid; EFalse, otherwise. */
123 virtual TBool IsValidChar(const TChar& aChar) const;
125 /** Tests whether a character is a letter or a numeral.
127 * @param aChar The character to be tested.
128 * @return ETrue if the character is a letter or a numeral; EFalse, otherwise.
131 TBool IsAlphaOrNum(const TChar& aChar) const;
133 /** Tests whether the character is a letter.
135 * @param aChar The character to be tested.
136 * @return ETrue if the character is a letter; EFalse, otherwise.
139 TBool IsAlpha(const TChar& aChar) const;
141 /** Default constructor.
146 /** An array of pointer descriptors representing the subdomains of the DSN name. */
148 /** A heap descriptor representing the full domain name. */
152 //rfc822 email address has the form localpart@domain
154 class CX509RFC822NameSubtree : public CX509DomainName
155 /** A full or partial RFC 822 email address.
157 * The address may not contain the local host name as this is optional.
159 * The object is initialised with 8-bit encoded binary data, which is parsed
160 * into a series of sub domains and an optional local host.
166 /** Creates an RFC 822 email address object from the specified buffer containing
167 * the binary coded representation.
169 * The data is parsed into a series of sub domains and an optional local host.
171 * @param aBinaryData The encoded binary representation.
172 * @return The new RFC 822 email address object. */
173 IMPORT_C static CX509RFC822NameSubtree* NewL(const TDesC8& aBinaryData);
175 /** Creates an RFC 822 email address object from the specified buffer containing
176 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
177 * The data is parsed into a series of sub domains and an optional local host.
179 * @param aBinaryData The encoded binary representation.
180 * @return The new RFC 822 email address object. */
181 IMPORT_C static CX509RFC822NameSubtree* NewLC(const TDesC8& aBinaryData);
183 /** Gets a reference to the array of pointer descriptors representing the subdomains
184 * of the RFC 822 email address.
186 * @return The array of pointer descriptors. */
187 IMPORT_C const RArray<TPtrC>& Rep() const;
190 /** Second-phase constructor.
192 * @param aBinaryData The encoded binary representation. */
193 virtual void ConstructL(const TDesC8& aBinaryData);
195 /** Adds a local host.
197 * @param aPos The position from which to start decoding.
198 * @return ETrue, if the host has been found and added; EFalse, otherwise.
201 TBool AddLocalHostL(TInt& aPos);
203 /** Tests whether the character is valid.
205 * @param aChar The character to be tested.
206 * @return ETrue, if the character is valid; EFalse, otherwise.
209 TBool IsValidChar(const TChar& aChar) const;
212 class CX509RFC822Name : public CX509RFC822NameSubtree
213 /** A full RFC 822 email address.
215 * Exactly as subtree, but requires local host and full domain name.
221 /** Creates a full RFC 822 email address object from the specified buffer containing
222 * the binary coded representation.
224 * The data is parsed into a series of sub domains.
226 * The data must represent a full RFC 822 email address, otherwise this function leaves.
228 * @param aBinaryData The encoded binary representation.
229 * @return The new full RFC 822 email address object. */
230 IMPORT_C static CX509RFC822Name* NewL(const TDesC8& aBinaryData);
232 /** Creates a full RFC 822 email address object from the specified buffer containing
233 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
235 * The data is parsed into a series of sub domains.
237 * The data must represent a full RFC 822 email address, otherwise this function leaves.
239 * @param aBinaryData The encoded binary representation.
240 * @return The new full RFC 822 email address object. */
241 IMPORT_C static CX509RFC822Name* NewLC(const TDesC8& aBinaryData);
243 virtual void ConstructL(const TDesC8& aBinaryData);
246 class CX509DNSNameSubtree : public CX509DomainName
247 /** A Domain Name System (DNS) name subtree.
249 * Initialised with 8-bit encoded binary data, which is parsed into a series
252 * Because it is a subtree it may start with a period. For example, '.symbian.com',
253 * indicating that 'symbian.com' does not lie within the subtree.
259 /** Creates a DNS name object from the specified buffer containing the binary coded
262 * The data is parsed into a series of sub domains.
264 * @param aBinaryData The encoded binary representation.
265 * @return The new DNS name object. */
266 IMPORT_C static CX509DNSNameSubtree* NewL(const TDesC8& aBinaryData);
268 /** Creates a DNS name object from the specified buffer containing the binary coded
269 * representation, and puts a pointer to it onto the cleanup stack.
271 * The data is parsed into a series of sub domains.
273 * @param aBinaryData The encoded binary representation.
274 * @return The new DNS name object. */
275 IMPORT_C static CX509DNSNameSubtree* NewLC(const TDesC8& aBinaryData);
277 // IMPORT_C static CX509DNSNameSubtree* NewL(const CX509DNSNameSubtree& aName);
278 // IMPORT_C static CX509DNSNameSubtree* NewLC(const CX509DNSNameSubtree& aName);
280 /** Gets a reference to the array of pointer descriptors representing the subdomains
283 * @return The array of pointer descriptors. */
284 IMPORT_C const RArray<TPtrC>& Rep() const;
287 void ConstructL(const CX509DNSNameSubtree& aName);
288 void ConstructL(const TDesC8& aBinaryData);
289 TBool IsValidString(const TDesC& aStr) const;
292 class CX509DNSName : public CX509DNSNameSubtree
293 /** A Domain Name System (DNS) name.
295 * The name must begin with a valid sub domain and not a period.
301 /** Creates a DNS name object from the specified buffer containing the binary coded
304 * @param aBinaryData The encoded binary representation.
305 * @return The new DNS name object. */
306 IMPORT_C static CX509DNSName* NewL(const TDesC8& aBinaryData);
308 /** Creates a DNS name object from the specified buffer containing the binary coded
309 * representation, and puts a pointer to it onto the cleanup stack.
311 * @param aBinaryData The encoded binary representation.
312 * @return The new DSN name object. */
313 IMPORT_C static CX509DNSName* NewLC(const TDesC8& aBinaryData);
315 /** Creates a new DSN name object from an existing object.
317 * This is equivalent to a copy constructor.
319 * @param aName The DSN name object to be copied.
320 * @return The DSN name object. */
321 IMPORT_C static CX509DNSName* NewL(const CX509DNSName& aName);
323 /** Creates a new DSN name object from an existing object, and puts a pointer to
324 * it onto the clean up stack.
326 * This is equivalent to a copy constructor.
328 * @param aName The DNS name object to be copied.
329 * @return The new DSN name object. */
330 IMPORT_C static CX509DNSName* NewLC(const CX509DNSName& aName);
332 /** Constructs a new DSN name object from a name string.
334 * @param aNameString The name string.
335 * @return The new DSN name object. */
336 IMPORT_C static CX509DNSName* NewL(const TDesC& aNameString);
338 /** Creates a DSN name object from a name string, and puts a pointer to it onto
341 * @param aNameString The name string.
342 * @return The new DSN name object. */
343 IMPORT_C static CX509DNSName* NewLC(const TDesC& aNameString);
345 void ConstructL(const TDesC8& aBinaryData);
346 void ConstructL(const TDesC& aNameString);
347 void ConstructL(const CX509DNSName& aName);
351 class CX509IPBasedURI : public CBase
354 * The class extracts a DNS name, i.e. the host part of the URI.
356 * Note that it must be of 'ip-based' form (see RFC 1738 section 3.1) and contain
357 * a domain name (not an IP address).
363 /** Creates an IP based URI name object from the specified buffer containing the
364 * binary coded representation.
366 * @param aBinaryData The encoded binary representation.
367 * @return The new URI name object. */
368 IMPORT_C static CX509IPBasedURI* NewL(const TDesC8& aBinaryData);
370 /** Creates a URI name object from the specified buffer containing the binary coded
371 * representation, and puts a pointer to it onto the clean up stack.
373 * @param aBinaryData The encoded binary representation.
374 * @return The new URI name object. */
375 IMPORT_C static CX509IPBasedURI* NewLC(const TDesC8& aBinaryData);
379 * Frees all resources owned by the object, prior to its destruction. */
380 IMPORT_C ~CX509IPBasedURI();
382 /** Gets the host part.
384 * @return The host part. */
385 IMPORT_C const CX509DNSName& Host() const;
387 /** Gets the whole name.
389 * @return A pointer descriptor representing the whole name. */
390 IMPORT_C TPtrC Name() const;
392 /** Default constructor.
397 void ConstructL(const TDesC8& aBinaryData);
398 TPtrC ExtractHostNameL() const;
403 class CX509IPSubnetMask : public CBase
404 /** An IP subnet mask.
406 * Input data is parsed into an 8-bit base address and an 8-bit mask.
411 friend class CX509IPAddress;
413 /** Creates an IP subnet mask object from the specified buffer containing the binary
414 * coded representation.
416 * The data is parsed into an 8-bit base address and an 8-bit mask.
418 * @param aBinaryData The encoded binary representation.
419 * @return The new IP subnet mask object. */
420 IMPORT_C static CX509IPSubnetMask* NewL(const TDesC8& aBinaryData);
422 /** Creates an IP subnet mask object from the specified buffer containing the binary
423 * coded representation, and puts a pointer to it onto the cleanup stack.
425 * The data is parsed into an 8-bit base address and an 8-bit mask.
427 * @param aBinaryData The encoded binary representation.
428 * @return The new IP subnet mask object. */
429 IMPORT_C static CX509IPSubnetMask* NewLC(const TDesC8& aBinaryData);
433 * Frees all resources owned by the object, prior to its destruction. */
434 IMPORT_C ~CX509IPSubnetMask();
436 /** Gets the base IP address.
438 * @return A pointer descriptor representing the base IP address. */
439 IMPORT_C TPtrC8 BaseAddress() const;
441 /** Gets the subnet mask.
443 * @return A pointer descriptor representing the subnet mask. */
444 IMPORT_C TPtrC8 Mask() const;
451 void ConstructL(const TDesC8& aBinaryData);
455 class CX509IPAddress : public CBase
456 /** A single IP address.
462 /** Creates a single IP address object from the specified buffer containing the
463 * binary coded representation.
465 * @param aBinaryData The encoded binary representation.
466 * @return The new single IP addres. */
467 IMPORT_C static CX509IPAddress* NewL(const TDesC8& aBinaryData);
469 /** Creates a single IP address object from the specified buffer containing the
470 * binary coded representation, and puts a pointer to it onto the cleanup stack.
472 * @param aBinaryData The encoded binary representation.
473 * @return The new single IP addres object. */
474 IMPORT_C static CX509IPAddress* NewLC(const TDesC8& aBinaryData);
476 /** Tests whether the IP address lies within the specified subnet address.
478 * @param aName The subnet mask name.
479 * @return ETrue, if the IP address lies within the specified subnet address;
480 * EFalse, otherwise. */
481 IMPORT_C TBool IsWithinSubtree(const CX509IPSubnetMask& aName) const;
485 * Frees all resources owned by the object, prior to its destruction. */
486 IMPORT_C ~CX509IPAddress();
488 /** Gets the IP address.
490 * @return A pointer descriptor representing the single IP address. */
491 IMPORT_C TPtrC8 Address() const;
498 void ConstructL(const TDesC8& aBinaryData);
499 HBufC8* iName;//4 octets for v4, 16 for v6
504 class CX509GeneralName : public CBase
505 /** Defines a general name.
507 * The class contains a tag and a name whose form depends on the value of that tag.
509 * When a General Name is included as part of a Name Constraints Extension, the
510 * values need not be complete names but may be simply subtrees.
512 * For example, 'symbian.com' instead of john.doe@symbian.com'. Both names are
513 * valid subtrees but only the second is a valid RFC822 name.
519 /** Creates a new general name object from the specified buffer containing the
520 * binary coded representation.
522 * @param aBinaryData The encoded binary representation.
523 * @return The new general name object. */
524 IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData);
526 /** Creates a new general name object from the specified buffer containing the
527 * binary coded representation, and puts a pointer to it onto the cleanup stack.
529 * Initialises the object from its encoded binary form into an internal representation.
531 * @param aBinaryData The encoded binary representation.
532 * @return The new general name object. */
533 IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData);
535 /** Creates a new general name object from the specified buffer containing the
536 * binary coded representation,starting at the specified offset.
538 * @param aBinaryData The encoded binary representation.
539 * @param aPos The offset position from which to start decoding.
540 * @return The new general name object. */
541 IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData, TInt& aPos);
543 /** Creates a new general name object from the specified buffer containing the
544 * binary coded representation, starting at the specified offset, and puts a
545 * pointer to it onto the cleanup stack.
547 * Initialises the object from its encoded binary form into an internal representation.
549 * @param aBinaryData The encoded binary representation.
550 * @param aPos The offset position from which to start decoding.
551 * @return The new general name object. */
552 IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
554 /** Creates a new general name object from an existing object.
556 * This is equivalent to a copy constructor.
558 * @param aName The general name object to be copied.
559 * @return The new general name object. */
560 IMPORT_C static CX509GeneralName* NewL(const CX509GeneralName& aName);
562 /** Creates a new general name object from an existing object, and puts a pointer
563 * to it onto the cleanup stack.
565 * This is equivalent to a copy constructor.
567 * @param aName The general name object to be copied.
568 * @return The new general name object. */
569 IMPORT_C static CX509GeneralName* NewLC(const CX509GeneralName& aName);
571 /** Gets the type tag.
573 * @return The type tag. */
574 IMPORT_C TGNType Tag() const;
578 * @return A pointer descriptor representing the name. */
579 IMPORT_C TPtrC8 Data() const;
583 * Frees all resources owned by the object, prior to its destruction. */
584 IMPORT_C ~CX509GeneralName();
586 /** Dummy Function which always returns EFalse.
587 * @param aName The general name object to be copied.
590 IMPORT_C TBool ExactMatch(const CX509GeneralName& aName) const;
593 CX509GeneralName(TGNType aType);
595 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
596 void ConstructL(const TDesC8& aData);