os/security/cryptoservices/certificateandkeymgmt/asn1/printstrdec.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) 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 Printable String ASN1 object.
    16 * The characters included in this string type are:
    17 * AB...Zab...z01...9<space>'()+,-./:?
    18 *
    19 */
    20 
    21 
    22 #include <asn1dec.h>
    23 
    24 const TInt8 PrintableStringValid[256]=
    25 	{
    26 //  0 1 2 3 4 5 6 7 8 9 a b c d e f
    27 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // 0
    28 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // 1
    29 	0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1,  // 2
    30 	1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,  // 3
    31 	0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,  // 4
    32 	1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,  // 5 
    33 	0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,  // 6
    34 	1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,  // 7 
    35 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // 8
    36 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // 9
    37 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // a
    38 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // b
    39 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // c
    40 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // d
    41 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // e
    42 	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  // f
    43 	};
    44 
    45 EXPORT_C TASN1DecPrintableString::TASN1DecPrintableString(void)
    46 	{
    47 	}
    48 
    49 TInt TASN1DecPrintableString::CheckValid(const TDesC8& aString)
    50 
    51 	{
    52 	TInt i;
    53 	for (i=0;i<aString.Length();i++)
    54 		{
    55 		if (PrintableStringValid[aString[i]]==0)
    56 			{
    57 			return EFalse;
    58 			}
    59 		}
    60 	return ETrue;
    61 	}
    62 
    63 EXPORT_C HBufC* TASN1DecPrintableString::DecodeDERL(const TDesC8& aSource,TInt& aPos)
    64 
    65 	{
    66 	TPtrC8 Source=aSource.Mid(aPos);
    67 	TASN1DecGeneric gen(Source);
    68 	gen.InitL();	
    69 	HBufC* res = DecodeContentsL(gen.GetContentDER());
    70 	return res;
    71 	}
    72 
    73 EXPORT_C HBufC* TASN1DecPrintableString::DecodeDERL(const TASN1DecGeneric& aSource)
    74 
    75 	{
    76 	return DecodeContentsL(aSource.GetContentDER());
    77 	}
    78 
    79 HBufC* TASN1DecPrintableString::DecodeContentsL(const TDesC8& aSource)
    80 	{
    81 	HBufC* res = HBufC::NewL(aSource.Length());
    82 	TPtr pRes = res->Des();
    83 	pRes.Copy(aSource);
    84 	return res;
    85 	}