os/security/cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/common/tkeydetails.cpp
First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Defines the class which represents the structure of the key on
16 * which Crypto Token HAI internally operates. It contains the key
17 * information relevant to Crypto Token HAI.
22 #include "tkeydetails.h"
23 #include <mctkeystore.h>
25 CKeyDetails::CKeyDetails()
28 CKeyDetails::CKeyDetails(
30 TKeyUsagePKCS15 aUsage,
34 const TSecurityPolicy& aUsePolicy,
35 const TSecurityPolicy& aManagementPolicy,
36 EKeyAlgorithm aAlgorithm,
41 HBufC8* aPKCS8AttributeSet)
42 : CKeyInfoBase( aID,aUsage,aSize,aLabel,aHandle,
43 aUsePolicy,aManagementPolicy,aAlgorithm,
44 aAccessType,aNative,aStartDate,aEndDate,aPKCS8AttributeSet)
47 CKeyDetails::~CKeyDetails()
53 TInt CKeyDetails::Handle() const
58 HBufC8* CKeyDetails::PrivateKey() const
63 HBufC8* CKeyDetails::PublicKey() const
68 CKeyDetails* CKeyDetails::NewL( TInt aHandle,
70 const TDesC8& aPrivateKey,
71 const TDesC8& aPublicKey )
74 keyID.FillZ(keyID.MaxSize());
75 TKeyUsagePKCS15 usage = EPKCS15UsageNone;
77 TInt handle = aHandle;
78 const TSecurityPolicy& usePolicy = TSecurityPolicy::EAlwaysPass;
79 const TSecurityPolicy& managementPolicy = TSecurityPolicy::EAlwaysPass;
80 EKeyAlgorithm algorithm = EECC;
81 TInt accessType = CKeyInfoBase::ENeverExtractable;
82 accessType |= CKeyInfoBase::ELocal;
86 HBufC8* pkcs8AttributeSet = NULL;
88 HBufC* label = HBufC::NewLC(aLabel.Length());
89 label->Des().Copy(aLabel);
91 CKeyDetails* keyDetails = new (ELeave) CKeyDetails(keyID,usage,size,label,handle,usePolicy,managementPolicy,algorithm,accessType,native,startDate,endDate,pkcs8AttributeSet);
93 CleanupStack::Pop(label);
94 CleanupStack::PushL(keyDetails);
95 keyDetails->ConstructL(aPrivateKey, aPublicKey);
96 CleanupStack::Pop(keyDetails);
101 CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream)
103 CKeyDetails* self = new (ELeave) CKeyDetails();
104 CleanupStack::PushL(self);
105 self->ConstructL(aReadStream);
106 CleanupStack::Pop(self);
110 void CKeyDetails::ConstructL( const TDesC8& aPrivateKey, const TDesC8& aPublicKey )
112 iPrivateKey = aPrivateKey.AllocL();
113 iPublicKey = aPublicKey.AllocL();
116 void CKeyDetails::ConstructL(RStoreReadStream& aReadStream)
118 CKeyInfoBase::ConstructL(aReadStream);
119 InternalizeL(aReadStream);
122 void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const
124 CKeyInfoBase::ExternalizeL(aWriteStream);
126 TInt stringLen = iPrivateKey->Length();
127 aWriteStream.WriteInt32L(stringLen);
128 TPtr8 keyPtr = iPrivateKey->Des();
129 keyPtr.SetLength(stringLen);
130 aWriteStream.WriteL(keyPtr);
132 stringLen = iPublicKey->Length();
133 aWriteStream.WriteInt32L(stringLen);
134 keyPtr = iPublicKey->Des();
135 keyPtr.SetLength(stringLen);
136 aWriteStream.WriteL(keyPtr);
140 void CKeyDetails::InternalizeL(RReadStream& aReadStream)
142 TInt stringLen = aReadStream.ReadInt32L();
143 iPrivateKey = HBufC8::NewMaxL(stringLen);
144 TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen);
145 privateKeyPtr.FillZ(stringLen);
146 aReadStream.ReadL(privateKeyPtr);
148 stringLen = aReadStream.ReadInt32L();
149 iPublicKey = HBufC8::NewMaxL(stringLen);
150 TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen);
151 publicKeyPtr.FillZ(stringLen);
152 aReadStream.ReadL(publicKeyPtr);