1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/spi/keys.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,109 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Generic Key implementation
1.19 +* Generic Key implementation
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#include <cryptospi/keys.h>
1.29 +#include <cryptospi/cryptoparams.h>
1.30 +#include <cryptospi/cryptospidef.h>
1.31 +#include <cryptopanic.h>
1.32 +
1.33 +using namespace CryptoSpi;
1.34 +
1.35 +EXPORT_C CKey* CKey::NewL(const CKey& aKey)
1.36 + {
1.37 + CKey* self=NewLC(aKey);
1.38 + CleanupStack::Pop();
1.39 + return self;
1.40 + }
1.41 +
1.42 +EXPORT_C CKey* CKey::NewLC(const CKey& aKey)
1.43 + {
1.44 + CKey* self=new(ELeave) CKey(aKey.iKeyProperty);
1.45 + CleanupStack::PushL(self);
1.46 + self->ConstructL(*aKey.iKeyParameters);
1.47 + return self;
1.48 + }
1.49 +
1.50 +EXPORT_C CKey* CKey::NewL(const TKeyProperty& aKeyProperty, const CCryptoParams& aKeyParameters)
1.51 + {
1.52 + CKey* self=NewLC(aKeyProperty, aKeyParameters);
1.53 + CleanupStack::Pop();
1.54 + return self;
1.55 + }
1.56 +
1.57 +EXPORT_C CKey* CKey::NewLC(const TKeyProperty& aKeyProperty, const CCryptoParams& aKeyParameters)
1.58 + {
1.59 + CKey* self=new(ELeave) CKey(aKeyProperty);
1.60 + CleanupStack::PushL(self);
1.61 + self->ConstructL(aKeyParameters);
1.62 + return self;
1.63 + }
1.64 +
1.65 +EXPORT_C const TKeyProperty& CKey::KeyProperty() const
1.66 + {
1.67 + return iKeyProperty;
1.68 + }
1.69 +
1.70 +CKey::CKey(const TKeyProperty& aKeyProperty) : iKeyProperty(aKeyProperty)
1.71 + {
1.72 + }
1.73 +
1.74 +EXPORT_C CKey::~CKey()
1.75 + {
1.76 + // The destructors for each CCryptoParam in this array should securely
1.77 + // delete their contents, e.g. RSA/DSA BigInt exponent and modulus.
1.78 + delete iKeyParameters;
1.79 + }
1.80 +
1.81 +EXPORT_C const TInteger& CKey::GetBigIntL(TUid aUid) const
1.82 + {
1.83 + return iKeyParameters->GetBigIntL(aUid);
1.84 + }
1.85 +
1.86 +EXPORT_C TInt CKey::GetTIntL(TUid aUid) const
1.87 + {
1.88 + return iKeyParameters->GetTIntL(aUid);
1.89 + }
1.90 +
1.91 +EXPORT_C const TDesC8& CKey::GetTDesC8L(TUid aUid) const
1.92 + {
1.93 + return iKeyParameters->GetTDesC8L(aUid);
1.94 + }
1.95 +
1.96 +EXPORT_C TBool CKey::IsPresent(TUid aUid) const
1.97 + {
1.98 + return iKeyParameters->IsPresent(aUid);
1.99 + }
1.100 +
1.101 +void CKey::ConstructL(const CCryptoParams& aKeyParameters)
1.102 + {
1.103 + iKeyParameters = CCryptoParams::NewL();
1.104 + iKeyParameters->CopyL(aKeyParameters);
1.105 + }
1.106 +
1.107 +EXPORT_C const CCryptoParams& CKey::KeyParameters() const
1.108 + {
1.109 + return *iKeyParameters;
1.110 + }
1.111 +
1.112 +