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.
26 #ifndef __CCTCERTINFO_H__
27 #define __CCTCERTINFO_H__
32 #include <securitydefs.h>
33 #include <ct/mcttokentype.h>
34 #include <ct/mcttoken.h>
35 #include <ct/mcttokenobject.h>
37 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
39 /** Mask constants used for serializing iDeletable and iFormat attributes
41 const TUint KReadOnlyFlagMask = 128;
42 const TUint KFormatMask = 127;
44 /** The UID of a CertInfo MCTTokenObject. */
45 const TInt KCTObjectCertInfo = 0x101F50E6;
49 /** The maximum length of a certificate label. */
50 const TUint32 KMaxCertLabelLength = 64;
52 /** Defines a modifiable buffer descriptor to contain a human-readable certificate label.
55 typedef TBuf<KMaxCertLabelLength> TCertLabel;
58 * Mix-in class representnig data about a stored certificate. Provides
59 * implementation of serialization.
61 * Note that for backward compatibility reasons, the issuer hash is not serialised.
67 // Internalization/Externalization
68 // Externalize. Writes the data out to a stream
70 /** Externalises an object of this class to a write stream.
72 * The presence of this function means that the standard templated operator<<()
73 * can be used to externalise objects of this class.
75 * @param aStream Stream to which the object should be externalised. */
76 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
78 // Internalize. Reads the data from a stream
79 /** Internalises an object of this class from a read stream.
81 * The presence of this function means that the standard templated operator>>()
82 * can be used to internalise objects of this class.
84 * Note that this function has assignment semantics: it replaces the old value
85 * of the object with a new value read from the read stream.
87 * @param aStream Stream from which the object should be internalised. */
88 IMPORT_C void InternalizeL(RReadStream& aStream);
92 IMPORT_C MCertInfo(const TDesC& aLabel,
93 TCertificateFormat aFormat,
94 TCertificateOwnerType aCertificateOwnerType,
96 const TKeyIdentifier* aSubjectKeyId,
97 const TKeyIdentifier* aIssuerKeyId,
100 IMPORT_C MCertInfo(const MCertInfo& aOther);
101 IMPORT_C ~MCertInfo();
103 IMPORT_C void ConstructL(const TDesC8* aIssuerHash);
105 const TDesC8* IssuerHash() const;
109 const MCertInfo& operator=(const MCertInfo& aOther);
114 TCertificateFormat iFormat;
115 TCertificateOwnerType iCertificateOwnerType;
117 TKeyIdentifier iSubjectKeyId;
118 TKeyIdentifier iIssuerKeyId;
125 /** Encapsulates information about a stored certificate.
127 * Objects of this type are usually returned by a certificate store, to allow
128 * a client to query the contents of the store.
130 * Note that these objects are normally constructed by certificate stores, not
134 class CCTCertInfo : protected CBase, public MCTTokenObject, public MCertInfo
137 /** Construction -- Note that these objects are normally constructed by certificate stores, not by clients. */
141 * Creates the certificate information object by copying from an existing object.
143 * @param aCertInfo The source certificate information.
144 * @return A pointer to the new certificate information object.
145 * @leave KErrNoMemory There is no memory to construct it. */
146 IMPORT_C static CCTCertInfo* NewL(const CCTCertInfo& aCertInfo);
150 * Creates the certificate information object by copying from an existing object,
151 * and puts a pointer to the new object onto the cleanup stack.
153 * @param aCertInfo The source certificate information.
154 * @return A pointer to the new certificate information object.
155 * @leave KErrNoMemory There is no memory to construct it. */
156 IMPORT_C static CCTCertInfo* NewLC(const CCTCertInfo& aCertInfo);
160 * Creates the certificate information object from its constituent parts.
162 * @param aLabel The certificate's label.
163 * @param aFormat The certificate's format.
164 * @param aCertificateOwnerType The owner type.
165 * @param aSize The size of the certificate.
166 * @param aSubjectKeyId The subject key ID.
167 * @param aIssuerKeyId The issuer key ID.
168 * @param aToken The token that the certificate is within.
169 * @param aCertificateId The ID within the object handle.
170 * @param aDeletable The certificate is deletable.
171 * @param aIssuerHash The hash of the DN of the issuer.
172 * @return A pointer to the new certificate information object.
173 * @leave KErrNoMemory There is no memory to construct it.*/
174 IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
175 TCertificateOwnerType aCertificateOwnerType, TInt aSize,
176 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
177 MCTToken& aToken, TInt aCertificateId, TBool aDeletable,
178 const TDesC8* aIssuerHash = NULL);
182 * Creates the certificate information object from its constituent parts.
184 * @param aLabel The certificate's label.
185 * @param aFormat The certificate's format.
186 * @param aCertificateOwnerType The owner type.
187 * @param aSize The size of the certificate.
188 * @param aSubjectKeyId The subject key ID.
189 * @param aIssuerKeyId The issuer key ID.
190 * @param aToken The token that the certificate is within.
191 * @param aCertificateId The ID within the object handle.
192 * @return A pointer to the new certificate information object.
193 * @leave KErrNoMemory There is no memory to construct it.*/
194 IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
195 TCertificateOwnerType aCertificateOwnerType, TInt aSize,
196 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
197 MCTToken& aToken, TInt aCertificateId);
201 * Creates the certificate information object from its constituent parts,
202 * and puts a pointer to the new object onto the cleanup stack.
204 * @param aLabel The certificate's label.
205 * @param aFormat The certificate's format.
206 * @param aCertificateOwnerType The owner type.
207 * @param aSize The size of the certificate.
208 * @param aSubjectKeyId The subject key ID.
209 * @param aIssuerKeyId The issuer key ID.
210 * @param aToken The token that the certificate is within.
211 * @param aCertificateId The ID within the object handle.
212 * @param aDeletable The certificate is deletable.
213 * @param aIssuerHash The hash of the issuer's DN.
214 * @return A pointer to the new certificate information object.
215 * @leave KErrNoMemory There is no memory to construct it.*/
216 IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
217 TCertificateOwnerType aCertificateOwnerType, TInt aSize,
218 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
219 MCTToken& aToken, TInt aCertificateId, TBool aDeletable,
220 const TDesC8* aIssuerHash = NULL);
224 * Creates the certificate information object from its constituent parts, and puts
225 * a pointer to the new object onto the cleanup stack.
227 * @param aLabel The certificate's label.
228 * @param aFormat The certificate's format.
229 * @param aCertificateOwnerType The owner type.
230 * @param aSize The size of the certificate.
231 * @param aSubjectKeyId The subject key ID.
232 * @param aIssuerKeyId The issuer key ID.
233 * @param aToken The token that the certificate is within.
234 * @param aCertificateId The ID within the object handle.
235 * @return A pointer to the new certificate information object.
236 * @leave KErrNoMemory There is no memory to construct it.*/
237 IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
238 TCertificateOwnerType aCertificateOwnerType, TInt aSize,
239 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
240 MCTToken& aToken, TInt aCertificateId);
244 * Creates the certificate information object by internalising a previously externalised
247 * @param aStream The stream from which the object is to be internalised.
248 * @param aToken The token that it is within.
249 * @return A pointer to the new certificate information object.
250 * @leave KErrNoMemory There is no memory to construct it.
252 * @see InternalizeL */
253 IMPORT_C static CCTCertInfo* NewL(RReadStream& aStream, MCTToken& aToken);
257 * Creates the certificate information object, by internalising a previously externalised
258 * one, and puts a pointer to the new object onto the cleanup stack.
260 * @param aStream The stream from which the object is to be internalised.
261 * @param aToken The token that it is within.
262 * @return A pointer to the new certificate information object.
263 * @leave KErrNoMemory There is no memory to construct it.
265 * @see InternalizeL */
266 IMPORT_C static CCTCertInfo* NewLC(RReadStream& aStream, MCTToken& aToken);
268 /** Gets the subject key ID.
270 * @return A reference to a key identifier object. */
271 IMPORT_C const TKeyIdentifier& SubjectKeyId() const;
273 /** Gets the issuer key ID.
275 * @return A reference to a key identifier object. */
276 IMPORT_C const TKeyIdentifier& IssuerKeyId() const;
278 /** Gets the certificate format.
280 * @return The certificate format. */
281 IMPORT_C TCertificateFormat CertificateFormat() const;
283 /** Gets the owner type.
285 * @return The owner type. */
286 IMPORT_C TCertificateOwnerType CertificateOwnerType() const;
288 /** Gets the size of the certificate.
290 * Note that this function must be called so that the correct size of descriptor
291 * can be allocated when retrieving the certificate (with MCertStore::Retrieve()).
293 * @return The size of the certificate. */
294 IMPORT_C TInt Size() const;
296 /** Gets a handle for the object.
298 * The primary purpose of the handle is to allow token objects to be 'passed'
301 * @return A handle for the object.
302 * @see TCTTokenObjectHandle */
303 IMPORT_C TCTTokenObjectHandle Handle() const;
305 /** Whether the certificate is deletable.
307 * @return ETrue if it is possible to delete the certificate; EFalse, otherwise. */
308 IMPORT_C TBool IsDeletable() const;
310 /** Gets the hash of the issuer's DN.
312 * @return The hash of the issuer's DN, or NULL if not known. */
313 IMPORT_C const TDesC8* IssuerHash() const;
316 // from MCTTokenObject
317 /** Gets the object's human-readable label.
319 * @return The object's human-readable label.
320 * @see MCTTokenObject::Label()*/
321 virtual const TDesC& Label() const;
323 /** Gets a reference to the associated token.
325 * @return A reference to the associated token.
326 * @see MCTTokenObject::Token()*/
327 virtual MCTToken& Token() const;
329 /** Gets a UID representing the type of the token object.
331 * The function overrides MCTTokenObject::Type().
333 * The meanings of possible UIDs should be documented in the documentation for
334 * the interface that returns them.
336 * @return A UID representing the type of the token object; this implementation
337 * returns KCTObjectCertInfo.
338 * @see MCTTokenObject::Type() */
339 virtual TUid Type() const;
341 // Compares 2 cert infos
342 /** Compares this certificate information object with a specified Certificate
343 * Information object for equality.
345 * @param aCertInfo The certificate information object to be compared.
346 * @return ETrue, if they are the same; EFalse, otherwise. */
347 IMPORT_C TBool operator ==(const CCTCertInfo& aCertInfo) const;
349 /** Sets the certificate Id.
351 * @param aCertId The certificate Id.*/
352 IMPORT_C void SetCertificateId(TInt aCertId);
355 IMPORT_C virtual ~CCTCertInfo();
358 CCTCertInfo(MCTToken& aToken);
359 CCTCertInfo(const TDesC& aLabel, TCertificateFormat aFormat,
360 TCertificateOwnerType aCertificateOwnerType,
362 const TKeyIdentifier* aSubjectKeyId,
363 const TKeyIdentifier* aIssuerKeyId,
364 MCTToken& aToken, TInt aCertificateId,
366 CCTCertInfo(const CCTCertInfo& aCertInfo);
367 void ConstructL(RReadStream& aStream);
368 void ConstructL(const TDesC8* aIssuerHash);
371 const CCTCertInfo& operator=(const CCTCertInfo& aOther);