os/security/cryptoservices/certificateandkeymgmt/x500/dstringdec.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2000-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 * This file contains the implementation of the directory string ASN1 object
    16 *
    17 */
    18 
    19 
    20 #include "X500dec.h"
    21 
    22 /*
    23 
    24   This file contains the implementation of the following ASN1 data structures:
    25 
    26 	DirectoryString ::= CHOICE {
    27 		  teletexString             TeletexString (SIZE (1..MAX)),
    28 		  printableString           PrintableString (SIZE (1..MAX)),
    29 		  universalString           UniversalString (SIZE (1..MAX)),
    30 		  utf8String              UTF8String (SIZE (1..MAX)),
    31 		  bmpString               BMPString (SIZE(1..MAX))   }
    32 
    33 */
    34 
    35 TASN1DecX500DirectoryString::TASN1DecX500DirectoryString(void):
    36 iMaxLength(KMaxTInt)
    37 	{
    38 	}
    39 
    40 HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TDesC8& aSource,TInt& aPos, TInt aMaxLength)
    41 
    42 	{
    43 	TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
    44 	TASN1DecGeneric gen(Ptr);
    45 	gen.InitL();
    46 	aPos+=gen.LengthDER();
    47 	HBufC* Object=DecodeContentsL(gen, aMaxLength);
    48 	return Object;
    49 	}
    50 
    51 HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TASN1DecGeneric& aSource, TInt aMaxLength)
    52 
    53 	{
    54 	return DecodeContentsL(aSource, aMaxLength);
    55 	}
    56 
    57 HBufC* TASN1DecX500DirectoryString::DecodeContentsL(const TASN1DecGeneric& aSource, TInt aMaxLength)
    58 	{
    59 	HBufC* res = NULL;
    60 	switch (aSource.Tag())
    61 		{
    62 		case EASN1TeletexString:
    63 			{
    64 			TASN1DecTeletexString tStr;
    65 			res = tStr.DecodeDERL(aSource);
    66 			break;
    67 			}
    68 		case EASN1PrintableString:
    69 			{
    70 			TASN1DecPrintableString pStr;
    71 			res = pStr.DecodeDERL(aSource);
    72 			break;
    73 			}
    74 		case EASN1IA5String:
    75 			{
    76 			TASN1DecIA5String pStr;
    77 			res = pStr.DecodeDERL(aSource);
    78 			break;
    79 			}
    80 		case EASN1UTF8String:
    81 			{
    82 			TASN1DecUTF8String pStr;
    83 			res = pStr.DecodeDERL(aSource);
    84 			break;
    85 			}												
    86 		case EASN1BMPString:
    87 			{
    88 			TASN1DecBMPString pStr;
    89 			res = pStr.DecodeDERL(aSource);
    90 			break;	
    91 			}									
    92 		default:
    93 			{
    94 			User::Leave(KErrNotSupported);
    95 			break;
    96 			}
    97 		}
    98 	if (res->Length() > aMaxLength)
    99 		{
   100 		delete res;
   101 		User::Leave(KErrArgument);
   102 		}
   103 	return res;
   104 	}
   105 
   106 void TASN1DecX500DirectoryString::SetMaxLength(TInt aLength)
   107 // perhaps this should have some kind of testing to make sure the current 
   108 // contents are valid...this is not as easy as it might first appear, the 
   109 // contents might be eight or sixteen bits.
   110 	{
   111 	iMaxLength=aLength;
   112 	}