sl@0: /* sl@0: * Copyright (c) 2006-2010 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: * blocktransformationshim.cpp sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "bufferedtransformationshim.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../common/inlines.h" sl@0: sl@0: // CBufferedEncryptorShim sl@0: CBufferedEncryptorShim::CBufferedEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : sl@0: iSymmetricCipherImpl(aSymmetricCipherImpl) sl@0: { sl@0: } sl@0: sl@0: CBufferedEncryptorShim* CBufferedEncryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding) sl@0: { sl@0: CBufferedEncryptorShim* self(0); sl@0: sl@0: // Check whether the block transform contains an SPI plug-in sl@0: TAny* implPtr(0); sl@0: TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); sl@0: if (err == KErrNone && implPtr) sl@0: { sl@0: CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); sl@0: sl@0: const CryptoSpi::TCharacteristics* c(0); sl@0: impl->GetCharacteristicsL(c); sl@0: sl@0: const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( sl@0: static_cast(c)); sl@0: sl@0: // See if the padding mode is recognised by CryptoSpi and if so, check sl@0: // whether the plug-in supports that padding mode. sl@0: TUid paddingMode; sl@0: TAny* paddingPtr = &paddingMode; sl@0: err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0); sl@0: if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode)) sl@0: { sl@0: impl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid); sl@0: impl->SetPaddingModeL(paddingMode); sl@0: self = new(ELeave) CBufferedEncryptorShim(impl); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aBT, aPadding); sl@0: CleanupStack::Pop(self); sl@0: } sl@0: } sl@0: return self; sl@0: } sl@0: sl@0: void CBufferedEncryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) sl@0: { sl@0: CBufferedEncryptor::ConstructL(aBT, aPadding); sl@0: } sl@0: sl@0: void CBufferedEncryptorShim::Process(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) sl@0: } sl@0: sl@0: TInt CBufferedEncryptorShim::MaxOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxOutputLength(aInputLength); sl@0: } sl@0: sl@0: void CBufferedEncryptorShim::Reset() sl@0: { sl@0: iSymmetricCipherImpl->Reset(); sl@0: } sl@0: sl@0: TInt CBufferedEncryptorShim::BlockSize() const sl@0: { sl@0: return BitsToBytes(iSymmetricCipherImpl->BlockSize()); sl@0: } sl@0: sl@0: TInt CBufferedEncryptorShim::KeySize() const sl@0: { sl@0: return iSymmetricCipherImpl->KeySize(); sl@0: } sl@0: sl@0: void CBufferedEncryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); sl@0: } sl@0: sl@0: TInt CBufferedEncryptorShim::MaxFinalOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); sl@0: } sl@0: sl@0: // CBufferedDecryptorShim sl@0: CBufferedDecryptorShim::CBufferedDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : sl@0: iSymmetricCipherImpl(aSymmetricCipherImpl) sl@0: { sl@0: } sl@0: sl@0: CBufferedDecryptorShim* CBufferedDecryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding) sl@0: { sl@0: CBufferedDecryptorShim* self(0); sl@0: sl@0: // Check whether the block transform contains an SPI plug-in sl@0: TAny* implPtr(0); sl@0: TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); sl@0: if (err == KErrNone && implPtr) sl@0: { sl@0: CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); sl@0: sl@0: const CryptoSpi::TCharacteristics* c(0); sl@0: impl->GetCharacteristicsL(c); sl@0: sl@0: const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( sl@0: static_cast(c)); sl@0: sl@0: // See if the padding mode is recognised by CryptoSpi and if so, check sl@0: // whether the plug-in supports that padding mode. sl@0: TUid paddingMode; sl@0: TAny* paddingPtr = &paddingMode; sl@0: err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0); sl@0: if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode)) sl@0: { sl@0: impl->SetCryptoModeL(CryptoSpi::KCryptoModeDecryptUid); sl@0: impl->SetPaddingModeL(paddingMode); sl@0: sl@0: self = new(ELeave) CBufferedDecryptorShim(impl); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aBT, aPadding); sl@0: CleanupStack::Pop(self); sl@0: } sl@0: } sl@0: return self; sl@0: } sl@0: sl@0: void CBufferedDecryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) sl@0: { sl@0: CBufferedDecryptor::ConstructL(aBT, aPadding); sl@0: } sl@0: sl@0: void CBufferedDecryptorShim::Process(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) sl@0: } sl@0: sl@0: TInt CBufferedDecryptorShim::MaxOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxOutputLength(aInputLength); sl@0: } sl@0: sl@0: void CBufferedDecryptorShim::Reset() sl@0: { sl@0: iSymmetricCipherImpl->Reset(); sl@0: } sl@0: sl@0: TInt CBufferedDecryptorShim::BlockSize() const sl@0: { sl@0: return BitsToBytes(iSymmetricCipherImpl->BlockSize()); sl@0: } sl@0: sl@0: TInt CBufferedDecryptorShim::KeySize() const sl@0: { sl@0: return iSymmetricCipherImpl->KeySize(); sl@0: } sl@0: sl@0: void CBufferedDecryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); sl@0: } sl@0: sl@0: TInt CBufferedDecryptorShim::MaxFinalOutputLength(TInt aInputLength) const sl@0: { sl@0: return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); sl@0: }