|
1 /* |
|
2 * Copyright (c) 2007-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 * CPKCS9ChallengePasswordAttr and CPKCS9ExtensionRequestAttr class implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32def.h> |
|
22 #include <asn1enc.h> |
|
23 #include <pkcs9attr.h> |
|
24 |
|
25 // CPKCS9ChallengePasswordAttr //////////////////////////////////////////////////////////// |
|
26 |
|
27 EXPORT_C CPKCS9ChallengePasswordAttr* CPKCS9ChallengePasswordAttr::NewLC(const TDesC8& aPassword) |
|
28 { |
|
29 CPKCS9ChallengePasswordAttr* self = new (ELeave) CPKCS9ChallengePasswordAttr; |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(aPassword); |
|
32 return self; |
|
33 } |
|
34 |
|
35 EXPORT_C CPKCS9ChallengePasswordAttr* CPKCS9ChallengePasswordAttr::NewL(const TDesC8& aPassword) |
|
36 { |
|
37 CPKCS9ChallengePasswordAttr* self = NewLC(aPassword); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 EXPORT_C void CPKCS9ChallengePasswordAttr::ResetL(const TDesC8& aPassword) |
|
43 { |
|
44 delete iRoot; |
|
45 iRoot = NULL; |
|
46 ConstructL(aPassword); |
|
47 } |
|
48 |
|
49 CPKCS9ChallengePasswordAttr::CPKCS9ChallengePasswordAttr() |
|
50 { |
|
51 } |
|
52 |
|
53 CPKCS9ChallengePasswordAttr::~CPKCS9ChallengePasswordAttr() |
|
54 { |
|
55 } |
|
56 |
|
57 CASN1EncBase* CPKCS9ChallengePasswordAttr::GetEncodingLC() |
|
58 { |
|
59 return CPKCSAttributeBase::GetEncodingLC(); |
|
60 } |
|
61 |
|
62 void CPKCS9ChallengePasswordAttr::ConstructL(const TDesC8& aPassword) |
|
63 { |
|
64 // Size of password string should be between bounds |
|
65 if ((aPassword.Length() < KPkcs9StringLB) || (aPassword.Length() > KPkcs9StringUB)) |
|
66 { |
|
67 User::Leave(KErrArgument); |
|
68 } |
|
69 |
|
70 iRoot = CASN1EncSequence::NewL(); |
|
71 CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(KPkcs9ChallengePasswordAttrOID); |
|
72 iRoot->AddAndPopChildL(oid); |
|
73 iValueSet = CASN1EncSet::NewLC(); |
|
74 iRoot->AddAndPopChildL(iValueSet); // Takes ownership |
|
75 CASN1EncPrintableString* value = CASN1EncPrintableString::NewLC(aPassword); |
|
76 iValueSet->AddAndPopChildL(value); |
|
77 } |
|
78 |
|
79 // CPKCS9ExtensionRequestAttr //////////////////////////////////////////////////////////// |
|
80 |
|
81 EXPORT_C CPKCS9ExtensionRequestAttr* CPKCS9ExtensionRequestAttr::NewLC(const CX509CertExtension& aExtension) |
|
82 { |
|
83 CPKCS9ExtensionRequestAttr* self = new (ELeave) CPKCS9ExtensionRequestAttr; |
|
84 CleanupStack::PushL(self); |
|
85 self->ConstructL(aExtension); |
|
86 return self; |
|
87 } |
|
88 |
|
89 EXPORT_C CPKCS9ExtensionRequestAttr* CPKCS9ExtensionRequestAttr::NewL(const CX509CertExtension& aExtension) |
|
90 { |
|
91 CPKCS9ExtensionRequestAttr* self = NewLC(aExtension); |
|
92 CleanupStack::Pop(self); |
|
93 return self; |
|
94 } |
|
95 |
|
96 EXPORT_C void CPKCS9ExtensionRequestAttr::AddExtensionL(const CX509CertExtension& aExtension) |
|
97 { |
|
98 CASN1EncSequence *extension = aExtension.EncodeASN1DERLC(); |
|
99 iExtSeq->AddAndPopChildL(extension); |
|
100 } |
|
101 |
|
102 EXPORT_C void CPKCS9ExtensionRequestAttr::ResetL(const CX509CertExtension& aExtension) |
|
103 { |
|
104 delete iRoot; |
|
105 iRoot = NULL; |
|
106 ConstructL(aExtension); |
|
107 } |
|
108 |
|
109 CPKCS9ExtensionRequestAttr::CPKCS9ExtensionRequestAttr() |
|
110 { |
|
111 } |
|
112 |
|
113 CPKCS9ExtensionRequestAttr::~CPKCS9ExtensionRequestAttr() |
|
114 { |
|
115 } |
|
116 |
|
117 CASN1EncBase* CPKCS9ExtensionRequestAttr::GetEncodingLC() |
|
118 { |
|
119 return CPKCSAttributeBase::GetEncodingLC(); |
|
120 } |
|
121 |
|
122 void CPKCS9ExtensionRequestAttr::ConstructL(const CX509CertExtension& aExtension) |
|
123 { |
|
124 iRoot = CASN1EncSequence::NewL(); |
|
125 CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC(KPkcs9ExtensionRequestAttrOID); |
|
126 iRoot->AddAndPopChildL(oid); |
|
127 iValueSet = CASN1EncSet::NewLC(); |
|
128 iRoot->AddAndPopChildL(iValueSet); // Takes ownership |
|
129 iExtSeq = CASN1EncSequence::NewLC(); |
|
130 iValueSet->AddAndPopChildL(iExtSeq); |
|
131 CASN1EncSequence *extension = aExtension.EncodeASN1DERLC(); |
|
132 iExtSeq->AddAndPopChildL(extension); |
|
133 } |