sl@0: /* sl@0: * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * This file contains the implementation of the directory string ASN1 object sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "X500dec.h" sl@0: sl@0: /* sl@0: sl@0: This file contains the implementation of the following ASN1 data structures: sl@0: sl@0: DirectoryString ::= CHOICE { sl@0: teletexString TeletexString (SIZE (1..MAX)), sl@0: printableString PrintableString (SIZE (1..MAX)), sl@0: universalString UniversalString (SIZE (1..MAX)), sl@0: utf8String UTF8String (SIZE (1..MAX)), sl@0: bmpString BMPString (SIZE(1..MAX)) } sl@0: sl@0: */ sl@0: sl@0: TASN1DecX500DirectoryString::TASN1DecX500DirectoryString(void): sl@0: iMaxLength(KMaxTInt) sl@0: { sl@0: } sl@0: sl@0: HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TDesC8& aSource,TInt& aPos, TInt aMaxLength) sl@0: sl@0: { sl@0: TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos); sl@0: TASN1DecGeneric gen(Ptr); sl@0: gen.InitL(); sl@0: aPos+=gen.LengthDER(); sl@0: HBufC* Object=DecodeContentsL(gen, aMaxLength); sl@0: return Object; sl@0: } sl@0: sl@0: HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TASN1DecGeneric& aSource, TInt aMaxLength) sl@0: sl@0: { sl@0: return DecodeContentsL(aSource, aMaxLength); sl@0: } sl@0: sl@0: HBufC* TASN1DecX500DirectoryString::DecodeContentsL(const TASN1DecGeneric& aSource, TInt aMaxLength) sl@0: { sl@0: HBufC* res = NULL; sl@0: switch (aSource.Tag()) sl@0: { sl@0: case EASN1TeletexString: sl@0: { sl@0: TASN1DecTeletexString tStr; sl@0: res = tStr.DecodeDERL(aSource); sl@0: break; sl@0: } sl@0: case EASN1PrintableString: sl@0: { sl@0: TASN1DecPrintableString pStr; sl@0: res = pStr.DecodeDERL(aSource); sl@0: break; sl@0: } sl@0: case EASN1IA5String: sl@0: { sl@0: TASN1DecIA5String pStr; sl@0: res = pStr.DecodeDERL(aSource); sl@0: break; sl@0: } sl@0: case EASN1UTF8String: sl@0: { sl@0: TASN1DecUTF8String pStr; sl@0: res = pStr.DecodeDERL(aSource); sl@0: break; sl@0: } sl@0: case EASN1BMPString: sl@0: { sl@0: TASN1DecBMPString pStr; sl@0: res = pStr.DecodeDERL(aSource); sl@0: break; sl@0: } sl@0: default: sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: break; sl@0: } sl@0: } sl@0: if (res->Length() > aMaxLength) sl@0: { sl@0: delete res; sl@0: User::Leave(KErrArgument); sl@0: } sl@0: return res; sl@0: } sl@0: sl@0: void TASN1DecX500DirectoryString::SetMaxLength(TInt aLength) sl@0: // perhaps this should have some kind of testing to make sure the current sl@0: // contents are valid...this is not as easy as it might first appear, the sl@0: // contents might be eight or sixteen bits. sl@0: { sl@0: iMaxLength=aLength; sl@0: }