sl@0: /* sl@0: * Copyright (c) 2009 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: * Defines the class which represents the structure of the key on sl@0: * which Crypto Token HAI internally operates. It contains the key sl@0: * information relevant to Crypto Token HAI. sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "tkeydetails.h" sl@0: #include sl@0: sl@0: CKeyDetails::CKeyDetails() sl@0: {} sl@0: sl@0: CKeyDetails::CKeyDetails( sl@0: TKeyIdentifier aID, sl@0: TKeyUsagePKCS15 aUsage, sl@0: TUint aSize, sl@0: HBufC* aLabel, sl@0: TInt aHandle, sl@0: const TSecurityPolicy& aUsePolicy, sl@0: const TSecurityPolicy& aManagementPolicy, sl@0: EKeyAlgorithm aAlgorithm, sl@0: TInt aAccessType, sl@0: TBool aNative, sl@0: TTime aStartDate, sl@0: TTime aEndDate, sl@0: HBufC8* aPKCS8AttributeSet) sl@0: : CKeyInfoBase( aID,aUsage,aSize,aLabel,aHandle, sl@0: aUsePolicy,aManagementPolicy,aAlgorithm, sl@0: aAccessType,aNative,aStartDate,aEndDate,aPKCS8AttributeSet) sl@0: {} sl@0: sl@0: CKeyDetails::~CKeyDetails() sl@0: { sl@0: delete iPrivateKey; sl@0: delete iPublicKey; sl@0: } sl@0: sl@0: TInt CKeyDetails::Handle() const sl@0: { sl@0: return iHandle; sl@0: } sl@0: sl@0: HBufC8* CKeyDetails::PrivateKey() const sl@0: { sl@0: return iPrivateKey; sl@0: } sl@0: sl@0: HBufC8* CKeyDetails::PublicKey() const sl@0: { sl@0: return iPublicKey; sl@0: } sl@0: sl@0: CKeyDetails* CKeyDetails::NewL( TInt aHandle, sl@0: const TDesC& aLabel, sl@0: const TDesC8& aPrivateKey, sl@0: const TDesC8& aPublicKey ) sl@0: { sl@0: TKeyIdentifier keyID; sl@0: keyID.FillZ(keyID.MaxSize()); sl@0: TKeyUsagePKCS15 usage = EPKCS15UsageNone; sl@0: TUint size = 0; sl@0: TInt handle = aHandle; sl@0: const TSecurityPolicy& usePolicy = TSecurityPolicy::EAlwaysPass; sl@0: const TSecurityPolicy& managementPolicy = TSecurityPolicy::EAlwaysPass; sl@0: EKeyAlgorithm algorithm = EECC; sl@0: TInt accessType = CKeyInfoBase::ENeverExtractable; sl@0: accessType |= CKeyInfoBase::ELocal; sl@0: TBool native = ETrue; sl@0: TTime startDate = 0; sl@0: TTime endDate = 0; sl@0: HBufC8* pkcs8AttributeSet = NULL; sl@0: sl@0: HBufC* label = HBufC::NewLC(aLabel.Length()); sl@0: label->Des().Copy(aLabel); sl@0: sl@0: CKeyDetails* keyDetails = new (ELeave) CKeyDetails(keyID,usage,size,label,handle,usePolicy,managementPolicy,algorithm,accessType,native,startDate,endDate,pkcs8AttributeSet); sl@0: sl@0: CleanupStack::Pop(label); sl@0: CleanupStack::PushL(keyDetails); sl@0: keyDetails->ConstructL(aPrivateKey, aPublicKey); sl@0: CleanupStack::Pop(keyDetails); sl@0: return keyDetails; sl@0: } sl@0: sl@0: sl@0: CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream) sl@0: { sl@0: CKeyDetails* self = new (ELeave) CKeyDetails(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aReadStream); sl@0: CleanupStack::Pop(self); sl@0: return (self); sl@0: } sl@0: sl@0: void CKeyDetails::ConstructL( const TDesC8& aPrivateKey, const TDesC8& aPublicKey ) sl@0: { sl@0: iPrivateKey = aPrivateKey.AllocL(); sl@0: iPublicKey = aPublicKey.AllocL(); sl@0: } sl@0: sl@0: void CKeyDetails::ConstructL(RStoreReadStream& aReadStream) sl@0: { sl@0: CKeyInfoBase::ConstructL(aReadStream); sl@0: InternalizeL(aReadStream); sl@0: } sl@0: sl@0: void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const sl@0: { sl@0: CKeyInfoBase::ExternalizeL(aWriteStream); sl@0: sl@0: TInt stringLen = iPrivateKey->Length(); sl@0: aWriteStream.WriteInt32L(stringLen); sl@0: TPtr8 keyPtr = iPrivateKey->Des(); sl@0: keyPtr.SetLength(stringLen); sl@0: aWriteStream.WriteL(keyPtr); sl@0: sl@0: stringLen = iPublicKey->Length(); sl@0: aWriteStream.WriteInt32L(stringLen); sl@0: keyPtr = iPublicKey->Des(); sl@0: keyPtr.SetLength(stringLen); sl@0: aWriteStream.WriteL(keyPtr); sl@0: sl@0: } sl@0: sl@0: void CKeyDetails::InternalizeL(RReadStream& aReadStream) sl@0: { sl@0: TInt stringLen = aReadStream.ReadInt32L(); sl@0: iPrivateKey = HBufC8::NewMaxL(stringLen); sl@0: TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen); sl@0: privateKeyPtr.FillZ(stringLen); sl@0: aReadStream.ReadL(privateKeyPtr); sl@0: sl@0: stringLen = aReadStream.ReadInt32L(); sl@0: iPublicKey = HBufC8::NewMaxL(stringLen); sl@0: TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen); sl@0: publicKeyPtr.FillZ(stringLen); sl@0: aReadStream.ReadL(publicKeyPtr); sl@0: sl@0: }