|
1 /* |
|
2 * Copyright (c) 2002 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 "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: Implementation of CDmAdCertLuidMappingElem. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //#include <utf.h> |
|
20 |
|
21 #include "dmadcertluidmappingelem.h" |
|
22 #include "utlcrypto.h" |
|
23 #include "base64.h" |
|
24 #include "vpnlogger.h" |
|
25 |
|
26 CDmAdCertLuidMappingElem* CDmAdCertLuidMappingElem::NewL(const TDesC8& aIssuerName, const TDesC8& aSerialNumber) |
|
27 { |
|
28 TRACE("CDmAdCertLuidMappingElem::NewL"); |
|
29 |
|
30 CDmAdCertLuidMappingElem* self = NewLC(aIssuerName, aSerialNumber); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CDmAdCertLuidMappingElem* CDmAdCertLuidMappingElem::NewLC(const TDesC8& aIssuerName, const TDesC8& aSerialNumber) |
|
36 { |
|
37 CDmAdCertLuidMappingElem* self = new (ELeave) CDmAdCertLuidMappingElem(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(aIssuerName, aSerialNumber); |
|
40 return self; |
|
41 } |
|
42 |
|
43 void CDmAdCertLuidMappingElem::ConstructL(const TDesC8& aIssuerName, const TDesC8& aSerialNumber) |
|
44 { |
|
45 TRACE("CDmAdCertLuidMappingElem::ConstructL"); |
|
46 |
|
47 iIssuerName = aIssuerName.AllocL(); |
|
48 iSerialNumber = aSerialNumber.AllocL(); |
|
49 iLuid = BuildLuidL(aIssuerName, aSerialNumber); |
|
50 } |
|
51 |
|
52 CDmAdCertLuidMappingElem::CDmAdCertLuidMappingElem() |
|
53 { |
|
54 } |
|
55 |
|
56 CDmAdCertLuidMappingElem::~CDmAdCertLuidMappingElem() |
|
57 { |
|
58 TRACE("CDmAdCertLuidMappingElem::~CDmAdCertLuidMappingElem"); |
|
59 |
|
60 delete iLuid; |
|
61 delete iIssuerName; |
|
62 delete iSerialNumber; |
|
63 } |
|
64 |
|
65 void CDmAdCertLuidMappingElem::CleanupOperationDeleteCArrayPtr(TAny* aPtr) |
|
66 { |
|
67 TRACE("CDmAdCertLuidMappingElem::CleanupOperationDeleteCArrayPtr"); |
|
68 |
|
69 if (!aPtr) |
|
70 { |
|
71 return; |
|
72 } |
|
73 CArrayPtr<CDmAdCertLuidMappingElem>* array = reinterpret_cast<CArrayPtr<CDmAdCertLuidMappingElem>*>(aPtr); |
|
74 array->ResetAndDestroy(); |
|
75 delete array; |
|
76 } |
|
77 |
|
78 TPtrC8 CDmAdCertLuidMappingElem::Luid() const |
|
79 { |
|
80 TRACE("CDmAdCertLuidMappingElem::Luid"); |
|
81 |
|
82 TPtrC8 ret(KNullDesC8); |
|
83 if (iLuid != 0) |
|
84 { |
|
85 ret.Set(*iLuid); |
|
86 } |
|
87 return ret; |
|
88 } |
|
89 |
|
90 TPtrC8 CDmAdCertLuidMappingElem::IssuerName() const |
|
91 { |
|
92 TRACE("CDmAdCertLuidMappingElem::IssuerName"); |
|
93 |
|
94 TPtrC8 ret(KNullDesC8); |
|
95 if (iIssuerName != 0) |
|
96 { |
|
97 ret.Set(*iIssuerName); |
|
98 } |
|
99 return ret; |
|
100 } |
|
101 |
|
102 TPtrC8 CDmAdCertLuidMappingElem::SerialNumber() const |
|
103 { |
|
104 TRACE("CDmAdCertLuidMappingElem::SerialNumber"); |
|
105 |
|
106 TPtrC8 ret(KNullDesC8); |
|
107 if (iSerialNumber != 0) |
|
108 { |
|
109 ret.Set(*iSerialNumber); |
|
110 } |
|
111 return ret; |
|
112 } |
|
113 |
|
114 HBufC8* CDmAdCertLuidMappingElem::BuildLuidL(const TDesC8& aIssuerName, const TDesC8& aSerialNumber) |
|
115 { |
|
116 TRACE("CDmAdCertLuidMappingElem::BuildLuidL"); |
|
117 |
|
118 CUtlMessageDigest* digester = TUtlCrypto::MakeMessageDigesterL(TUtlCrypto::EUtlMessageDigestSha1); |
|
119 CleanupStack::PushL(digester); |
|
120 |
|
121 HBufC8* hashBuf = HBufC8::NewLC(digester->HashSize()); |
|
122 TPtr8 hashBufDesc(hashBuf->Des()); |
|
123 |
|
124 digester->Update(aIssuerName); |
|
125 hashBufDesc.Copy(digester->Final(aSerialNumber)); |
|
126 |
|
127 TBase64Codec base64Codec; |
|
128 HBufC8* luidB64; |
|
129 if ((luidB64 = base64Codec.Base64EncodeLC(*hashBuf)) == NULL) |
|
130 { |
|
131 DEBUG_LOG(_L("No memory")); |
|
132 User::Leave(KErrNoMemory); |
|
133 } |
|
134 |
|
135 CleanupStack::Pop(luidB64); |
|
136 CleanupStack::PopAndDestroy(2); //hashBuf, digester |
|
137 return luidB64; |
|
138 } |