|
1 /* |
|
2 * Copyright (c) 2004 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 "CCMSX509Signed.h" |
|
21 #include "CCMSX509AlgorithmIdentifier.h" |
|
22 // CONSTANTS |
|
23 const TInt KNumberOfSubModules = 3; |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CCMSX509Signed::CCMSX509Signed |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CCMSX509Signed::CCMSX509Signed( ) |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CCMSX509Signed::BaseConstructL |
|
39 // Constructs the member variables. Makes copies. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 void CCMSX509Signed::BaseConstructL( |
|
43 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
44 const TDesC8& aEncrypted ) |
|
45 { |
|
46 SetAlgorithmIdentifierL( aAlgorithmIdentifier ); |
|
47 SetEncryptedL( aEncrypted ); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CCMSX509Signed::SignAndPopLC |
|
52 // Creates a signed encoder. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CASN1EncSequence* CCMSX509Signed::SignAndPopLC( |
|
56 CASN1EncBase* aToBeSigned ) const |
|
57 { |
|
58 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
59 |
|
60 // encode toBeSigned |
|
61 root->AddChildL( aToBeSigned ); |
|
62 |
|
63 CleanupStack::Pop( 2 ); // root, aToBeSigned |
|
64 CleanupStack::PushL( root ); |
|
65 |
|
66 // encode algorithmIdentifier AlgorithmIdentifier |
|
67 CASN1EncBase* algId = iAlgorithmIdentifier->EncoderLC( ); |
|
68 root->AddAndPopChildL( algId ); |
|
69 |
|
70 // encode encrypted ENCRYPTED-HASH{ToBeSigned} |
|
71 CASN1EncBitString* encrypted = CASN1EncBitString::NewLC( *iEncrypted ); |
|
72 root->AddAndPopChildL( encrypted ); |
|
73 |
|
74 return root; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CCMSX509Signed::DecodeSignatureL |
|
79 // Decodes algorithmIdentifier and encrypted parts from the raw data. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 TASN1DecGeneric CCMSX509Signed::DecodeSignatureL( |
|
83 const TDesC8& aRawData, |
|
84 CCMSX509AlgorithmIdentifier*& aAlgorithmIdentifier, |
|
85 HBufC8*& aEncrypted ) const |
|
86 { |
|
87 CArrayPtr< TASN1DecGeneric >* itemList = DecodeSequenceLC( |
|
88 aRawData, KNumberOfSubModules, KNumberOfSubModules ); |
|
89 |
|
90 TASN1DecGeneric retVal = |
|
91 DecodeSignatureArrayL( *itemList, aAlgorithmIdentifier, aEncrypted ); |
|
92 |
|
93 CleanupStack::PopAndDestroy( itemList ); |
|
94 |
|
95 return retVal; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CCMSX509Signed::DecodeSignatureArrayL |
|
100 // Decodes algorithmIdentifier and encrypted parts from the array. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TASN1DecGeneric CCMSX509Signed::DecodeSignatureArrayL( |
|
104 CArrayPtr< TASN1DecGeneric >& aItemArray, |
|
105 CCMSX509AlgorithmIdentifier*& aAlgorithmIdentifier, |
|
106 HBufC8*& aEncrypted ) const |
|
107 { |
|
108 TInt sequenceCounter = 0; |
|
109 |
|
110 // ToBeSigned will be returned |
|
111 TASN1DecGeneric retVal( *aItemArray.At( sequenceCounter++ ) ); |
|
112 |
|
113 // decode algorithmIdentifier |
|
114 CCMSX509AlgorithmIdentifier* algId = CCMSX509AlgorithmIdentifier::NewL( ); |
|
115 CleanupStack::PushL( algId ); |
|
116 algId->DecodeL( aItemArray.At( sequenceCounter++ )->Encoding() ); |
|
117 |
|
118 // decode encrypted |
|
119 TASN1DecBitString bsDecoder; |
|
120 HBufC8* encrypted = |
|
121 bsDecoder.ExtractOctetStringL( *( aItemArray.At( sequenceCounter ) ) ); |
|
122 |
|
123 // change parameter pointers |
|
124 aAlgorithmIdentifier = algId; |
|
125 aEncrypted = encrypted; |
|
126 CleanupStack::Pop( algId ); |
|
127 |
|
128 return retVal; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CCMSX509Signed::~CCMSX509Signed |
|
133 // Destructor |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 CCMSX509Signed::~CCMSX509Signed() |
|
137 { |
|
138 delete iAlgorithmIdentifier; |
|
139 delete iEncrypted; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CCMSX509Signed::AlgorithmIdentifier |
|
144 // algorithmIdentifier getter |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C const CCMSX509AlgorithmIdentifier& |
|
148 CCMSX509Signed::AlgorithmIdentifier() const |
|
149 { |
|
150 return *iAlgorithmIdentifier; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CCMSX509Signed::Encrypted |
|
155 // encrypted getter |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C const TDesC8& CCMSX509Signed::Encrypted() const |
|
159 { |
|
160 return *iEncrypted; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CCMSX509Signed::SetAlgorithmIdentifierL |
|
165 // AlgorithmIdentifier setter |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CCMSX509Signed::SetAlgorithmIdentifierL( |
|
169 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier ) |
|
170 { |
|
171 CCMSX509AlgorithmIdentifier* algorithmIdentifier = |
|
172 CCMSX509AlgorithmIdentifier::NewL( |
|
173 aAlgorithmIdentifier.AlgorithmIdentifier() ); |
|
174 CleanupStack::PushL( algorithmIdentifier ); |
|
175 const CAlgorithmIdentifier* digestAlgorithm = |
|
176 aAlgorithmIdentifier.DigestAlgorithm(); |
|
177 if( digestAlgorithm ) |
|
178 { |
|
179 algorithmIdentifier->SetDigestAlgorithmL( digestAlgorithm ); |
|
180 } |
|
181 CleanupStack::Pop( algorithmIdentifier ); |
|
182 delete iAlgorithmIdentifier; |
|
183 iAlgorithmIdentifier = algorithmIdentifier; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCMSX509Signed::SetEncryptedL |
|
188 // encrypted setter |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C void CCMSX509Signed::SetEncryptedL( |
|
192 const TDesC8& aEncrypted ) |
|
193 { |
|
194 HBufC8* encrypted = aEncrypted.AllocL(); |
|
195 delete iEncrypted; |
|
196 iEncrypted = encrypted; |
|
197 } |
|
198 |
|
199 // End of File |