|
1 /* |
|
2 * Copyright (c) 2003-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 #include <pkcs7issuerserial.h> |
|
22 #include <x500dn.h> |
|
23 #include <asn1dec.h> |
|
24 #include <asn1enc.h> |
|
25 #include <bigint.h> |
|
26 #include "pkcs7asn1.h" |
|
27 |
|
28 // |
|
29 // Implementation of CPKCS7IssuerAndSerialNumber |
|
30 // |
|
31 CPKCS7IssuerAndSerialNumber* CPKCS7IssuerAndSerialNumber::NewL(CX500DistinguishedName* aIssuerName, const TDesC8& aSerialNumber) |
|
32 { |
|
33 CPKCS7IssuerAndSerialNumber* self = NewLC(aIssuerName, aSerialNumber); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CPKCS7IssuerAndSerialNumber* CPKCS7IssuerAndSerialNumber::NewLC(CX500DistinguishedName* aIssuerName, const TDesC8& aSerialNumber) |
|
39 { |
|
40 if (!aIssuerName) |
|
41 { |
|
42 User::Leave(KErrArgument); |
|
43 } |
|
44 |
|
45 CPKCS7IssuerAndSerialNumber* self = new (ELeave) CPKCS7IssuerAndSerialNumber(); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aIssuerName, aSerialNumber); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CPKCS7IssuerAndSerialNumber* CPKCS7IssuerAndSerialNumber::NewL(const TDesC8& aRawData) |
|
52 { |
|
53 CPKCS7IssuerAndSerialNumber* self = new (ELeave) CPKCS7IssuerAndSerialNumber(); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(aRawData); |
|
56 CleanupStack::Pop(self); |
|
57 return self; |
|
58 } |
|
59 |
|
60 EXPORT_C CPKCS7IssuerAndSerialNumber::~CPKCS7IssuerAndSerialNumber() |
|
61 { |
|
62 delete iIssuerName; |
|
63 delete iSerialNumber; |
|
64 } |
|
65 |
|
66 CPKCS7IssuerAndSerialNumber::CPKCS7IssuerAndSerialNumber(void) |
|
67 { |
|
68 } |
|
69 |
|
70 void CPKCS7IssuerAndSerialNumber::ConstructL(const TDesC8& aRawData) |
|
71 { |
|
72 CArrayPtr<TASN1DecGeneric>* itemsData = PKCS7ASN1::DecodeSequenceLC(aRawData, 2, 2); |
|
73 TASN1DecInteger decInt; |
|
74 iIssuerName = CX500DistinguishedName::NewL(itemsData->At(0)->Encoding()); |
|
75 RInteger sn = decInt.DecodeDERLongL(*itemsData->At(1)); |
|
76 CleanupClosePushL(sn); |
|
77 iSerialNumber = sn.BufferLC(); |
|
78 CleanupStack::Pop(iSerialNumber); |
|
79 CleanupStack::PopAndDestroy(2, itemsData); |
|
80 } |
|
81 |
|
82 void CPKCS7IssuerAndSerialNumber::ConstructL(CX500DistinguishedName* aIssuerName, const TDesC8& aSerialNumber) |
|
83 { |
|
84 iSerialNumber=aSerialNumber.AllocL(); |
|
85 iIssuerName=aIssuerName; |
|
86 } |
|
87 |
|
88 EXPORT_C const CX500DistinguishedName& CPKCS7IssuerAndSerialNumber::IssuerName() const |
|
89 { |
|
90 return *iIssuerName; |
|
91 } |
|
92 |
|
93 EXPORT_C const TDesC8& CPKCS7IssuerAndSerialNumber::SerialNumber() const |
|
94 { |
|
95 return *iSerialNumber; |
|
96 } |
|
97 |
|
98 |
|
99 CASN1EncSequence* CPKCS7IssuerAndSerialNumber::EncodeASN1DERLC() const |
|
100 { |
|
101 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
102 CASN1EncSequence* issuerName=iIssuerName->EncodeASN1LC(); |
|
103 root->AddAndPopChildL(issuerName); |
|
104 RInteger snBInt=RInteger::NewL(iSerialNumber->Des()); |
|
105 CleanupClosePushL(snBInt); |
|
106 CASN1EncBigInt* sn=CASN1EncBigInt::NewLC(snBInt); |
|
107 root->AddAndPopChildL(sn); |
|
108 CleanupStack::PopAndDestroy(&snBInt); |
|
109 return root; |
|
110 } |