|
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 "CCMSSequence.h" |
|
21 |
|
22 // ============================ MEMBER FUNCTIONS =============================== |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // CCMSSequence::CCMSSequence |
|
26 // C++ default constructor can NOT contain any code, that |
|
27 // might leave. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CCMSSequence::CCMSSequence() |
|
31 { |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CCMSSequence::DecodeSequenceLC |
|
36 // Decodes raw-data to ASN.1 modules, pushes items to cleanupstack |
|
37 // ----------------------------------------------------------------------------- |
|
38 |
|
39 EXPORT_C CArrayPtr<TASN1DecGeneric>* CCMSSequence::DecodeSequenceLC( const TDesC8& aRawData ) |
|
40 { |
|
41 CArrayPtr<TASN1DecGeneric>* items = NULL; |
|
42 |
|
43 // Check we've got a sequence |
|
44 TASN1DecGeneric decGen( aRawData ); |
|
45 decGen.InitL(); |
|
46 // Accept only sequences or sets |
|
47 if( ( decGen.Tag() != EASN1Sequence ) && |
|
48 ( decGen.Tag() != EASN1Set ) ) |
|
49 { |
|
50 User::Leave(KErrArgument); |
|
51 } |
|
52 else |
|
53 { |
|
54 // Decode the sequence |
|
55 TASN1DecSequence decSeq; |
|
56 items = decSeq.DecodeDERLC( decGen ); |
|
57 } |
|
58 return items; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCMSSequence::DecodeSequenceLC |
|
63 // Decodes raw-data to ASN.1 modules, pushes items to cleanupstack |
|
64 // Validates that there is right number of modules, leaves with KErrArgument if |
|
65 // not. |
|
66 // ----------------------------------------------------------------------------- |
|
67 |
|
68 EXPORT_C CArrayPtr<TASN1DecGeneric>* CCMSSequence::DecodeSequenceLC( const TDesC8& aRawData, |
|
69 const TInt aMinTerms, |
|
70 const TInt aMaxTerms) |
|
71 { |
|
72 CArrayPtr<TASN1DecGeneric>* items = DecodeSequenceLC(aRawData); |
|
73 TInt count = items->Count(); |
|
74 if( ( count < aMinTerms ) || |
|
75 ( count > aMaxTerms ) ) |
|
76 { |
|
77 // not in the range, leave |
|
78 User::Leave( KErrArgument ); |
|
79 } |
|
80 |
|
81 return items; |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CCMSSequence::EncodeL |
|
86 // Encrypts this instance to descriptor |
|
87 // ----------------------------------------------------------------------------- |
|
88 |
|
89 void CCMSSequence::EncodeL( HBufC8*& aResult ) const |
|
90 { |
|
91 CASN1EncBase* root = EncoderLC(); |
|
92 |
|
93 // encode the object in a DER encoding |
|
94 HBufC8* der = CreateDerEncodingL( root ); |
|
95 CleanupStack::PopAndDestroy( root ); |
|
96 |
|
97 aResult = der; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CCMSSequence::CreateDerEncodingLC() |
|
102 // Creates DER encoding |
|
103 // ----------------------------------------------------------------------------- |
|
104 EXPORT_C HBufC8* CCMSSequence::CreateDerEncodingL( CASN1EncBase* aEncoding ) |
|
105 { |
|
106 // encode the object in a DER encoding |
|
107 HBufC8* der = HBufC8::NewMaxLC( aEncoding->LengthDER() ); |
|
108 TPtr8 pder( der->Des() ); |
|
109 TUint pos = 0; |
|
110 aEncoding->WriteDERL( pder, pos ); |
|
111 CleanupStack::Pop( der ); |
|
112 return der; |
|
113 } |
|
114 // End of File |