|
1 /* |
|
2 * Copyright (c) 2006-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 #include <cmssigneridentifier.h> |
|
20 #include <asn1dec.h> |
|
21 #include <asn1enc.h> |
|
22 |
|
23 // |
|
24 // Implementation of CCmsSignerIdentifier |
|
25 // |
|
26 |
|
27 CCmsSignerIdentifier* CCmsSignerIdentifier::NewL(CPKCS7IssuerAndSerialNumber* aIssuerAndSerialNumber) |
|
28 { |
|
29 CCmsSignerIdentifier* self = NewLC(aIssuerAndSerialNumber); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CCmsSignerIdentifier* CCmsSignerIdentifier::NewLC(CPKCS7IssuerAndSerialNumber* aIssuerAndSerialNumber) |
|
35 { |
|
36 if (!aIssuerAndSerialNumber) |
|
37 { |
|
38 User::Leave(KErrArgument); |
|
39 } |
|
40 CCmsSignerIdentifier* self = new (ELeave) CCmsSignerIdentifier(aIssuerAndSerialNumber); |
|
41 CleanupStack::PushL(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CCmsSignerIdentifier* CCmsSignerIdentifier::NewL(HBufC8* aSubjectKeyIdExt) |
|
46 { |
|
47 CCmsSignerIdentifier* self = NewLC(aSubjectKeyIdExt); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CCmsSignerIdentifier* CCmsSignerIdentifier::NewLC(HBufC8* aSubjectKeyIdExt) |
|
53 { |
|
54 if (!aSubjectKeyIdExt) |
|
55 { |
|
56 User::Leave(KErrArgument); |
|
57 } |
|
58 CCmsSignerIdentifier* self = new (ELeave) CCmsSignerIdentifier(aSubjectKeyIdExt); |
|
59 CleanupStack::PushL(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 CCmsSignerIdentifier* CCmsSignerIdentifier::NewL(const TDesC8& aRawData) |
|
64 { |
|
65 CCmsSignerIdentifier* self = NewLC(aRawData); |
|
66 CleanupStack::Pop(self); |
|
67 return self; |
|
68 } |
|
69 |
|
70 CCmsSignerIdentifier* CCmsSignerIdentifier::NewLC(const TDesC8& aRawData) |
|
71 { |
|
72 CCmsSignerIdentifier* self = new (ELeave) CCmsSignerIdentifier(); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(aRawData); |
|
75 return self; |
|
76 } |
|
77 |
|
78 CCmsSignerIdentifier::CCmsSignerIdentifier(CPKCS7IssuerAndSerialNumber* aIssuerAndSerialNumber) : iSignerIdentifierType(EIssuerAndSerialNumber) |
|
79 { |
|
80 iIssuerAndSerialNumber=aIssuerAndSerialNumber; |
|
81 } |
|
82 |
|
83 CCmsSignerIdentifier::CCmsSignerIdentifier(HBufC8* aSubjectKeyIdExt) : iSignerIdentifierType(ESubjectKeyIdentifier) |
|
84 { |
|
85 iSubjectKeyIdExt=aSubjectKeyIdExt; |
|
86 } |
|
87 |
|
88 EXPORT_C CCmsSignerIdentifier::~CCmsSignerIdentifier() |
|
89 { |
|
90 delete iIssuerAndSerialNumber; |
|
91 delete iSubjectKeyIdExt; |
|
92 } |
|
93 |
|
94 CASN1EncBase* CCmsSignerIdentifier::EncodeASN1DERLC() const |
|
95 { |
|
96 switch (iSignerIdentifierType) |
|
97 { |
|
98 case EIssuerAndSerialNumber: |
|
99 { |
|
100 return iIssuerAndSerialNumber->EncodeASN1DERLC(); |
|
101 } |
|
102 |
|
103 case ESubjectKeyIdentifier: |
|
104 { |
|
105 CASN1EncBase* subKey = CASN1EncOctetString::NewLC(*iSubjectKeyIdExt); |
|
106 subKey->SetTag(0); |
|
107 return subKey; |
|
108 } |
|
109 |
|
110 default: |
|
111 User::Leave(KErrNotSupported); |
|
112 } |
|
113 |
|
114 //Should not arrive here |
|
115 return NULL; |
|
116 } |
|
117 |
|
118 EXPORT_C const CPKCS7IssuerAndSerialNumber* CCmsSignerIdentifier::IssuerAndSerialNumber() const |
|
119 { |
|
120 return iIssuerAndSerialNumber; |
|
121 } |
|
122 |
|
123 EXPORT_C TInt CCmsSignerIdentifier::SignerIdentifierType() const |
|
124 { |
|
125 return iSignerIdentifierType; |
|
126 } |
|
127 |
|
128 CCmsSignerIdentifier::CCmsSignerIdentifier() |
|
129 { |
|
130 } |
|
131 |
|
132 void CCmsSignerIdentifier::ConstructL(const TDesC8& aRawData) |
|
133 { |
|
134 TASN1DecGeneric decGen(aRawData); |
|
135 decGen.InitL(); |
|
136 |
|
137 if(decGen.Tag() == EASN1Sequence && decGen.Class()==EUniversal) |
|
138 { |
|
139 iSignerIdentifierType=EIssuerAndSerialNumber; |
|
140 iIssuerAndSerialNumber=CPKCS7IssuerAndSerialNumber::NewL(aRawData); |
|
141 } |
|
142 else if(decGen.Tag() == 0 && decGen.Class()==EContextSpecific) |
|
143 { |
|
144 iSignerIdentifierType=ESubjectKeyIdentifier; |
|
145 iSubjectKeyIdExt=decGen.GetContentDER().AllocL(); |
|
146 } |
|
147 else |
|
148 { |
|
149 User::Leave(KErrArgument); |
|
150 } |
|
151 } |
|
152 |
|
153 EXPORT_C const TDesC8& CCmsSignerIdentifier::SubjectKeyIdentifier() const |
|
154 { |
|
155 return *iSubjectKeyIdExt; |
|
156 } |