|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include <e32std.h> |
|
26 #include <e32def.h> |
|
27 #include <asn1enc.h> |
|
28 #include <asn1dec.h> |
|
29 |
|
30 EXPORT_C CASN1EncEncoding::~CASN1EncEncoding() |
|
31 { |
|
32 delete iContents; |
|
33 } |
|
34 |
|
35 // Set arbitrary initial values for tag type and class because they will be |
|
36 // inited in ConstructL(). |
|
37 EXPORT_C CASN1EncEncoding::CASN1EncEncoding() : |
|
38 CASN1EncBase(EASN1EOC, EUniversal) |
|
39 { |
|
40 } |
|
41 |
|
42 EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding) |
|
43 { |
|
44 CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding; |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(aEncoding); |
|
47 return self; |
|
48 } |
|
49 |
|
50 EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewL(const TDesC8& aEncoding) |
|
51 { |
|
52 CASN1EncEncoding* self = NewLC(aEncoding); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass) |
|
58 { |
|
59 CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding; |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(aEncoding, aType, aClass); |
|
62 return self; |
|
63 } |
|
64 |
|
65 void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding) |
|
66 { |
|
67 // Use decoder to get information about the outer wrapper of the passed |
|
68 // encoding. |
|
69 TASN1DecGeneric decoder(aEncoding); |
|
70 decoder.InitL(); |
|
71 iClass = decoder.Class(); |
|
72 iTag = decoder.Tag(); |
|
73 // Set this information so that the base class knows how to write |
|
74 // DER encoding. |
|
75 SetTag(iTag, iClass); |
|
76 // Copy just the contents of the passed encoding. |
|
77 iContents = decoder.GetContentDER().AllocL(); |
|
78 // Save this for base class writing functions. |
|
79 iContentsLengthDER = iContents->Length(); |
|
80 // This is base class' method which initializes length of length |
|
81 // encoding for proper DER writing. |
|
82 CalculateLengthLengthDER(); |
|
83 } |
|
84 |
|
85 void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass) |
|
86 { |
|
87 // Use decoder to get information about the outer wrapper of the passed |
|
88 // encoding. |
|
89 TASN1DecGeneric decoder(aEncoding); |
|
90 decoder.InitL(); |
|
91 iClass = aClass; |
|
92 iTag = aType; |
|
93 // Set this information so that the base class knows how to write |
|
94 // DER encoding. |
|
95 SetTag(aType, aClass); |
|
96 // Copy just the contents of the passed encoding. |
|
97 iContents = decoder.GetContentDER().AllocL(); |
|
98 // Save this for base class writing functions. |
|
99 iContentsLengthDER = iContents->Length(); |
|
100 // This is base class' method which initializes length of length |
|
101 // encoding for proper DER writing. |
|
102 CalculateLengthLengthDER(); |
|
103 } |
|
104 |
|
105 |
|
106 // This method is not called but is necessary because it overrides a |
|
107 // pure virtual function of the base class. The variable is properly |
|
108 // initialized in ConstructL(). |
|
109 void CASN1EncEncoding::CalculateContentsLengthDER() |
|
110 { |
|
111 iContentsLengthDER = iContents->Length(); |
|
112 } |
|
113 |
|
114 TBool CASN1EncEncoding::IsConstructed() const |
|
115 { |
|
116 return ETrue; |
|
117 } |
|
118 |
|
119 // When this method is called by the base class write helper, the tag |
|
120 // and length are already written. |
|
121 void CASN1EncEncoding::WriteContentsDERL(TDes8& aBuf) const |
|
122 { |
|
123 aBuf.Copy(*iContents); |
|
124 } |