Bug 449533. Set the mFixedPitch flag within SetFixedPitch. r+sr=vlad
[wine-gecko.git] / security / nss / lib / ckfw / object.c
blob740a0591b93eb3494e317b2366635ef9ddc250d5
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifdef DEBUG
38 static const char CVS_ID[] = "@(#) $RCSfile: object.c,v $ $Revision: 1.15 $ $Date: 2007/12/12 00:41:37 $";
39 #endif /* DEBUG */
42 * object.c
44 * This file implements the NSSCKFWObject type and methods.
47 #ifndef CK_T
48 #include "ck.h"
49 #endif /* CK_T */
52 * NSSCKFWObject
54 * -- create/destroy --
55 * nssCKFWObject_Create
56 * nssCKFWObject_Finalize
57 * nssCKFWObject_Destroy
59 * -- public accessors --
60 * NSSCKFWObject_GetMDObject
61 * NSSCKFWObject_GetArena
62 * NSSCKFWObject_IsTokenObject
63 * NSSCKFWObject_GetAttributeCount
64 * NSSCKFWObject_GetAttributeTypes
65 * NSSCKFWObject_GetAttributeSize
66 * NSSCKFWObject_GetAttribute
67 * NSSCKFWObject_SetAttribute
68 * NSSCKFWObject_GetObjectSize
70 * -- implement public accessors --
71 * nssCKFWObject_GetMDObject
72 * nssCKFWObject_GetArena
74 * -- private accessors --
75 * nssCKFWObject_SetHandle
76 * nssCKFWObject_GetHandle
78 * -- module fronts --
79 * nssCKFWObject_IsTokenObject
80 * nssCKFWObject_GetAttributeCount
81 * nssCKFWObject_GetAttributeTypes
82 * nssCKFWObject_GetAttributeSize
83 * nssCKFWObject_GetAttribute
84 * nssCKFWObject_SetAttribute
85 * nssCKFWObject_GetObjectSize
88 struct NSSCKFWObjectStr {
89 NSSCKFWMutex *mutex; /* merely to serialise the MDObject calls */
90 NSSArena *arena;
91 NSSCKMDObject *mdObject;
92 NSSCKMDSession *mdSession;
93 NSSCKFWSession *fwSession;
94 NSSCKMDToken *mdToken;
95 NSSCKFWToken *fwToken;
96 NSSCKMDInstance *mdInstance;
97 NSSCKFWInstance *fwInstance;
98 CK_OBJECT_HANDLE hObject;
101 #ifdef DEBUG
103 * But first, the pointer-tracking stuff.
105 * NOTE: the pointer-tracking support in NSS/base currently relies
106 * upon NSPR's CallOnce support. That, however, relies upon NSPR's
107 * locking, which is tied into the runtime. We need a pointer-tracker
108 * implementation that uses the locks supplied through C_Initialize.
109 * That support, however, can be filled in later. So for now, I'll
110 * just do this routines as no-ops.
113 static CK_RV
114 object_add_pointer
116 const NSSCKFWObject *fwObject
119 return CKR_OK;
122 static CK_RV
123 object_remove_pointer
125 const NSSCKFWObject *fwObject
128 return CKR_OK;
131 NSS_IMPLEMENT CK_RV
132 nssCKFWObject_verifyPointer
134 const NSSCKFWObject *fwObject
137 return CKR_OK;
140 #endif /* DEBUG */
144 * nssCKFWObject_Create
147 NSS_IMPLEMENT NSSCKFWObject *
148 nssCKFWObject_Create
150 NSSArena *arena,
151 NSSCKMDObject *mdObject,
152 NSSCKFWSession *fwSession,
153 NSSCKFWToken *fwToken,
154 NSSCKFWInstance *fwInstance,
155 CK_RV *pError
158 NSSCKFWObject *fwObject;
159 nssCKFWHash *mdObjectHash;
161 #ifdef NSSDEBUG
162 if( (CK_RV *)NULL == pError ) {
163 return (NSSCKFWObject *)NULL;
166 if( PR_SUCCESS != nssArena_verifyPointer(arena) ) {
167 *pError = CKR_ARGUMENTS_BAD;
168 return (NSSCKFWObject *)NULL;
170 #endif /* NSSDEBUG */
172 if( (NSSCKFWToken *)NULL == fwToken ) {
173 *pError = CKR_ARGUMENTS_BAD;
174 return (NSSCKFWObject *)NULL;
176 mdObjectHash = nssCKFWToken_GetMDObjectHash(fwToken);
177 if( (nssCKFWHash *)NULL == mdObjectHash ) {
178 *pError = CKR_GENERAL_ERROR;
179 return (NSSCKFWObject *)NULL;
182 if( nssCKFWHash_Exists(mdObjectHash, mdObject) ) {
183 fwObject = nssCKFWHash_Lookup(mdObjectHash, mdObject);
184 return fwObject;
187 fwObject = nss_ZNEW(arena, NSSCKFWObject);
188 if( (NSSCKFWObject *)NULL == fwObject ) {
189 *pError = CKR_HOST_MEMORY;
190 return (NSSCKFWObject *)NULL;
193 fwObject->arena = arena;
194 fwObject->mdObject = mdObject;
195 fwObject->fwSession = fwSession;
197 if( (NSSCKFWSession *)NULL != fwSession ) {
198 fwObject->mdSession = nssCKFWSession_GetMDSession(fwSession);
201 fwObject->fwToken = fwToken;
202 fwObject->mdToken = nssCKFWToken_GetMDToken(fwToken);
203 fwObject->fwInstance = fwInstance;
204 fwObject->mdInstance = nssCKFWInstance_GetMDInstance(fwInstance);
205 fwObject->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
206 if( (NSSCKFWMutex *)NULL == fwObject->mutex ) {
207 if( CKR_OK == *pError ) {
208 *pError = CKR_GENERAL_ERROR;
210 return (NSSCKFWObject *)NULL;
213 *pError = nssCKFWHash_Add(mdObjectHash, mdObject, fwObject);
214 if( CKR_OK != *pError ) {
215 nss_ZFreeIf(fwObject);
216 return (NSSCKFWObject *)NULL;
219 #ifdef DEBUG
220 *pError = object_add_pointer(fwObject);
221 if( CKR_OK != *pError ) {
222 nssCKFWHash_Remove(mdObjectHash, mdObject);
223 nss_ZFreeIf(fwObject);
224 return (NSSCKFWObject *)NULL;
226 #endif /* DEBUG */
228 *pError = CKR_OK;
229 return fwObject;
233 * nssCKFWObject_Finalize
236 NSS_IMPLEMENT void
237 nssCKFWObject_Finalize
239 NSSCKFWObject *fwObject,
240 PRBool removeFromHash
243 nssCKFWHash *mdObjectHash;
245 #ifdef NSSDEBUG
246 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
247 return;
249 #endif /* NSSDEBUG */
251 (void)nssCKFWMutex_Destroy(fwObject->mutex);
253 if( (void *)NULL != (void *)fwObject->mdObject->Finalize ) {
254 fwObject->mdObject->Finalize(fwObject->mdObject, fwObject,
255 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
256 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance);
259 if (removeFromHash) {
260 mdObjectHash = nssCKFWToken_GetMDObjectHash(fwObject->fwToken);
261 if( (nssCKFWHash *)NULL != mdObjectHash ) {
262 nssCKFWHash_Remove(mdObjectHash, fwObject->mdObject);
266 if (fwObject->fwSession) {
267 nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
269 nss_ZFreeIf(fwObject);
271 #ifdef DEBUG
272 (void)object_remove_pointer(fwObject);
273 #endif /* DEBUG */
275 return;
279 * nssCKFWObject_Destroy
282 NSS_IMPLEMENT void
283 nssCKFWObject_Destroy
285 NSSCKFWObject *fwObject
288 nssCKFWHash *mdObjectHash;
290 #ifdef NSSDEBUG
291 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
292 return;
294 #endif /* NSSDEBUG */
296 (void)nssCKFWMutex_Destroy(fwObject->mutex);
298 if( (void *)NULL != (void *)fwObject->mdObject->Destroy ) {
299 fwObject->mdObject->Destroy(fwObject->mdObject, fwObject,
300 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
301 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance);
304 mdObjectHash = nssCKFWToken_GetMDObjectHash(fwObject->fwToken);
305 if( (nssCKFWHash *)NULL != mdObjectHash ) {
306 nssCKFWHash_Remove(mdObjectHash, fwObject->mdObject);
309 if (fwObject->fwSession) {
310 nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
312 nss_ZFreeIf(fwObject);
314 #ifdef DEBUG
315 (void)object_remove_pointer(fwObject);
316 #endif /* DEBUG */
318 return;
322 * nssCKFWObject_GetMDObject
325 NSS_IMPLEMENT NSSCKMDObject *
326 nssCKFWObject_GetMDObject
328 NSSCKFWObject *fwObject
331 #ifdef NSSDEBUG
332 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
333 return (NSSCKMDObject *)NULL;
335 #endif /* NSSDEBUG */
337 return fwObject->mdObject;
341 * nssCKFWObject_GetArena
344 NSS_IMPLEMENT NSSArena *
345 nssCKFWObject_GetArena
347 NSSCKFWObject *fwObject,
348 CK_RV *pError
351 #ifdef NSSDEBUG
352 if( (CK_RV *)NULL == pError ) {
353 return (NSSArena *)NULL;
356 *pError = nssCKFWObject_verifyPointer(fwObject);
357 if( CKR_OK != *pError ) {
358 return (NSSArena *)NULL;
360 #endif /* NSSDEBUG */
362 return fwObject->arena;
366 * nssCKFWObject_SetHandle
369 NSS_IMPLEMENT CK_RV
370 nssCKFWObject_SetHandle
372 NSSCKFWObject *fwObject,
373 CK_OBJECT_HANDLE hObject
376 #ifdef NSSDEBUG
377 CK_RV error = CKR_OK;
378 #endif /* NSSDEBUG */
380 #ifdef NSSDEBUG
381 error = nssCKFWObject_verifyPointer(fwObject);
382 if( CKR_OK != error ) {
383 return error;
385 #endif /* NSSDEBUG */
387 if( (CK_OBJECT_HANDLE)0 != fwObject->hObject ) {
388 return CKR_GENERAL_ERROR;
391 fwObject->hObject = hObject;
393 return CKR_OK;
397 * nssCKFWObject_GetHandle
400 NSS_IMPLEMENT CK_OBJECT_HANDLE
401 nssCKFWObject_GetHandle
403 NSSCKFWObject *fwObject
406 #ifdef NSSDEBUG
407 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
408 return (CK_OBJECT_HANDLE)0;
410 #endif /* NSSDEBUG */
412 return fwObject->hObject;
416 * nssCKFWObject_IsTokenObject
419 NSS_IMPLEMENT CK_BBOOL
420 nssCKFWObject_IsTokenObject
422 NSSCKFWObject *fwObject
425 CK_BBOOL b = CK_FALSE;
427 #ifdef NSSDEBUG
428 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
429 return CK_FALSE;
431 #endif /* NSSDEBUG */
433 if( (void *)NULL == (void *)fwObject->mdObject->IsTokenObject ) {
434 NSSItem item;
435 NSSItem *pItem;
436 CK_RV rv = CKR_OK;
438 item.data = (void *)&b;
439 item.size = sizeof(b);
441 pItem = nssCKFWObject_GetAttribute(fwObject, CKA_TOKEN, &item,
442 (NSSArena *)NULL, &rv);
443 if( (NSSItem *)NULL == pItem ) {
444 /* Error of some type */
445 b = CK_FALSE;
446 goto done;
449 goto done;
452 b = fwObject->mdObject->IsTokenObject(fwObject->mdObject, fwObject,
453 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
454 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance);
456 done:
457 return b;
461 * nssCKFWObject_GetAttributeCount
464 NSS_IMPLEMENT CK_ULONG
465 nssCKFWObject_GetAttributeCount
467 NSSCKFWObject *fwObject,
468 CK_RV *pError
471 CK_ULONG rv;
473 #ifdef NSSDEBUG
474 if( (CK_RV *)NULL == pError ) {
475 return (CK_ULONG)0;
478 *pError = nssCKFWObject_verifyPointer(fwObject);
479 if( CKR_OK != *pError ) {
480 return (CK_ULONG)0;
482 #endif /* NSSDEBUG */
484 if( (void *)NULL == (void *)fwObject->mdObject->GetAttributeCount ) {
485 *pError = CKR_GENERAL_ERROR;
486 return (CK_ULONG)0;
489 *pError = nssCKFWMutex_Lock(fwObject->mutex);
490 if( CKR_OK != *pError ) {
491 return (CK_ULONG)0;
494 rv = fwObject->mdObject->GetAttributeCount(fwObject->mdObject, fwObject,
495 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
496 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
497 pError);
499 (void)nssCKFWMutex_Unlock(fwObject->mutex);
500 return rv;
504 * nssCKFWObject_GetAttributeTypes
507 NSS_IMPLEMENT CK_RV
508 nssCKFWObject_GetAttributeTypes
510 NSSCKFWObject *fwObject,
511 CK_ATTRIBUTE_TYPE_PTR typeArray,
512 CK_ULONG ulCount
515 CK_RV error = CKR_OK;
517 #ifdef NSSDEBUG
518 error = nssCKFWObject_verifyPointer(fwObject);
519 if( CKR_OK != error ) {
520 return error;
523 if( (CK_ATTRIBUTE_TYPE_PTR)NULL == typeArray ) {
524 return CKR_ARGUMENTS_BAD;
526 #endif /* NSSDEBUG */
528 if( (void *)NULL == (void *)fwObject->mdObject->GetAttributeTypes ) {
529 return CKR_GENERAL_ERROR;
532 error = nssCKFWMutex_Lock(fwObject->mutex);
533 if( CKR_OK != error ) {
534 return error;
537 error = fwObject->mdObject->GetAttributeTypes(fwObject->mdObject, fwObject,
538 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
539 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
540 typeArray, ulCount);
542 (void)nssCKFWMutex_Unlock(fwObject->mutex);
543 return error;
547 * nssCKFWObject_GetAttributeSize
550 NSS_IMPLEMENT CK_ULONG
551 nssCKFWObject_GetAttributeSize
553 NSSCKFWObject *fwObject,
554 CK_ATTRIBUTE_TYPE attribute,
555 CK_RV *pError
558 CK_ULONG rv;
560 #ifdef NSSDEBUG
561 if( (CK_RV *)NULL == pError ) {
562 return (CK_ULONG)0;
565 *pError = nssCKFWObject_verifyPointer(fwObject);
566 if( CKR_OK != *pError ) {
567 return (CK_ULONG)0;
569 #endif /* NSSDEBUG */
571 if( (void *)NULL == (void *)fwObject->mdObject->GetAttributeSize ) {
572 *pError = CKR_GENERAL_ERROR;
573 return (CK_ULONG )0;
576 *pError = nssCKFWMutex_Lock(fwObject->mutex);
577 if( CKR_OK != *pError ) {
578 return (CK_ULONG)0;
581 rv = fwObject->mdObject->GetAttributeSize(fwObject->mdObject, fwObject,
582 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
583 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
584 attribute, pError);
586 (void)nssCKFWMutex_Unlock(fwObject->mutex);
587 return rv;
591 * nssCKFWObject_GetAttribute
593 * Usual NSS allocation rules:
594 * If itemOpt is not NULL, it will be returned; otherwise an NSSItem
595 * will be allocated. If itemOpt is not NULL but itemOpt->data is,
596 * the buffer will be allocated; otherwise, the buffer will be used.
597 * Any allocations will come from the optional arena, if one is
598 * specified.
600 NSS_IMPLEMENT NSSItem *
601 nssCKFWObject_GetAttribute
603 NSSCKFWObject *fwObject,
604 CK_ATTRIBUTE_TYPE attribute,
605 NSSItem *itemOpt,
606 NSSArena *arenaOpt,
607 CK_RV *pError
610 NSSItem *rv = (NSSItem *)NULL;
611 NSSCKFWItem mdItem;
613 #ifdef NSSDEBUG
614 if( (CK_RV *)NULL == pError ) {
615 return (NSSItem *)NULL;
618 *pError = nssCKFWObject_verifyPointer(fwObject);
619 if( CKR_OK != *pError ) {
620 return (NSSItem *)NULL;
622 #endif /* NSSDEBUG */
624 if( (void *)NULL == (void *)fwObject->mdObject->GetAttribute ) {
625 *pError = CKR_GENERAL_ERROR;
626 return (NSSItem *)NULL;
629 *pError = nssCKFWMutex_Lock(fwObject->mutex);
630 if( CKR_OK != *pError ) {
631 return (NSSItem *)NULL;
634 mdItem = fwObject->mdObject->GetAttribute(fwObject->mdObject, fwObject,
635 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
636 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
637 attribute, pError);
639 if( (NSSItem *)NULL == mdItem.item ) {
640 if( CKR_OK == *pError ) {
641 *pError = CKR_GENERAL_ERROR;
644 goto done;
647 if( (NSSItem *)NULL == itemOpt ) {
648 rv = nss_ZNEW(arenaOpt, NSSItem);
649 if( (NSSItem *)NULL == rv ) {
650 *pError = CKR_HOST_MEMORY;
651 goto done;
653 } else {
654 rv = itemOpt;
657 if( (void *)NULL == rv->data ) {
658 rv->size = mdItem.item->size;
659 rv->data = nss_ZAlloc(arenaOpt, rv->size);
660 if( (void *)NULL == rv->data ) {
661 *pError = CKR_HOST_MEMORY;
662 if( (NSSItem *)NULL == itemOpt ) {
663 nss_ZFreeIf(rv);
665 rv = (NSSItem *)NULL;
666 goto done;
668 } else {
669 if( rv->size >= mdItem.item->size ) {
670 rv->size = mdItem.item->size;
671 } else {
672 *pError = CKR_BUFFER_TOO_SMALL;
673 /* Should we set rv->size to mdItem->size? */
674 /* rv can't have been allocated */
675 rv = (NSSItem *)NULL;
676 goto done;
680 (void)nsslibc_memcpy(rv->data, mdItem.item->data, rv->size);
682 if (PR_TRUE == mdItem.needsFreeing) {
683 PR_ASSERT(fwObject->mdObject->FreeAttribute);
684 if (fwObject->mdObject->FreeAttribute) {
685 *pError = fwObject->mdObject->FreeAttribute(&mdItem);
689 done:
690 (void)nssCKFWMutex_Unlock(fwObject->mutex);
691 return rv;
695 * nssCKFWObject_SetAttribute
698 NSS_IMPLEMENT CK_RV
699 nssCKFWObject_SetAttribute
701 NSSCKFWObject *fwObject,
702 NSSCKFWSession *fwSession,
703 CK_ATTRIBUTE_TYPE attribute,
704 NSSItem *value
707 CK_RV error = CKR_OK;
709 #ifdef NSSDEBUG
710 error = nssCKFWObject_verifyPointer(fwObject);
711 if( CKR_OK != error ) {
712 return error;
714 #endif /* NSSDEBUG */
716 if( CKA_TOKEN == attribute ) {
718 * We're changing from a session object to a token object or
719 * vice-versa.
722 CK_ATTRIBUTE a;
723 NSSCKFWObject *newFwObject;
724 NSSCKFWObject swab;
726 a.type = CKA_TOKEN;
727 a.pValue = value->data;
728 a.ulValueLen = value->size;
730 newFwObject = nssCKFWSession_CopyObject(fwSession, fwObject,
731 &a, 1, &error);
732 if( (NSSCKFWObject *)NULL == newFwObject ) {
733 if( CKR_OK == error ) {
734 error = CKR_GENERAL_ERROR;
736 return error;
740 * Actually, I bet the locking is worse than this.. this part of
741 * the code could probably use some scrutiny and reworking.
743 error = nssCKFWMutex_Lock(fwObject->mutex);
744 if( CKR_OK != error ) {
745 nssCKFWObject_Destroy(newFwObject);
746 return error;
749 error = nssCKFWMutex_Lock(newFwObject->mutex);
750 if( CKR_OK != error ) {
751 nssCKFWMutex_Unlock(fwObject->mutex);
752 nssCKFWObject_Destroy(newFwObject);
753 return error;
757 * Now, we have our new object, but it has a new fwObject pointer,
758 * while we have to keep the existing one. So quick swap the contents.
760 swab = *fwObject;
761 *fwObject = *newFwObject;
762 *newFwObject = swab;
764 /* But keep the mutexes the same */
765 swab.mutex = fwObject->mutex;
766 fwObject->mutex = newFwObject->mutex;
767 newFwObject->mutex = swab.mutex;
769 (void)nssCKFWMutex_Unlock(newFwObject->mutex);
770 (void)nssCKFWMutex_Unlock(fwObject->mutex);
773 * Either remove or add this to the list of session objects
776 if( CK_FALSE == *(CK_BBOOL *)value->data ) {
778 * New one is a session object, except since we "stole" the fwObject, it's
779 * not in the list. Add it.
781 nssCKFWSession_RegisterSessionObject(fwSession, fwObject);
782 } else {
784 * New one is a token object, except since we "stole" the fwObject, it's
785 * in the list. Remove it.
787 if (fwObject->fwSession) {
788 nssCKFWSession_DeregisterSessionObject(fwObject->fwSession, fwObject);
793 * Now delete the old object. Remember the names have changed.
795 nssCKFWObject_Destroy(newFwObject);
797 return CKR_OK;
798 } else {
800 * An "ordinary" change.
802 if( (void *)NULL == (void *)fwObject->mdObject->SetAttribute ) {
803 /* We could fake it with copying, like above.. later */
804 return CKR_ATTRIBUTE_READ_ONLY;
807 error = nssCKFWMutex_Lock(fwObject->mutex);
808 if( CKR_OK != error ) {
809 return error;
812 error = fwObject->mdObject->SetAttribute(fwObject->mdObject, fwObject,
813 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
814 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
815 attribute, value);
817 (void)nssCKFWMutex_Unlock(fwObject->mutex);
819 return error;
824 * nssCKFWObject_GetObjectSize
827 NSS_IMPLEMENT CK_ULONG
828 nssCKFWObject_GetObjectSize
830 NSSCKFWObject *fwObject,
831 CK_RV *pError
834 CK_ULONG rv;
836 #ifdef NSSDEBUG
837 if( (CK_RV *)NULL == pError ) {
838 return (CK_ULONG)0;
841 *pError = nssCKFWObject_verifyPointer(fwObject);
842 if( CKR_OK != *pError ) {
843 return (CK_ULONG)0;
845 #endif /* NSSDEBUG */
847 if( (void *)NULL == (void *)fwObject->mdObject->GetObjectSize ) {
848 *pError = CKR_INFORMATION_SENSITIVE;
849 return (CK_ULONG)0;
852 *pError = nssCKFWMutex_Lock(fwObject->mutex);
853 if( CKR_OK != *pError ) {
854 return (CK_ULONG)0;
857 rv = fwObject->mdObject->GetObjectSize(fwObject->mdObject, fwObject,
858 fwObject->mdSession, fwObject->fwSession, fwObject->mdToken,
859 fwObject->fwToken, fwObject->mdInstance, fwObject->fwInstance,
860 pError);
862 (void)nssCKFWMutex_Unlock(fwObject->mutex);
863 return rv;
867 * NSSCKFWObject_GetMDObject
870 NSS_IMPLEMENT NSSCKMDObject *
871 NSSCKFWObject_GetMDObject
873 NSSCKFWObject *fwObject
876 #ifdef DEBUG
877 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
878 return (NSSCKMDObject *)NULL;
880 #endif /* DEBUG */
882 return nssCKFWObject_GetMDObject(fwObject);
886 * NSSCKFWObject_GetArena
889 NSS_IMPLEMENT NSSArena *
890 NSSCKFWObject_GetArena
892 NSSCKFWObject *fwObject,
893 CK_RV *pError
896 #ifdef DEBUG
897 if( (CK_RV *)NULL == pError ) {
898 return (NSSArena *)NULL;
901 *pError = nssCKFWObject_verifyPointer(fwObject);
902 if( CKR_OK != *pError ) {
903 return (NSSArena *)NULL;
905 #endif /* DEBUG */
907 return nssCKFWObject_GetArena(fwObject, pError);
911 * NSSCKFWObject_IsTokenObject
914 NSS_IMPLEMENT CK_BBOOL
915 NSSCKFWObject_IsTokenObject
917 NSSCKFWObject *fwObject
920 #ifdef DEBUG
921 if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
922 return CK_FALSE;
924 #endif /* DEBUG */
926 return nssCKFWObject_IsTokenObject(fwObject);
930 * NSSCKFWObject_GetAttributeCount
933 NSS_IMPLEMENT CK_ULONG
934 NSSCKFWObject_GetAttributeCount
936 NSSCKFWObject *fwObject,
937 CK_RV *pError
940 #ifdef DEBUG
941 if( (CK_RV *)NULL == pError ) {
942 return (CK_ULONG)0;
945 *pError = nssCKFWObject_verifyPointer(fwObject);
946 if( CKR_OK != *pError ) {
947 return (CK_ULONG)0;
949 #endif /* DEBUG */
951 return nssCKFWObject_GetAttributeCount(fwObject, pError);
955 * NSSCKFWObject_GetAttributeTypes
958 NSS_IMPLEMENT CK_RV
959 NSSCKFWObject_GetAttributeTypes
961 NSSCKFWObject *fwObject,
962 CK_ATTRIBUTE_TYPE_PTR typeArray,
963 CK_ULONG ulCount
966 #ifdef DEBUG
967 CK_RV error = CKR_OK;
969 error = nssCKFWObject_verifyPointer(fwObject);
970 if( CKR_OK != error ) {
971 return error;
974 if( (CK_ATTRIBUTE_TYPE_PTR)NULL == typeArray ) {
975 return CKR_ARGUMENTS_BAD;
977 #endif /* DEBUG */
979 return nssCKFWObject_GetAttributeTypes(fwObject, typeArray, ulCount);
983 * NSSCKFWObject_GetAttributeSize
986 NSS_IMPLEMENT CK_ULONG
987 NSSCKFWObject_GetAttributeSize
989 NSSCKFWObject *fwObject,
990 CK_ATTRIBUTE_TYPE attribute,
991 CK_RV *pError
994 #ifdef DEBUG
995 if( (CK_RV *)NULL == pError ) {
996 return (CK_ULONG)0;
999 *pError = nssCKFWObject_verifyPointer(fwObject);
1000 if( CKR_OK != *pError ) {
1001 return (CK_ULONG)0;
1003 #endif /* DEBUG */
1005 return nssCKFWObject_GetAttributeSize(fwObject, attribute, pError);
1009 * NSSCKFWObject_GetAttribute
1012 NSS_IMPLEMENT NSSItem *
1013 NSSCKFWObject_GetAttribute
1015 NSSCKFWObject *fwObject,
1016 CK_ATTRIBUTE_TYPE attribute,
1017 NSSItem *itemOpt,
1018 NSSArena *arenaOpt,
1019 CK_RV *pError
1022 #ifdef DEBUG
1023 if( (CK_RV *)NULL == pError ) {
1024 return (NSSItem *)NULL;
1027 *pError = nssCKFWObject_verifyPointer(fwObject);
1028 if( CKR_OK != *pError ) {
1029 return (NSSItem *)NULL;
1031 #endif /* DEBUG */
1033 return nssCKFWObject_GetAttribute(fwObject, attribute, itemOpt, arenaOpt, pError);
1037 * NSSCKFWObject_GetObjectSize
1040 NSS_IMPLEMENT CK_ULONG
1041 NSSCKFWObject_GetObjectSize
1043 NSSCKFWObject *fwObject,
1044 CK_RV *pError
1047 #ifdef DEBUG
1048 if( (CK_RV *)NULL == pError ) {
1049 return (CK_ULONG)0;
1052 *pError = nssCKFWObject_verifyPointer(fwObject);
1053 if( CKR_OK != *pError ) {
1054 return (CK_ULONG)0;
1056 #endif /* DEBUG */
1058 return nssCKFWObject_GetObjectSize(fwObject, pError);