sl@0: /* sl@0: * Copyright (c) 2007-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: * Implementation for class encoding printable strings in ASN1 DER sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: sl@0: const TInt8 PrintableStringValid[256]= sl@0: { sl@0: // 0 1 2 3 4 5 6 7 8 9 a b c d e f sl@0: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0 sl@0: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 1 sl@0: 0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1, // 2 sl@0: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // 3 sl@0: 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 4 sl@0: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 5 sl@0: 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 6 sl@0: 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 7 sl@0: }; sl@0: sl@0: EXPORT_C CASN1EncPrintableString* CASN1EncPrintableString::NewLC(const TDesC8& aStr) sl@0: { sl@0: CASN1EncPrintableString* self = new (ELeave) CASN1EncPrintableString(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aStr); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CASN1EncPrintableString* CASN1EncPrintableString::NewL(const TDesC8& aStr) sl@0: { sl@0: CASN1EncPrintableString* self = NewLC(aStr); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CASN1EncPrintableString::~CASN1EncPrintableString() sl@0: { sl@0: delete iContents; sl@0: } sl@0: sl@0: sl@0: CASN1EncPrintableString::CASN1EncPrintableString() sl@0: : CASN1EncPrimitive(EASN1PrintableString) sl@0: { sl@0: } sl@0: sl@0: TInt CASN1EncPrintableString::CheckValid(const TDesC8& aString) sl@0: { sl@0: TInt i; sl@0: for (i = 0; i < aString.Length(); ++i) sl@0: { sl@0: if ((aString[i] > 0x7F) || (PrintableStringValid[aString[i]] == 0)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: void CASN1EncPrintableString::ConstructL(const TDesC8& aStr) sl@0: { sl@0: if (CheckValid(aStr) == EFalse) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: iContents = aStr.AllocL(); sl@0: CASN1EncPrimitive::ConstructL(); sl@0: } sl@0: sl@0: sl@0: void CASN1EncPrintableString::CalculateContentsLengthDER() sl@0: { sl@0: iContentsLengthDER = iContents->Length(); sl@0: } sl@0: sl@0: sl@0: void CASN1EncPrintableString::WriteContentsDERL(TDes8& aBuf) const sl@0: { sl@0: aBuf.Copy(*iContents); sl@0: }