Update contrib.
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "cctcertinfo.h"
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
23 /** Mask constants used for serializing iDeletable and iFormat attributes
25 const TUint KReadOnlyFlagMask = 128;
26 const TUint KFormatMask = 127;
28 /** The UID of a CertInfo MCTTokenObject. */
29 const TInt KCTObjectCertInfo = 0x101F50E6;
33 // MCertInfo ///////////////////////////////////////////////////////////////////
35 EXPORT_C MCertInfo::MCertInfo() :
40 EXPORT_C MCertInfo::MCertInfo(const TDesC& aLabel,
41 TCertificateFormat aFormat,
42 TCertificateOwnerType aCertificateOwnerType,
44 const TKeyIdentifier* aSubjectKeyId,
45 const TKeyIdentifier* aIssuerKeyId,
48 iLabel(aLabel), iCertificateId(aCertificateId),
49 iFormat(aFormat), iCertificateOwnerType(aCertificateOwnerType),
50 iSize(aSize), iDeletable(aDeletable)
54 iSubjectKeyId = *aSubjectKeyId;
58 iSubjectKeyId = KNullDesC8;
62 iIssuerKeyId = *aIssuerKeyId;
66 iIssuerKeyId = KNullDesC8;
70 EXPORT_C MCertInfo::MCertInfo(const MCertInfo& aOther) :
71 iLabel(aOther.iLabel),
72 iCertificateId(aOther.iCertificateId),
73 iFormat(aOther.iFormat),
74 iCertificateOwnerType(aOther.iCertificateOwnerType),
76 iSubjectKeyId(aOther.iSubjectKeyId),
77 iIssuerKeyId(aOther.iIssuerKeyId),
78 iDeletable(aOther.iDeletable)
82 EXPORT_C MCertInfo::~MCertInfo()
87 const TDesC8* MCertInfo::IssuerHash() const
92 EXPORT_C void MCertInfo::ConstructL(const TDesC8* aIssuerHash)
98 iIssuerHash = aIssuerHash->AllocL();
103 User::Leave(KErrArgument);
107 TBool MCertInfo::Valid() const
109 if (iLabel.Length() == 0)
114 if (iCertificateId < 0)
119 if (iFormat != EX509Certificate && iFormat != EWTLSCertificate &&
120 iFormat != EX968Certificate && iFormat != EX509CertificateUrl &&
121 iFormat != EWTLSCertificateUrl && iFormat != EX968CertificateUrl)
126 if (iCertificateOwnerType != ECACertificate &&
127 iCertificateOwnerType != EUserCertificate &&
128 iCertificateOwnerType != EPeerCertificate)
138 if (iIssuerHash && *iIssuerHash == KNullDesC8)
147 EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const
149 This method externalizes the MCertInfo object to the given stream.
150 The iDeletable boolean attribute is combined with the iFormat attribute
151 for certstore backward compatibility
153 EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const
155 // insert iDeletable flag as most significant digit of iFormat in order
156 // store the flag without changing the externalized record format
157 // The value is OPPOSITE for backward compatibility
158 TUint8 tmpValue = static_cast <TUint8>(iFormat | (iDeletable ? 0 : KReadOnlyFlagMask));
160 aStream.WriteUint8L(tmpValue);
161 aStream.WriteInt32L(iSize);
163 aStream.WriteInt32L(iCertificateId);
164 aStream.WriteUint8L(iCertificateOwnerType);
165 aStream << iSubjectKeyId;
166 aStream << iIssuerKeyId;
170 EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream)
172 This method internalizes a MCertInfo object from the given stream.
173 The iDeletable boolean and iFormat attributes are both extracted
174 from the stored iFormat value using for certstore backward compatibility
176 EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream)
178 // get first byte from stream containing iDeletable flag and iFormat value
179 TUint8 tmpValue = aStream.ReadUint8L();
181 // extract iDeletable flag from most significant digit of iFormat
182 // set iDeletable to the OPPOSITE of the 8th bit value
183 iDeletable = !(tmpValue & KReadOnlyFlagMask);
185 // extract iFormat = the value of the 7 least significant bits
186 iFormat = static_cast <TCertificateFormat>(tmpValue & KFormatMask);
188 iSize = aStream.ReadInt32L();
190 iCertificateId = aStream.ReadInt32L();
191 iCertificateOwnerType = static_cast<TCertificateOwnerType>(aStream.ReadUint8L());
192 aStream >> iSubjectKeyId;
193 aStream >> iIssuerKeyId;
197 User::Leave(KErrCorrupt);
201 // CCTCertInfo /////////////////////////////////////////////////////////////////
203 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(RReadStream& aStream, MCTToken& aToken)
205 CCTCertInfo* self = CCTCertInfo::NewLC(aStream, aToken);
206 CleanupStack::Pop(self);
210 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(RReadStream& aStream, MCTToken& aToken)
212 CCTCertInfo* self = new(ELeave) CCTCertInfo(aToken);
213 CleanupReleasePushL(*self);
214 self->ConstructL(aStream);
218 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel,
219 TCertificateFormat aFormat,
220 TCertificateOwnerType aCertificateOwnerType,
222 const TKeyIdentifier* aSubjectKeyId,
223 const TKeyIdentifier* aIssuerKeyId,
227 CCTCertInfo* self = CCTCertInfo::NewLC(aLabel,
228 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken,
229 aCertificateId, ETrue);
230 CleanupStack::Pop(self);
234 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel,
235 TCertificateFormat aFormat,
236 TCertificateOwnerType aCertificateOwnerType,
238 const TKeyIdentifier* aSubjectKeyId,
239 const TKeyIdentifier* aIssuerKeyId,
243 const TDesC8* aIssuerHash)
245 CCTCertInfo* self = CCTCertInfo::NewLC(aLabel,
246 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken,
247 aCertificateId, aIsDeletable, aIssuerHash);
248 CleanupStack::Pop(self);
252 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel,
253 TCertificateFormat aFormat,
254 TCertificateOwnerType aCertificateOwnerType,
256 const TKeyIdentifier* aSubjectKeyId,
257 const TKeyIdentifier* aIssuerKeyId,
261 return CCTCertInfo::NewLC(aLabel,
262 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId,
263 aToken, aCertificateId, ETrue);
266 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel,
267 TCertificateFormat aFormat,
268 TCertificateOwnerType aCertificateOwnerType,
270 const TKeyIdentifier* aSubjectKeyId,
271 const TKeyIdentifier* aIssuerKeyId,
275 const TDesC8* aIssuerHash)
277 CCTCertInfo* self = new(ELeave) CCTCertInfo(aLabel,
278 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId,
279 aIssuerKeyId, aToken, aCertificateId, aIsDeletable);
280 CleanupReleasePushL(*self);
281 self->ConstructL(aIssuerHash);
285 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const CCTCertInfo& aCertInfo)
287 CCTCertInfo* self = CCTCertInfo::NewLC(aCertInfo);
288 CleanupStack::Pop(self);
292 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const CCTCertInfo& aCertInfo)
294 CCTCertInfo* self = new(ELeave) CCTCertInfo(aCertInfo);
295 CleanupReleasePushL(*self);
296 self->ConstructL(aCertInfo.IssuerHash());
300 CCTCertInfo::CCTCertInfo(MCTToken& aToken)
301 : MCTTokenObject(aToken), iToken(aToken)
305 CCTCertInfo::CCTCertInfo(const TDesC& aLabel,
306 TCertificateFormat aFormat,
307 TCertificateOwnerType aCertificateOwnerType,
309 const TKeyIdentifier* aSubjectKeyId,
310 const TKeyIdentifier* aIssuerKeyId,
314 : MCTTokenObject(aToken),
315 MCertInfo(aLabel, aFormat, aCertificateOwnerType, aSize, aSubjectKeyId,
316 aIssuerKeyId, aCertificateId, aIsDeletable),
321 CCTCertInfo::CCTCertInfo(const CCTCertInfo& aOther)
322 : MCTTokenObject(aOther.iToken), MCertInfo(aOther), iToken(aOther.iToken)
326 void CCTCertInfo::ConstructL(RReadStream& aStream)
328 InternalizeL(aStream);
331 void CCTCertInfo::ConstructL(const TDesC8* aIssuerHash)
333 MCertInfo::ConstructL(aIssuerHash);
336 EXPORT_C CCTCertInfo::~CCTCertInfo()
340 const TDesC& CCTCertInfo::Label() const
345 TUid CCTCertInfo::Type() const
347 TUid uid = { KCTObjectCertInfo };
351 EXPORT_C const TKeyIdentifier& CCTCertInfo::SubjectKeyId() const
353 return iSubjectKeyId;
356 EXPORT_C const TKeyIdentifier& CCTCertInfo::IssuerKeyId() const
361 EXPORT_C TCertificateFormat CCTCertInfo::CertificateFormat() const
366 EXPORT_C TCertificateOwnerType CCTCertInfo::CertificateOwnerType() const
368 return iCertificateOwnerType;
371 EXPORT_C TInt CCTCertInfo::Size() const
376 MCTToken& CCTCertInfo::Token() const
381 EXPORT_C TCTTokenObjectHandle CCTCertInfo::Handle() const
383 return TCTTokenObjectHandle(iToken.Handle(), iCertificateId);
386 EXPORT_C TBool CCTCertInfo::IsDeletable() const
391 EXPORT_C const TDesC8* CCTCertInfo::IssuerHash() const
393 return MCertInfo::IssuerHash();
396 EXPORT_C TBool CCTCertInfo::operator==(const CCTCertInfo& aCertInfo) const
398 return aCertInfo.iLabel == iLabel;
401 EXPORT_C void CCTCertInfo::SetCertificateId(TInt aCertId)
403 iCertificateId = aCertId;