|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCMSX509SubjectPublicKeyInfo.h" |
|
21 #include "CCMSX509AlgorithmIdentifier.h" |
|
22 #include <asn1dec.h> |
|
23 #include <asn1enc.h> |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KNumberOfSubModules = 2; |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CCMSX509SubjectPublicKeyInfo::CCMSX509SubjectPublicKeyInfo |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C CCMSX509SubjectPublicKeyInfo::CCMSX509SubjectPublicKeyInfo() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CCMSX509SubjectPublicKeyInfo::ConstructL |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C void CCMSX509SubjectPublicKeyInfo::ConstructL( |
|
46 const CCMSX509AlgorithmIdentifier& aAlgorithm, |
|
47 const TDesC8& aSubjectPublicKey ) |
|
48 { |
|
49 SetAlgorithmL( aAlgorithm ); |
|
50 SetSubjectPublicKeyL( aSubjectPublicKey ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCMSX509SubjectPublicKeyInfo::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C void CCMSX509SubjectPublicKeyInfo::ConstructL( |
|
59 const CSubjectPublicKeyInfo& aSubjectPublicKeyInfo ) |
|
60 { |
|
61 TAlgorithmId algIdType = aSubjectPublicKeyInfo.AlgorithmId(); |
|
62 CAlgorithmIdentifier* algId = CAlgorithmIdentifier::NewLC( |
|
63 algIdType, |
|
64 aSubjectPublicKeyInfo.EncodedParams() ); |
|
65 CCMSX509AlgorithmIdentifier* cmsAlgId = |
|
66 CCMSX509AlgorithmIdentifier::NewL( *algId ); |
|
67 CleanupStack::PushL( cmsAlgId ); |
|
68 SetAlgorithmL( *cmsAlgId ); |
|
69 CleanupStack::PopAndDestroy( 2 ); // cmsAlgId, algId |
|
70 SetSubjectPublicKeyL( aSubjectPublicKeyInfo.KeyData() ); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CCMSX509SubjectPublicKeyInfo::ConstructL |
|
75 // Symbian 2nd phase constructor can leave. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C void CCMSX509SubjectPublicKeyInfo::ConstructL( ) |
|
79 { |
|
80 // creating empty/default values |
|
81 iAlgorithm = CCMSX509AlgorithmIdentifier::NewL(); |
|
82 iSubjectPublicKey = KNullDesC8().AllocL(); |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCMSX509SubjectPublicKeyInfo::NewL |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CCMSX509SubjectPublicKeyInfo* |
|
92 CCMSX509SubjectPublicKeyInfo::NewL() |
|
93 { |
|
94 // creating with empty values |
|
95 CCMSX509SubjectPublicKeyInfo* self = |
|
96 new( ELeave ) CCMSX509SubjectPublicKeyInfo(); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( ); |
|
99 CleanupStack::Pop( self ); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CCMSX509SubjectPublicKeyInfo::NewL |
|
105 // Two-phased constructor. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C CCMSX509SubjectPublicKeyInfo* |
|
109 CCMSX509SubjectPublicKeyInfo::NewL( |
|
110 const CCMSX509AlgorithmIdentifier& aAlgorithm, |
|
111 const TDesC8& aSubjectPublicKey ) |
|
112 { |
|
113 CCMSX509SubjectPublicKeyInfo* self = |
|
114 new( ELeave ) CCMSX509SubjectPublicKeyInfo(); |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL( aAlgorithm, aSubjectPublicKey ); |
|
117 CleanupStack::Pop(); |
|
118 |
|
119 return self; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CCMSX509SubjectPublicKeyInfo::NewL |
|
124 // Two-phased constructor. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C CCMSX509SubjectPublicKeyInfo* |
|
128 CCMSX509SubjectPublicKeyInfo::NewL( |
|
129 const CSubjectPublicKeyInfo& aSubjectPublicKeyInfo ) |
|
130 { |
|
131 CCMSX509SubjectPublicKeyInfo* self = |
|
132 new( ELeave ) CCMSX509SubjectPublicKeyInfo(); |
|
133 CleanupStack::PushL( self ); |
|
134 self->ConstructL( aSubjectPublicKeyInfo ); |
|
135 CleanupStack::Pop(); |
|
136 |
|
137 return self; |
|
138 } |
|
139 |
|
140 // Destructor |
|
141 CCMSX509SubjectPublicKeyInfo::~CCMSX509SubjectPublicKeyInfo() |
|
142 { |
|
143 delete iAlgorithm; |
|
144 delete iSubjectPublicKey; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CCMSX509SubjectPublicKeyInfo::DecodeL |
|
149 // Decrypts raw data to this instance |
|
150 // ----------------------------------------------------------------------------- |
|
151 void CCMSX509SubjectPublicKeyInfo::DecodeL( const TDesC8& aRawData ) |
|
152 { |
|
153 CArrayPtr< TASN1DecGeneric >* itemList = DecodeSequenceLC( |
|
154 aRawData, KNumberOfSubModules, KNumberOfSubModules ); |
|
155 |
|
156 TInt sequenceCounter = 0; |
|
157 |
|
158 // decode algorithm |
|
159 CCMSX509AlgorithmIdentifier* algId = CCMSX509AlgorithmIdentifier::NewL( ); |
|
160 CleanupStack::PushL( algId ); |
|
161 algId->DecodeL( itemList->At( sequenceCounter++ )->Encoding() ); |
|
162 |
|
163 // decode subjectPublicKey |
|
164 TASN1DecBitString bsDecoder; |
|
165 HBufC8* subjectPublicKey = |
|
166 bsDecoder.ExtractOctetStringL( *( itemList->At( sequenceCounter ) ) ); |
|
167 |
|
168 // all done, change state |
|
169 delete iAlgorithm; |
|
170 iAlgorithm = algId; |
|
171 delete iSubjectPublicKey; |
|
172 iSubjectPublicKey = subjectPublicKey; |
|
173 CleanupStack::Pop( algId ); |
|
174 CleanupStack::PopAndDestroy( itemList ); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CCMSX509SubjectPublicKeyInfo::EncoderLC |
|
179 // Returns ASN1 encoder for this instance |
|
180 // ----------------------------------------------------------------------------- |
|
181 |
|
182 CASN1EncBase* CCMSX509SubjectPublicKeyInfo::EncoderLC() const |
|
183 { |
|
184 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
185 |
|
186 // encode algorithm AlgorithmIdentifier |
|
187 CASN1EncBase* algId = iAlgorithm->EncoderLC(); |
|
188 root->AddAndPopChildL( algId ); |
|
189 |
|
190 // encode subjectPublicKey BIT STRING |
|
191 CASN1EncBitString* spKey = CASN1EncBitString::NewLC( *iSubjectPublicKey ); |
|
192 root->AddAndPopChildL( spKey ); |
|
193 |
|
194 return root; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CCMSX509SubjectPublicKeyInfo::Algorithm() |
|
199 // Getter for algorithm |
|
200 // ----------------------------------------------------------------------------- |
|
201 EXPORT_C const CCMSX509AlgorithmIdentifier& |
|
202 CCMSX509SubjectPublicKeyInfo::Algorithm() const |
|
203 { |
|
204 return *iAlgorithm; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CCMSX509SubjectPublicKeyInfo::SubjectPublicKey() |
|
209 // Getter for subjectPublicKey |
|
210 // ----------------------------------------------------------------------------- |
|
211 EXPORT_C const TDesC8& |
|
212 CCMSX509SubjectPublicKeyInfo::SubjectPublicKey() const |
|
213 { |
|
214 return *iSubjectPublicKey; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CCMSX509SubjectPublicKeyInfo::SetAlgorithmL() |
|
219 // Setter for algorithm |
|
220 // ----------------------------------------------------------------------------- |
|
221 EXPORT_C void CCMSX509SubjectPublicKeyInfo::SetAlgorithmL( |
|
222 const CCMSX509AlgorithmIdentifier& aAlgorithm ) |
|
223 { |
|
224 CCMSX509AlgorithmIdentifier* algorithm = |
|
225 CCMSX509AlgorithmIdentifier::NewL( aAlgorithm.AlgorithmIdentifier() ); |
|
226 CleanupStack::PushL( algorithm ); |
|
227 const CAlgorithmIdentifier* digestIdentifier = |
|
228 aAlgorithm.DigestAlgorithm(); |
|
229 if( digestIdentifier ) |
|
230 { |
|
231 algorithm->SetDigestAlgorithmL( digestIdentifier ); |
|
232 } |
|
233 CleanupStack::Pop( algorithm ); |
|
234 delete iAlgorithm; |
|
235 iAlgorithm = algorithm; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CCMSX509SubjectPublicKeyInfo::SetSubjectPublicKeyL() |
|
240 // Setter for subjectPublicKey |
|
241 // ----------------------------------------------------------------------------- |
|
242 EXPORT_C void CCMSX509SubjectPublicKeyInfo::SetSubjectPublicKeyL( |
|
243 const TDesC8& aSubjectPublicKey ) |
|
244 { |
|
245 HBufC8* key = aSubjectPublicKey.AllocL(); |
|
246 delete iSubjectPublicKey; |
|
247 iSubjectPublicKey = key; |
|
248 } |
|
249 |
|
250 // End of File |