|
1 /* |
|
2 * Copyright (c) 2005-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 * CTransientKeyInfo implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 #include <pbedata.h> |
|
24 #include "authserver_impl.h" |
|
25 |
|
26 using namespace AuthServer; |
|
27 |
|
28 CTransientKeyInfo* CTransientKeyInfo::NewL( |
|
29 TPluginId aPluginId) |
|
30 { |
|
31 CTransientKeyInfo* key = |
|
32 CTransientKeyInfo::NewLC(aPluginId); |
|
33 CleanupStack::Pop(key); |
|
34 return key; |
|
35 } |
|
36 |
|
37 CTransientKeyInfo* CTransientKeyInfo::NewLC( |
|
38 TPluginId aPluginId) |
|
39 { |
|
40 CTransientKeyInfo* key = new (ELeave) CTransientKeyInfo(); |
|
41 CleanupStack::PushL(key); |
|
42 key->ConstructL(aPluginId); |
|
43 return key; |
|
44 } |
|
45 |
|
46 void CTransientKeyInfo::ConstructL(TPluginId aPluginId) |
|
47 { |
|
48 iPluginId = aPluginId; |
|
49 } |
|
50 |
|
51 CTransientKeyInfo* CTransientKeyInfo::NewL(RReadStream& aInputStream) |
|
52 { |
|
53 CTransientKeyInfo* key = |
|
54 CTransientKeyInfo::NewLC(aInputStream); |
|
55 CleanupStack::Pop(key); |
|
56 return key; |
|
57 } |
|
58 |
|
59 CTransientKeyInfo* CTransientKeyInfo::NewLC(RReadStream& aInputStream) |
|
60 { |
|
61 CTransientKeyInfo* key = new (ELeave) CTransientKeyInfo(); |
|
62 CleanupStack::PushL(key); |
|
63 key->InternalizeL(aInputStream); |
|
64 return key; |
|
65 } |
|
66 |
|
67 |
|
68 CTransientKeyInfo::~CTransientKeyInfo() |
|
69 { |
|
70 delete iEncryptedKey; |
|
71 delete iEncryptionData; |
|
72 } |
|
73 |
|
74 CTransientKey* |
|
75 CTransientKeyInfo::CreateTransientKeyL(const TDesC8& aPluginData) const |
|
76 { |
|
77 CPBEncryptElement* encrypt = 0; |
|
78 if (!iEncryptionData) |
|
79 { |
|
80 // Plugin data used as password |
|
81 encrypt = CPBEncryptElement::NewL(aPluginData); |
|
82 CleanupStack::PushL(encrypt); |
|
83 iEncryptionData = CPBEncryptionData::NewL(encrypt->EncryptionData()); |
|
84 } |
|
85 else |
|
86 { |
|
87 // Plugin data used as password |
|
88 encrypt = CPBEncryptElement::NewL(*iEncryptionData, aPluginData); |
|
89 CleanupStack::PushL(encrypt); |
|
90 } |
|
91 |
|
92 CTransientKey* key = CTransientKey::NewL(encrypt); // Ownership of encrypt transferred |
|
93 CleanupStack::Pop(encrypt); |
|
94 return key; |
|
95 } |
|
96 |
|
97 const CEncryptedProtectionKey& CTransientKeyInfo::EncryptedKey() const |
|
98 { |
|
99 return *iEncryptedKey; |
|
100 } |
|
101 |
|
102 void CTransientKeyInfo::SetEncryptedProtectionKeyL( |
|
103 CEncryptedProtectionKey* aEncryptedKey) |
|
104 { |
|
105 if (iEncryptedKey != 0) |
|
106 { |
|
107 User::Leave(KErrAlreadyExists); |
|
108 } |
|
109 |
|
110 iEncryptedKey = aEncryptedKey; |
|
111 } |
|
112 |
|
113 void CTransientKeyInfo::ExternalizeL(RWriteStream& aOutStream) const |
|
114 { |
|
115 ASSERT(iEncryptedKey != 0); |
|
116 |
|
117 aOutStream << iPluginId; |
|
118 aOutStream << *iEncryptedKey; |
|
119 aOutStream << *iEncryptionData; |
|
120 } |
|
121 |
|
122 void CTransientKeyInfo::InternalizeL(RReadStream& aInStream) |
|
123 { |
|
124 iPluginId = aInStream.ReadInt32L(); |
|
125 iEncryptedKey = CEncryptedProtectionKey::NewL(aInStream); |
|
126 iEncryptionData = CPBEncryptionData::NewL(aInStream); |
|
127 } |
|
128 |
|
129 TPluginId CTransientKeyInfo::PluginId() const |
|
130 { |
|
131 return iPluginId; |
|
132 } |