|
1 /* |
|
2 * Copyright (c) 2006 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 "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: Class is used for configuring secure RTP. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <mmf/common/mmfcontrollerframework.h> |
|
22 #include <e32math.h> |
|
23 |
|
24 #include "mmccinterfacelogs.h" |
|
25 #include "mmcccryptocontextcontainer.h" |
|
26 #include "mmcccryptocontext.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CMccCryptoContextContainer::ConstructL |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 void CMccCryptoContextContainer::ConstructL( ) |
|
36 { |
|
37 __INTERFACE( "CMccCryptoContextContainer::ConstructL" ) |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CMccCryptoContextContainer::NewL() |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CMccCryptoContextContainer* CMccCryptoContextContainer::NewL( ) |
|
45 { |
|
46 CMccCryptoContextContainer* self = new(ELeave) CMccCryptoContextContainer(); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL( ); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMccCryptoContextContainer::~CMccCryptoContextContainer |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CMccCryptoContextContainer::~CMccCryptoContextContainer() |
|
58 { |
|
59 iContextArray.Close(); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CMccCryptoContextContainer::CreateContext |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 TInt CMccCryptoContextContainer::CreateContext( const TMccSrtpMasterKey& aMasterKey, |
|
67 const TMccSrtpMasterSalt& aSaltKey, |
|
68 TUint32& aContextId, |
|
69 const TMccSrtpCryptoParams& aCryptoParams ) |
|
70 { |
|
71 __INTERFACE( "CMccCryptoContextContainer::CreateContext" ) |
|
72 |
|
73 TUint32 contextId( GenerateContextId() ); |
|
74 |
|
75 TMccCryptoContext cryptoContext( contextId, |
|
76 aMasterKey, |
|
77 aSaltKey, |
|
78 aCryptoParams ); |
|
79 |
|
80 |
|
81 TInt error( cryptoContext.ValidateContext() ); |
|
82 |
|
83 if ( KErrNone == error ) |
|
84 { |
|
85 error = iContextArray.Append( cryptoContext ); |
|
86 aContextId = contextId; |
|
87 } |
|
88 |
|
89 return error; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CMccCryptoContextContainer::RemoveContext |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 TInt CMccCryptoContextContainer::RemoveContext( TUint32 aContextId ) |
|
97 { |
|
98 __INTERFACE( "CMccContextContainer::RemoveContext" ) |
|
99 |
|
100 TInt contextId = FindContext( aContextId ); |
|
101 |
|
102 if ( KErrNotFound != contextId ) |
|
103 { |
|
104 iContextArray.Remove( contextId ); |
|
105 return KErrNone; |
|
106 } |
|
107 |
|
108 return KErrNotFound; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CMccCryptoContextContainer::UpdateContextL |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 TInt CMccCryptoContextContainer::UpdateContext( TUint32 aContextId, |
|
116 TMccCryptoContext& aContext ) |
|
117 { |
|
118 __INTERFACE( "CMccContextContainer::UpdateContext" ) |
|
119 |
|
120 TInt contextId = FindContext( aContextId ); |
|
121 |
|
122 if ( KErrNotFound != contextId ) |
|
123 { |
|
124 iContextArray[ contextId ].UpdateContext( aContext ); |
|
125 |
|
126 return KErrNone; |
|
127 } |
|
128 return KErrNotFound; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CMccCryptoContextContainer::GetContext |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 TInt CMccCryptoContextContainer::GetContext( TUint32 aContextId, |
|
136 TMccCryptoContext* &aContext ) |
|
137 { |
|
138 __INTERFACE( "CMccContextContainer::GetContext" ) |
|
139 |
|
140 TInt contextId = FindContext( aContextId ); |
|
141 |
|
142 if ( KErrNotFound != contextId ) |
|
143 { |
|
144 aContext = &iContextArray[ contextId ]; |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 return KErrNotFound; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CMccCryptoContextContainer::GenerateContextId |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TUint32 CMccCryptoContextContainer::GenerateContextId() |
|
156 { |
|
157 __INTERFACE( "CMccContextContainer::GenerateContextId" ) |
|
158 TUint32 id( 0 ); |
|
159 |
|
160 do |
|
161 { |
|
162 id = static_cast<TUint32>( Math::Random() ); |
|
163 } while ( KErrNotFound != FindContext( id ) ); |
|
164 |
|
165 return id; |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CMccCryptoContextContainer::FindContext |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CMccCryptoContextContainer::FindContext( TUint32 aContextId ) |
|
173 { |
|
174 TInt count( iContextArray.Count() ); |
|
175 |
|
176 for ( TInt i = 0; i < count; i++ ) |
|
177 { |
|
178 if ( iContextArray[ i ].ContextId() == aContextId ) |
|
179 { |
|
180 return i; |
|
181 } |
|
182 } |
|
183 return KErrNotFound; |
|
184 } |
|
185 // End of File |