os/security/cryptoservices/certificateandkeymgmt/x500/dstringdec.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/x500/dstringdec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 +* Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* This file contains the implementation of the directory string ASN1 object
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#include "X500dec.h"
    1.24 +
    1.25 +/*
    1.26 +
    1.27 +  This file contains the implementation of the following ASN1 data structures:
    1.28 +
    1.29 +	DirectoryString ::= CHOICE {
    1.30 +		  teletexString             TeletexString (SIZE (1..MAX)),
    1.31 +		  printableString           PrintableString (SIZE (1..MAX)),
    1.32 +		  universalString           UniversalString (SIZE (1..MAX)),
    1.33 +		  utf8String              UTF8String (SIZE (1..MAX)),
    1.34 +		  bmpString               BMPString (SIZE(1..MAX))   }
    1.35 +
    1.36 +*/
    1.37 +
    1.38 +TASN1DecX500DirectoryString::TASN1DecX500DirectoryString(void):
    1.39 +iMaxLength(KMaxTInt)
    1.40 +	{
    1.41 +	}
    1.42 +
    1.43 +HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TDesC8& aSource,TInt& aPos, TInt aMaxLength)
    1.44 +
    1.45 +	{
    1.46 +	TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
    1.47 +	TASN1DecGeneric gen(Ptr);
    1.48 +	gen.InitL();
    1.49 +	aPos+=gen.LengthDER();
    1.50 +	HBufC* Object=DecodeContentsL(gen, aMaxLength);
    1.51 +	return Object;
    1.52 +	}
    1.53 +
    1.54 +HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TASN1DecGeneric& aSource, TInt aMaxLength)
    1.55 +
    1.56 +	{
    1.57 +	return DecodeContentsL(aSource, aMaxLength);
    1.58 +	}
    1.59 +
    1.60 +HBufC* TASN1DecX500DirectoryString::DecodeContentsL(const TASN1DecGeneric& aSource, TInt aMaxLength)
    1.61 +	{
    1.62 +	HBufC* res = NULL;
    1.63 +	switch (aSource.Tag())
    1.64 +		{
    1.65 +		case EASN1TeletexString:
    1.66 +			{
    1.67 +			TASN1DecTeletexString tStr;
    1.68 +			res = tStr.DecodeDERL(aSource);
    1.69 +			break;
    1.70 +			}
    1.71 +		case EASN1PrintableString:
    1.72 +			{
    1.73 +			TASN1DecPrintableString pStr;
    1.74 +			res = pStr.DecodeDERL(aSource);
    1.75 +			break;
    1.76 +			}
    1.77 +		case EASN1IA5String:
    1.78 +			{
    1.79 +			TASN1DecIA5String pStr;
    1.80 +			res = pStr.DecodeDERL(aSource);
    1.81 +			break;
    1.82 +			}
    1.83 +		case EASN1UTF8String:
    1.84 +			{
    1.85 +			TASN1DecUTF8String pStr;
    1.86 +			res = pStr.DecodeDERL(aSource);
    1.87 +			break;
    1.88 +			}												
    1.89 +		case EASN1BMPString:
    1.90 +			{
    1.91 +			TASN1DecBMPString pStr;
    1.92 +			res = pStr.DecodeDERL(aSource);
    1.93 +			break;	
    1.94 +			}									
    1.95 +		default:
    1.96 +			{
    1.97 +			User::Leave(KErrNotSupported);
    1.98 +			break;
    1.99 +			}
   1.100 +		}
   1.101 +	if (res->Length() > aMaxLength)
   1.102 +		{
   1.103 +		delete res;
   1.104 +		User::Leave(KErrArgument);
   1.105 +		}
   1.106 +	return res;
   1.107 +	}
   1.108 +
   1.109 +void TASN1DecX500DirectoryString::SetMaxLength(TInt aLength)
   1.110 +// perhaps this should have some kind of testing to make sure the current 
   1.111 +// contents are valid...this is not as easy as it might first appear, the 
   1.112 +// contents might be eight or sixteen bits.
   1.113 +	{
   1.114 +	iMaxLength=aLength;
   1.115 +	}