|
1 /* |
|
2 * Copyright (c) 2009 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 * 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. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 #include "tkeydetails.h" |
|
23 #include <mctkeystore.h> |
|
24 |
|
25 CKeyDetails::CKeyDetails() |
|
26 {} |
|
27 |
|
28 CKeyDetails::~CKeyDetails() |
|
29 { |
|
30 delete iPrivateKey; |
|
31 delete iPublicKey; |
|
32 } |
|
33 |
|
34 TInt CKeyDetails::Handle() const |
|
35 { |
|
36 return iHandle; |
|
37 } |
|
38 |
|
39 HBufC8* CKeyDetails::PrivateKey() const |
|
40 { |
|
41 return iPrivateKey; |
|
42 } |
|
43 |
|
44 HBufC8* CKeyDetails::PublicKey() const |
|
45 { |
|
46 return iPublicKey; |
|
47 } |
|
48 |
|
49 CKeyDetails* CKeyDetails::NewL( TInt aHandle, |
|
50 const TDesC& aLabel, |
|
51 const TDesC8& aPrivateKey, |
|
52 const TDesC8& aPublicKey ) |
|
53 { |
|
54 CKeyDetails* keyDetails = new (ELeave) CKeyDetails(); |
|
55 CleanupStack::PushL(keyDetails); |
|
56 keyDetails->ConstructL(aHandle, aLabel, aPrivateKey, aPublicKey); |
|
57 CleanupStack::Pop(keyDetails); |
|
58 return keyDetails; |
|
59 } |
|
60 |
|
61 |
|
62 CKeyDetails* CKeyDetails::NewL(RStoreReadStream& aReadStream) |
|
63 { |
|
64 CKeyDetails* self = new (ELeave) CKeyDetails(); |
|
65 CleanupStack::PushL(self); |
|
66 self->InternalizeL(aReadStream); |
|
67 CleanupStack::Pop(self); |
|
68 return (self); |
|
69 } |
|
70 |
|
71 void CKeyDetails::ConstructL( TInt aHandle, const TDesC& aLabel, |
|
72 const TDesC8& aPrivateKey, const TDesC8& aPublicKey ) |
|
73 { |
|
74 CKeyInfoBase::ConstructL(); |
|
75 iHandle = aHandle; |
|
76 iLabel = aLabel.AllocL(); |
|
77 iPrivateKey = aPrivateKey.AllocL(); |
|
78 iPublicKey = aPublicKey.AllocL(); |
|
79 |
|
80 // set the access type to never extractable |
|
81 iAccessType |= CKeyInfoBase::ENeverExtractable; |
|
82 iAccessType |= CKeyInfoBase::ELocal; |
|
83 |
|
84 } |
|
85 |
|
86 void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const |
|
87 { |
|
88 aWriteStream.WriteInt32L(iHandle); |
|
89 |
|
90 TInt stringLen = iLabel->Length(); |
|
91 aWriteStream.WriteInt32L(stringLen); |
|
92 TPtr stringPtr = iLabel->Des(); |
|
93 stringPtr.SetLength(stringLen); |
|
94 aWriteStream.WriteL(stringPtr); |
|
95 |
|
96 stringLen = iPrivateKey->Length(); |
|
97 aWriteStream.WriteInt32L(stringLen); |
|
98 TPtr8 keyPtr = iPrivateKey->Des(); |
|
99 keyPtr.SetLength(stringLen); |
|
100 aWriteStream.WriteL(keyPtr); |
|
101 |
|
102 stringLen = iPublicKey->Length(); |
|
103 aWriteStream.WriteInt32L(stringLen); |
|
104 keyPtr = iPublicKey->Des(); |
|
105 keyPtr.SetLength(stringLen); |
|
106 aWriteStream.WriteL(keyPtr); |
|
107 } |
|
108 |
|
109 void CKeyDetails::InternalizeL(RReadStream& aReadStream) |
|
110 { |
|
111 iHandle = aReadStream.ReadInt32L(); |
|
112 |
|
113 TInt stringLen = aReadStream.ReadInt32L(); |
|
114 iLabel = HBufC::NewMaxL(stringLen); |
|
115 TPtr labelPtr((TUint16*)iLabel->Ptr(), stringLen, stringLen); |
|
116 labelPtr.FillZ(stringLen); |
|
117 aReadStream.ReadL(labelPtr); |
|
118 |
|
119 stringLen = aReadStream.ReadInt32L(); |
|
120 iPrivateKey = HBufC8::NewMaxL(stringLen); |
|
121 TPtr8 privateKeyPtr((TUint8*)iPrivateKey->Ptr(), stringLen, stringLen); |
|
122 privateKeyPtr.FillZ(stringLen); |
|
123 aReadStream.ReadL(privateKeyPtr); |
|
124 |
|
125 stringLen = aReadStream.ReadInt32L(); |
|
126 iPublicKey = HBufC8::NewMaxL(stringLen); |
|
127 TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen); |
|
128 publicKeyPtr.FillZ(stringLen); |
|
129 aReadStream.ReadL(publicKeyPtr); |
|
130 } |