sl@0: /* sl@0: * Copyright (c) 2003-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: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "paddingshim.h" sl@0: sl@0: /* CPaddingPKCS7 */ sl@0: EXPORT_C CPaddingPKCS7* CPaddingPKCS7::NewL(TInt aBlockBytes) sl@0: { sl@0: __ASSERT_ALWAYS(aBlockBytes > 0, User::Leave(KErrArgument)); sl@0: return CPaddingPKCS7Shim::NewL(aBlockBytes); sl@0: } sl@0: sl@0: EXPORT_C CPaddingPKCS7* CPaddingPKCS7::NewLC(TInt aBlockBytes) sl@0: { sl@0: CPaddingPKCS7* self = CPaddingPKCS7::NewL(aBlockBytes); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CPaddingPKCS7::CPaddingPKCS7(TInt aBlockBytes):CPadding(aBlockBytes) sl@0: { sl@0: } sl@0: sl@0: void CPaddingPKCS7::DoPadL(const TDesC8& aInput,TDes8& aOutput) sl@0: { sl@0: TInt paddingBytes = BlockSize()-(aInput.Length()%BlockSize()); sl@0: aOutput.Append(aInput); sl@0: aOutput.SetLength(aOutput.Length()+paddingBytes); sl@0: for (TInt i=1;i<=paddingBytes;i++) sl@0: { sl@0: aOutput[aOutput.Length()-i]=(TUint8)(paddingBytes); sl@0: } sl@0: } sl@0: sl@0: void CPaddingPKCS7::UnPadL(const TDesC8& aInput,TDes8& aOutput) sl@0: { sl@0: TUint inputLen = aInput.Length(); sl@0: TUint paddingLen = (TUint)(aInput[inputLen - 1]); sl@0: sl@0: if (paddingLen > inputLen) sl@0: { sl@0: User::Leave(KErrInvalidPadding); sl@0: } sl@0: sl@0: TInt outlen = aInput.Length() - paddingLen; sl@0: sl@0: __ASSERT_DEBUG(aOutput.MaxLength() >= outlen, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); sl@0: sl@0: aOutput.Append(aInput.Left(outlen)); sl@0: for (TInt i=outlen;i