1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/printstrdec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,85 @@
1.4 +/*
1.5 +* Copyright (c) 1998-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 Printable String ASN1 object.
1.19 +* The characters included in this string type are:
1.20 +* AB...Zab...z01...9<space>'()+,-./:?
1.21 +*
1.22 +*/
1.23 +
1.24 +
1.25 +#include <asn1dec.h>
1.26 +
1.27 +const TInt8 PrintableStringValid[256]=
1.28 + {
1.29 +// 0 1 2 3 4 5 6 7 8 9 a b c d e f
1.30 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0
1.31 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 1
1.32 + 0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1, // 2
1.33 + 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // 3
1.34 + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 4
1.35 + 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 5
1.36 + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 6
1.37 + 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 7
1.38 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 8
1.39 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 9
1.40 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // a
1.41 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // b
1.42 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // c
1.43 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // d
1.44 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // e
1.45 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // f
1.46 + };
1.47 +
1.48 +EXPORT_C TASN1DecPrintableString::TASN1DecPrintableString(void)
1.49 + {
1.50 + }
1.51 +
1.52 +TInt TASN1DecPrintableString::CheckValid(const TDesC8& aString)
1.53 +
1.54 + {
1.55 + TInt i;
1.56 + for (i=0;i<aString.Length();i++)
1.57 + {
1.58 + if (PrintableStringValid[aString[i]]==0)
1.59 + {
1.60 + return EFalse;
1.61 + }
1.62 + }
1.63 + return ETrue;
1.64 + }
1.65 +
1.66 +EXPORT_C HBufC* TASN1DecPrintableString::DecodeDERL(const TDesC8& aSource,TInt& aPos)
1.67 +
1.68 + {
1.69 + TPtrC8 Source=aSource.Mid(aPos);
1.70 + TASN1DecGeneric gen(Source);
1.71 + gen.InitL();
1.72 + HBufC* res = DecodeContentsL(gen.GetContentDER());
1.73 + return res;
1.74 + }
1.75 +
1.76 +EXPORT_C HBufC* TASN1DecPrintableString::DecodeDERL(const TASN1DecGeneric& aSource)
1.77 +
1.78 + {
1.79 + return DecodeContentsL(aSource.GetContentDER());
1.80 + }
1.81 +
1.82 +HBufC* TASN1DecPrintableString::DecodeContentsL(const TDesC8& aSource)
1.83 + {
1.84 + HBufC* res = HBufC::NewL(aSource.Length());
1.85 + TPtr pRes = res->Des();
1.86 + pRes.Copy(aSource);
1.87 + return res;
1.88 + }