os/security/crypto/weakcryptospi/source/spi/cryptokeyagreementapi.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * crypto key agreement API implementation
    16 * crypto key agreement API implementation
    17 *
    18 */
    19 
    20 
    21 /**
    22  @file
    23 */
    24 
    25 #include <cryptospi/cryptokeyagreementapi.h>
    26 #include <cryptospi/keyagreementplugin.h>
    27 #include "legacyselector.h"
    28 
    29 using namespace CryptoSpi;
    30 
    31 //
    32 // Implementation of Key Agreement
    33 //
    34 CKeyAgreement* CKeyAgreement::NewL(MKeyAgreement* aKeyAgreement, TInt aHandle)
    35 	{
    36 	CKeyAgreement* self=new(ELeave) CKeyAgreement(aKeyAgreement, aHandle);
    37 	return self;
    38 	}
    39 
    40 CKeyAgreement::CKeyAgreement(MKeyAgreement* aKeyAgreement, TInt aHandle)
    41 : CCryptoBase(aKeyAgreement, aHandle)
    42 	{
    43 	}
    44 
    45 EXPORT_C CKeyAgreement::~CKeyAgreement()
    46 	{
    47 	}
    48 	
    49 EXPORT_C void CKeyAgreement::SetKeyL(const CKey& aSelfPrivateKey, const CCryptoParams* aParams)
    50 	{
    51 	MKeyAgreement* ptr=static_cast<MKeyAgreement*>(iPlugin);
    52 	ptr->SetKeyL(aSelfPrivateKey, aParams);
    53 	}
    54 
    55 EXPORT_C CKey* CKeyAgreement::AgreeL(const CKey& aOtherPublicKey, const CCryptoParams* aParams)
    56 	{
    57 	MKeyAgreement* ptr=static_cast<MKeyAgreement*>(iPlugin);
    58 	return ptr->AgreeL(aOtherPublicKey, aParams);
    59 	}
    60 
    61 //
    62 // Implementation of Key agreement factory
    63 //
    64 EXPORT_C void CKeyAgreementFactory::CreateKeyAgreementL(CKeyAgreement*& aKeyAgreement,
    65 													TUid aAlgorithmUid,
    66 													const CKey& aPrivateKey,
    67 													const CCryptoParams* aAlgorithmParams)
    68 	{
    69 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
    70 	if (selector)
    71 		{
    72 		selector->CreateKeyAgreementL(aKeyAgreement, aAlgorithmUid, aPrivateKey, aAlgorithmParams);
    73 		}
    74 	else
    75 		{
    76 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
    77 		legacySelector->CreateKeyAgreementL(aKeyAgreement, aAlgorithmUid, aPrivateKey, aAlgorithmParams);
    78 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector	
    79 		}
    80 	}
    81 	
    82 //
    83 // Implementation of Asynchronous Key Agreement
    84 // (async methods not implemented, so no coverage)
    85 //
    86 
    87 #ifdef _BullseyeCoverage
    88 #pragma suppress_warnings on
    89 #pragma BullseyeCoverage off
    90 #pragma suppress_warnings off
    91 #endif
    92 
    93 CAsyncKeyAgreement* CAsyncKeyAgreement::NewL(MAsyncKeyAgreement* /*aKeyAgreement*/, TInt /*aHandle*/)
    94 	{
    95 		ASSERT(EFalse);
    96 		return 0;
    97 	}
    98 
    99 CAsyncKeyAgreement::CAsyncKeyAgreement(MAsyncKeyAgreement* aKeyAgreement, TInt aHandle)
   100 : CCryptoBase(aKeyAgreement, aHandle)
   101 	{
   102 		
   103 	}
   104 
   105 EXPORT_C CAsyncKeyAgreement::~CAsyncKeyAgreement()
   106 	{
   107 	}
   108 
   109 EXPORT_C void CAsyncKeyAgreement::SetKeyL(const CKey& aSelfPrivateKey, const CCryptoParams* aParams)
   110 	{
   111 	MAsyncKeyAgreement* ptr=static_cast<MAsyncKeyAgreement*>(iPlugin);
   112 	ptr->SetKeyL(aSelfPrivateKey, aParams);
   113 	}
   114 
   115 EXPORT_C void CAsyncKeyAgreement::AgreeL(const CKey& aOtherPublicKey, CKey& aKey, const CCryptoParams* aParams, TRequestStatus& aRequestStatus)
   116 	{
   117 	MAsyncKeyAgreement* ptr=static_cast<MAsyncKeyAgreement*>(iPlugin);
   118 	return ptr->AgreeL(aOtherPublicKey, aKey, aParams, aRequestStatus);
   119 	}
   120 
   121 EXPORT_C void CKeyAgreementFactory::CreateAsyncKeyAgreementL(CAsyncKeyAgreement*& aKeyAgreement,
   122 														TUid aAlgorithmUid,
   123 														const CKey& aPrivateKey,
   124 														const CCryptoParams* aAlgorithmParams)
   125 	{
   126 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
   127 	if (selector)
   128 		{
   129 		selector->CreateAsyncKeyAgreementL(aKeyAgreement, aAlgorithmUid, aPrivateKey, aAlgorithmParams);
   130 		}
   131 	else
   132 		{
   133 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
   134 		legacySelector->CreateAsyncKeyAgreementL(aKeyAgreement, aAlgorithmUid, aPrivateKey, aAlgorithmParams);
   135 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector	
   136 		}		
   137 	}
   138