|
1 /* |
|
2 * Copyright (c) 2002-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 * CPKCS10Attributes class implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32def.h> |
|
22 #include <asn1enc.h> |
|
23 #include <pkcs10attr.h> |
|
24 |
|
25 |
|
26 // CPKCS10AttributeBase ///////////////////////////////////////////////////////// |
|
27 |
|
28 CPKCSAttributeBase::CPKCSAttributeBase() |
|
29 { |
|
30 } |
|
31 |
|
32 CPKCSAttributeBase::~CPKCSAttributeBase() |
|
33 { |
|
34 delete iRoot; |
|
35 } |
|
36 |
|
37 CASN1EncBase* CPKCSAttributeBase::GetEncodingLC() |
|
38 { |
|
39 CASN1EncBase* result = iRoot; |
|
40 iRoot = NULL; |
|
41 iValueSet = NULL; |
|
42 CleanupStack::PushL(result); |
|
43 return result; |
|
44 } |
|
45 |
|
46 // CPKCS10Attribute ///////////////////////////////////////////////////////// |
|
47 |
|
48 // This is being deprecated, will be removed |
|
49 EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID) |
|
50 { |
|
51 CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute; |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aAttrOID, NULL); |
|
54 return self; |
|
55 } |
|
56 |
|
57 EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewLC(const TDesC& aAttrOID, CASN1EncBase* aASN1) |
|
58 { |
|
59 if (aASN1 == NULL) |
|
60 { |
|
61 User::Leave(KErrArgument); |
|
62 } |
|
63 CPKCS10Attribute* self = new (ELeave) CPKCS10Attribute; |
|
64 CleanupStack::PushL(self); |
|
65 self->ConstructL(aAttrOID, aASN1); |
|
66 return self; |
|
67 } |
|
68 |
|
69 EXPORT_C CPKCS10Attribute* CPKCS10Attribute::NewL(const TDesC& aAttrOID, CASN1EncBase* aASN1) |
|
70 { |
|
71 CPKCS10Attribute* self = NewLC(aAttrOID, aASN1); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 EXPORT_C void CPKCS10Attribute::ResetL(const TDesC& aAttrOID, CASN1EncBase* aASN1) |
|
77 { |
|
78 if (aASN1 == NULL) |
|
79 { |
|
80 User::Leave(KErrArgument); |
|
81 } |
|
82 delete iRoot; |
|
83 iRoot = NULL; |
|
84 ConstructL(aAttrOID, aASN1); |
|
85 } |
|
86 |
|
87 EXPORT_C void CPKCS10Attribute::AddValueL(CASN1EncBase* aASN1) |
|
88 { |
|
89 if (aASN1 == NULL) |
|
90 { |
|
91 User::Leave(KErrArgument); |
|
92 } |
|
93 iValueSet->AddChildL(aASN1); |
|
94 } |
|
95 |
|
96 CPKCS10Attribute::CPKCS10Attribute() |
|
97 { |
|
98 } |
|
99 |
|
100 CPKCS10Attribute::~CPKCS10Attribute() |
|
101 { |
|
102 } |
|
103 |
|
104 void CPKCS10Attribute::ConstructL(const TDesC& aAttrOID, CASN1EncBase* aASN1) |
|
105 { |
|
106 iRoot = CASN1EncSequence::NewL(); |
|
107 CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(aAttrOID); |
|
108 iRoot->AddAndPopChildL(oid); |
|
109 iValueSet = CASN1EncSet::NewLC(); |
|
110 iRoot->AddAndPopChildL(iValueSet); // Takes ownership |
|
111 |
|
112 // For now just to allow for deprecated NewLC() which allows for NULL aASN1 |
|
113 // Replace with call to AddValueL() once the quirky NewLC() is removed |
|
114 if (aASN1) |
|
115 { |
|
116 iValueSet->AddChildL(aASN1); |
|
117 } |
|
118 } |
|
119 |
|
120 // Deprecated |
|
121 CASN1EncBase* CPKCS10Attribute::TakeEncodingC() |
|
122 { |
|
123 return CPKCSAttributeBase::GetEncodingLC(); |
|
124 } |
|
125 |
|
126 // Deprecated |
|
127 CASN1EncBase* CPKCS10Attribute::TakeEncodingLC() |
|
128 { |
|
129 return CPKCSAttributeBase::GetEncodingLC(); |
|
130 } |
|
131 |
|
132 CASN1EncBase* CPKCS10Attribute::GetEncodingLC() |
|
133 { |
|
134 return CPKCSAttributeBase::GetEncodingLC(); |
|
135 } |
|
136 |
|
137 |
|
138 // CPKCS10Attributes /////////////////////////////////////////////////////////// |
|
139 |
|
140 CPKCS10Attributes::CPKCS10Attributes() |
|
141 { |
|
142 } |
|
143 |
|
144 EXPORT_C CPKCS10Attributes::~CPKCS10Attributes() |
|
145 { |
|
146 delete iRoot; |
|
147 } |
|
148 |
|
149 EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewLC() |
|
150 { |
|
151 CPKCS10Attributes* self = new (ELeave) CPKCS10Attributes(); |
|
152 CleanupStack::PushL(self); |
|
153 self->ConstructL(); |
|
154 return self; |
|
155 } |
|
156 |
|
157 EXPORT_C CPKCS10Attributes* CPKCS10Attributes::NewL() |
|
158 { |
|
159 CPKCS10Attributes* self = NewLC(); |
|
160 CleanupStack::Pop(self); |
|
161 return self; |
|
162 } |
|
163 |
|
164 void CPKCS10Attributes::ConstructL() |
|
165 { |
|
166 // Create top level ASN1 sequence |
|
167 iRoot = CASN1EncSequence::NewL(); |
|
168 iRoot->SetTag(0); |
|
169 } |
|
170 |
|
171 // To be deprecated |
|
172 EXPORT_C void CPKCS10Attributes::AddAttributeL(CPKCS10Attribute* aAttr) |
|
173 { |
|
174 ASSERT(iRoot != NULL); |
|
175 ASSERT(aAttr != NULL); |
|
176 iRoot->AddAndPopChildL(aAttr->TakeEncodingLC()); |
|
177 delete aAttr; |
|
178 } |
|
179 |
|
180 EXPORT_C void CPKCS10Attributes::AddPKCSAttributeL(CPKCSAttributeBase* aAttr) |
|
181 { |
|
182 ASSERT(iRoot != NULL); |
|
183 if (aAttr == NULL) |
|
184 { |
|
185 User::Leave(KErrArgument); |
|
186 } |
|
187 iRoot->AddAndPopChildL(aAttr->GetEncodingLC()); |
|
188 delete aAttr; |
|
189 } |
|
190 |
|
191 CASN1EncBase* CPKCS10Attributes::TakeEncodingLC() |
|
192 { |
|
193 CASN1EncBase* result = iRoot; |
|
194 iRoot = NULL; |
|
195 CleanupStack::PushL(result); |
|
196 return result; |
|
197 } |