/* * Copyright (C) 2007 Stef Walter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef CKCAPI_OBJECT_H #define CKCAPI_OBJECT_H #include "ckcapi.h" /* Debug print something about an object */ #define DBGO(obj, msg) \ ckcapi_debug("O%d: %s", (obj) ? (obj)->id : 0, (msg)) /* A function to load data for an object */ typedef CK_RV (*CkCapiLoadData)(CkCapiSession* sess, struct _CkCapiObject* obj, CkCapiObjectData** objdata); /* Produce a hash code for an object */ typedef CK_RV (*CkCapiHashObject)(struct _CkCapiObject* obj); /* Produce a hash code for an object */ typedef CK_RV (*CkCapiEqualObject)(struct _CkCapiObject* one, struct _CkCapiObject* two); /* A function to free some data */ typedef void (*CkCapiRelease)(void* data); /* Object functions */ typedef struct _CkCapiObjectVtable { CkCapiLoadData load_data; CkCapiHashObject hash_object; CkCapiEqualObject equal_object; CkCapiRelease release; } CkCapiObjectVtable; /* Represents a object we've seen */ struct _CkCapiObject { CK_OBJECT_HANDLE id; CK_SLOT_ID slot; CK_SESSION_HANDLE session; const CkCapiObjectVtable* obj_funcs; }; /* A function to get an attribute from ObjectData */ typedef CK_RV (*CkCapiGetAttribute)(CkCapiObjectData* objdata, CK_ATTRIBUTE_PTR attr); /* Object data functions */ typedef struct _CkCapiObjectDataVtable { CkCapiGetAttribute get_bool; CkCapiGetAttribute get_ulong; CkCapiGetAttribute get_bytes; CkCapiRelease release; } CkCapiObjectDataVtable; /* * Base class for object data. Different types of * objects extend this with more detailed data */ struct _CkCapiObjectData { CK_OBJECT_HANDLE object; const CkCapiObjectDataVtable* data_funcs; }; /* Match object data against all the given match attributes */ CK_BBOOL ckcapi_object_data_match (CkCapiObjectData* objdata, CK_ATTRIBUTE_PTR matches, CK_ULONG count); /* Match a single attribute against object data */ CK_BBOOL ckcapi_object_data_match_attr (CkCapiObjectData* objdata, CK_ATTRIBUTE_PTR match); /* Get a bunch of attributes from object data */ CK_RV ckcapi_object_data_get_attrs (CkCapiObjectData* objdata, CK_ATTRIBUTE_PTR attrs, CK_ULONG count); /* Debug print something about an object data */ #define DBGOD(objdata, msg) \ ckcapi_debug("O%d: %s", (objdata) ? (objdata)->obj : 0, (msg)) #endif /* CKCAPI_OBJECT_H */