os/security/cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/common/tkeydetails.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Defines the class which represents the structure of the key on 
sl@0
    16
* which Crypto Token HAI internally operates. It contains the key 
sl@0
    17
* information relevant to Crypto Token HAI.
sl@0
    18
*
sl@0
    19
*/
sl@0
    20
sl@0
    21
sl@0
    22
#include "tkeydetails.h"
sl@0
    23
#include <mctkeystore.h>
sl@0
    24
sl@0
    25
CKeyDetails::CKeyDetails()
sl@0
    26
	{}
sl@0
    27
sl@0
    28
CKeyDetails::CKeyDetails(	
sl@0
    29
		TKeyIdentifier aID,
sl@0
    30
		TKeyUsagePKCS15 aUsage,
sl@0
    31
		TUint aSize, 
sl@0
    32
		HBufC* aLabel,
sl@0
    33
		TInt aHandle,
sl@0
    34
		const TSecurityPolicy& aUsePolicy,
sl@0
    35
		const TSecurityPolicy& aManagementPolicy,
sl@0
    36
		EKeyAlgorithm aAlgorithm,
sl@0
    37
		TInt aAccessType,
sl@0
    38
		TBool aNative,
sl@0
    39
		TTime aStartDate,
sl@0
    40
		TTime aEndDate,
sl@0
    41
		HBufC8* aPKCS8AttributeSet)
sl@0
    42
		: CKeyInfoBase(	aID,aUsage,aSize,aLabel,aHandle,
sl@0
    43
						aUsePolicy,aManagementPolicy,aAlgorithm,
sl@0
    44
						aAccessType,aNative,aStartDate,aEndDate,aPKCS8AttributeSet)
sl@0
    45
		{}
sl@0
    46
sl@0
    47
CKeyDetails::~CKeyDetails()
sl@0
    48
	{
sl@0
    49
	delete iPrivateKey;
sl@0
    50
	delete iPublicKey;
sl@0
    51
	}
sl@0
    52
sl@0
    53
TInt CKeyDetails::Handle() const
sl@0
    54
	{
sl@0
    55
	return iHandle;
sl@0
    56
	}
sl@0
    57
sl@0
    58
HBufC8* CKeyDetails::PrivateKey() const
sl@0
    59
	{
sl@0
    60
	return iPrivateKey;
sl@0
    61
	}
sl@0
    62
sl@0
    63
HBufC8* CKeyDetails::PublicKey() const
sl@0
    64
    {
sl@0
    65
    return iPublicKey;
sl@0
    66
    }
sl@0
    67
sl@0
    68
CKeyDetails* CKeyDetails::NewL(	TInt aHandle, 
sl@0
    69
								const TDesC& aLabel, 
sl@0
    70
								const TDesC8& aPrivateKey, 
sl@0
    71
								const TDesC8& aPublicKey )
sl@0
    72
	{
sl@0
    73
	TKeyIdentifier keyID;
sl@0
    74
	keyID.FillZ(keyID.MaxSize());
sl@0
    75
	TKeyUsagePKCS15 usage = EPKCS15UsageNone;
sl@0
    76
	TUint size = 0;
sl@0
    77
	TInt handle = aHandle;
sl@0
    78
	const TSecurityPolicy& usePolicy = TSecurityPolicy::EAlwaysPass;
sl@0
    79
	const TSecurityPolicy& managementPolicy = TSecurityPolicy::EAlwaysPass;
sl@0
    80
	EKeyAlgorithm algorithm = EECC;
sl@0
    81
	TInt accessType = CKeyInfoBase::ENeverExtractable;
sl@0
    82
	accessType |= CKeyInfoBase::ELocal;
sl@0
    83
	TBool native = ETrue;
sl@0
    84
	TTime startDate = 0;
sl@0
    85
	TTime endDate = 0;
sl@0
    86
	HBufC8* pkcs8AttributeSet = NULL;
sl@0
    87
	
sl@0
    88
	HBufC* label = HBufC::NewLC(aLabel.Length());
sl@0
    89
	label->Des().Copy(aLabel);
sl@0
    90
sl@0
    91
	CKeyDetails* keyDetails = new (ELeave) CKeyDetails(keyID,usage,size,label,handle,usePolicy,managementPolicy,algorithm,accessType,native,startDate,endDate,pkcs8AttributeSet);
sl@0
    92
	
sl@0
    93
	CleanupStack::Pop(label);
sl@0
    94
	CleanupStack::PushL(keyDetails);
sl@0
    95
	keyDetails->ConstructL(aPrivateKey, aPublicKey);
sl@0
    96
	CleanupStack::Pop(keyDetails);
sl@0
    97
	return keyDetails;
sl@0
    98
	}
sl@0
    99
sl@0
   100
sl@0
   101
CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream)
sl@0
   102
    {
sl@0
   103
    CKeyDetails* self = new (ELeave) CKeyDetails();
sl@0
   104
    CleanupStack::PushL(self);
sl@0
   105
    self->ConstructL(aReadStream);
sl@0
   106
    CleanupStack::Pop(self);
sl@0
   107
    return (self);
sl@0
   108
    }
sl@0
   109
sl@0
   110
void CKeyDetails::ConstructL( const TDesC8& aPrivateKey, const TDesC8& aPublicKey )
sl@0
   111
	{
sl@0
   112
	iPrivateKey = aPrivateKey.AllocL();
sl@0
   113
	iPublicKey = aPublicKey.AllocL();   
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CKeyDetails::ConstructL(RStoreReadStream& aReadStream)
sl@0
   117
	{
sl@0
   118
	CKeyInfoBase::ConstructL(aReadStream);
sl@0
   119
	InternalizeL(aReadStream);
sl@0
   120
	}
sl@0
   121
sl@0
   122
void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const
sl@0
   123
    {		
sl@0
   124
    CKeyInfoBase::ExternalizeL(aWriteStream);
sl@0
   125
    
sl@0
   126
    TInt stringLen = iPrivateKey->Length();
sl@0
   127
    aWriteStream.WriteInt32L(stringLen);
sl@0
   128
    TPtr8 keyPtr = iPrivateKey->Des();
sl@0
   129
    keyPtr.SetLength(stringLen);
sl@0
   130
    aWriteStream.WriteL(keyPtr);
sl@0
   131
        
sl@0
   132
    stringLen = iPublicKey->Length();
sl@0
   133
    aWriteStream.WriteInt32L(stringLen);
sl@0
   134
    keyPtr = iPublicKey->Des();
sl@0
   135
    keyPtr.SetLength(stringLen);
sl@0
   136
    aWriteStream.WriteL(keyPtr);
sl@0
   137
    
sl@0
   138
    }
sl@0
   139
sl@0
   140
void CKeyDetails::InternalizeL(RReadStream& aReadStream)
sl@0
   141
    {
sl@0
   142
    TInt stringLen = aReadStream.ReadInt32L();
sl@0
   143
    iPrivateKey = HBufC8::NewMaxL(stringLen);
sl@0
   144
    TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen);
sl@0
   145
    privateKeyPtr.FillZ(stringLen);
sl@0
   146
    aReadStream.ReadL(privateKeyPtr);
sl@0
   147
        
sl@0
   148
    stringLen = aReadStream.ReadInt32L();
sl@0
   149
    iPublicKey = HBufC8::NewMaxL(stringLen);
sl@0
   150
    TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen);
sl@0
   151
    publicKeyPtr.FillZ(stringLen);
sl@0
   152
    aReadStream.ReadL(publicKeyPtr);
sl@0
   153
    
sl@0
   154
    }