cryptoservices/certificateandkeymgmt/asn1/numstrdec.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     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 * This file contains the implementation of the ASN1 Numeric String class.
       
    16 * This character set includes the digits 0,1,...,9 and the character <space>
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <asn1dec.h>
       
    22 
       
    23 EXPORT_C TASN1DecNumericString::TASN1DecNumericString(void)
       
    24 	{
       
    25 	}
       
    26 
       
    27 EXPORT_C HBufC* TASN1DecNumericString::DecodeDERL(const TDesC8& aSource,TInt& aPos)
       
    28 
       
    29 	{
       
    30 	TPtrC8 Source=aSource.Mid(aPos);
       
    31 	TASN1DecGeneric gen(Source);
       
    32 	gen.InitL();
       
    33 	HBufC* res = DecodeContentsL(gen.GetContentDER());
       
    34 	return res;
       
    35 	}
       
    36 
       
    37 HBufC* TASN1DecNumericString::DecodeContentsL(const TDesC8& aSource)
       
    38 	{
       
    39 	HBufC* res = HBufC::NewL(aSource.Length());
       
    40 	TPtr pRes = res->Des();
       
    41 	pRes.Copy(aSource);
       
    42 	return res;
       
    43 	}
       
    44 
       
    45 TInt TASN1DecNumericString::CheckValid(const TDesC8& aString)
       
    46 
       
    47 	{
       
    48 	TInt i;
       
    49 	for (i=0;i<aString.Length();i++)
       
    50 		{
       
    51 		if ((aString[i]<'0')||(aString[i]>'9'))
       
    52 			{
       
    53 			if (aString[i]!=' ')
       
    54 				{
       
    55 				return KErrArgument;
       
    56 				}
       
    57 			}
       
    58 		}
       
    59 	return KErrNone;
       
    60 	}