diff -r f5050f1da672 -r 04becd199f91 javaextensions/satsa/apdu/src.s60/cstsace.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaextensions/satsa/apdu/src.s60/cstsace.cpp Tue Apr 27 16:30:29 2010 +0300 @@ -0,0 +1,270 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: + * +*/ + + +// INCLUDE FILES +#include + +#include "cstsace.h" + +namespace java +{ +namespace satsa +{ + +// CONSTANTS +const TTagType KSTSPrincipalsTag = 0; +const TTagType KSTSPermissionsTag = 1; +const TTagType KSTSUserAuthenticationsTag = 2; +const TTagType KSTSApduMaskPermissionTag = 0; + +const TInt KSTSDefaultGranularity = 5; + +// ============================ MEMBER FUNCTIONS =============================== + +// ----------------------------------------------------------------------------- +// CSTSAce::CSTSAce +// C++ default constructor can NOT contain any code, that +// might leave. +// ----------------------------------------------------------------------------- +// +CSTSAce::CSTSAce() +{ +} + +// ----------------------------------------------------------------------------- +// CSTSAce::ConstructL +// Symbian 2nd phase constructor can leave. +// ----------------------------------------------------------------------------- +// +void CSTSAce::ConstructL() +{ + // creating with empty values + iPrincipals + = new(ELeave) CArrayPtrFlat (KSTSDefaultGranularity); + + iApduMaskPermissions + = new(ELeave) CArrayPtrFlat (KSTSDefaultGranularity); + + iUserAuthentications + = new(ELeave) CArrayPtrFlat (KSTSDefaultGranularity); +} + +// ----------------------------------------------------------------------------- +// CSTSAce::NewL +// Two-phased constructor. +// ----------------------------------------------------------------------------- +// +CSTSAce* CSTSAce::NewLC() +{ + CSTSAce* self = new(ELeave) CSTSAce(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; +} + +// Destructor +CSTSAce::~CSTSAce() +{ + if (iPrincipals) + { + iPrincipals->ResetAndDestroy(); + delete iPrincipals; + } + if (iApduMaskPermissions) + { + iApduMaskPermissions->ResetAndDestroy(); + delete iApduMaskPermissions; + } + if (iUserAuthentications) + { + iUserAuthentications->ResetAndDestroy(); + delete iUserAuthentications; + } +} + +// ----------------------------------------------------------------------------- +// CSTSAce::DecodeL +// Decrypts raw data to this instance +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +void CSTSAce::DecodeL(const TDesC8& aRawData) +{ + CArrayPtr* itemsData = DecodeSequenceLC(ETrue, aRawData); //must be sequence + TInt pos = 0; + //decode possible sequence of principal (in loop) + if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() + == KSTSPrincipalsTag)) + { + //no need to check sequence tag + CArrayPtr* principals = DecodeSequenceLC(EFalse, + itemsData->At(pos++)->Encoding()); + + TInt numOfPrincipals = principals->Count(); + + if (numOfPrincipals) + { + CArrayPtr* princArray = new(ELeave) CArrayPtrFlat< + CSTSPrincipal> (numOfPrincipals); + CleanupStack::PushL(princArray); + //if leave occures, array's ResetAndDestroy method will be called + CleanupResetAndDestroyPushL(*princArray); + + for (TInt i = 0; i < numOfPrincipals; i++) + { + CSTSPrincipal* principal = CSTSPrincipal::NewLC(); + principal->DecodeL(principals->At(i)->Encoding()); + princArray->AppendL(principal); + CleanupStack::Pop(principal); + } + + if (iPrincipals) + { + iPrincipals->ResetAndDestroy(); + } + delete iPrincipals; + iPrincipals = princArray; + + CleanupStack::Pop(princArray);//ResetAndDestroy + CleanupStack::Pop(princArray); + } + CleanupStack::PopAndDestroy(principals); + } + + //decode possible sequence of permission (in loop) + if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() + == KSTSPermissionsTag)) + { + //no need to check sequence tag + CArrayPtr* permissions = DecodeSequenceLC(EFalse, + itemsData->At(pos++)->Encoding()); + + TInt numOfPermissions = permissions->Count(); + if (numOfPermissions) + { + CArrayPtr + * permissionArray = new(ELeave) CArrayPtrFlat< + CSTSAPDUMaskPermission> (numOfPermissions); + CleanupStack::PushL(permissionArray); + //if leave occures, array's ResetAndDestroy method will be called + CleanupResetAndDestroyPushL(*permissionArray); + + for (TInt i = 0; i < numOfPermissions; i++) + { + //we need only APDUMAskPermissions + if (permissions->At(i)->Tag() == KSTSApduMaskPermissionTag) + { + CSTSAPDUMaskPermission* permission = + CSTSAPDUMaskPermission::NewLC(); + permission->DecodeL(permissions->At(i)->Encoding()); + permissionArray->AppendL(permission); + CleanupStack::Pop(permission); + } + } + + if (iApduMaskPermissions) + { + iApduMaskPermissions->ResetAndDestroy(); + } + delete iApduMaskPermissions; + iApduMaskPermissions = permissionArray; + + CleanupStack::Pop(permissionArray); //ResetAndDestroy + CleanupStack::Pop(permissionArray); + } + CleanupStack::PopAndDestroy(permissions); + } + + //decode possible sequence of UserAuthentication (in loop) + if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() + == KSTSUserAuthenticationsTag)) + { + //no need to check sequence tag + CArrayPtr* userAuthentications = DecodeSequenceLC( + EFalse, itemsData->At(pos++)->Encoding()); + + TInt numOfUserAuthentications = userAuthentications->Count(); + if (numOfUserAuthentications) + { + + CArrayPtr + * userAuthArray = + new(ELeave) CArrayPtrFlat (numOfUserAuthentications); + CleanupStack::PushL(userAuthArray); + //if leave occures, array's ResetAndDestroy method will be called + CleanupResetAndDestroyPushL(*userAuthArray); + + for (TInt i = 0; i < numOfUserAuthentications; i++) + { + CSTSUserAuth* userAuthentication = CSTSUserAuth::NewLC(); + userAuthentication->DecodeL( + userAuthentications->At(i)->Encoding()); + //we need only EAPDUPinEntry + if (userAuthentication->Type() == CSTSUserAuth::EAPDUPinEntry) + { + userAuthArray->AppendL(userAuthentication); + } + CleanupStack::Pop(userAuthentication); + } + + if (iUserAuthentications) + { + iUserAuthentications->ResetAndDestroy(); + } + delete iUserAuthentications; + iUserAuthentications = userAuthArray; + CleanupStack::Pop(userAuthArray);//ResetAndDestroy + CleanupStack::Pop(userAuthArray); + } + CleanupStack::PopAndDestroy(userAuthentications); + } + CleanupStack::PopAndDestroy(itemsData); +} + +// ----------------------------------------------------------------------------- +// CSTSAce::Principals +// Getter for principals +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +const CArrayPtr& CSTSAce::Principals() const +{ + return *iPrincipals; +} + +// ----------------------------------------------------------------------------- +// CSTSAce::APDUMaskPermissions +// Getter for APDUMaskPermissions +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +const CArrayPtr& CSTSAce::APDUMaskPermissions() const +{ + return *iApduMaskPermissions; +} + +// ----------------------------------------------------------------------------- +// CSTSAce::UserAuthentications +// Getter for UserAuthentications +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +const CArrayPtr& CSTSAce::UserAuthentications() const +{ + return *iUserAuthentications; +} + +} // namespace satsa +} // namespace java +// End of File