/* * Copyright (C) 2006 Richard Kotal * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library 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. */ static int ns_mhash_HmacNew (Tcl_Interp * interp, char *name, char *keyword, int key_size) { Tcl_Obj *out = NULL; MHASH td = MHASH_FAILED; int ret = TCL_ERROR; if (interp == NULL || keyword == NULL) return ret; td = ns_mhash_HmacCreate (name, keyword, key_size); if (td == MHASH_FAILED) { Tcl_SetResult (interp, "Cannot create HMAC object.", TCL_STATIC); return ret; } out = ns_mhash_NewHashObj (td, STR_HMAC); if (ns_mhash_IsHashObj (out, STR_HMAC) != NS_TRUE) { ns_mhash_DestroyHashPtr (td, STR_HMAC); Tcl_SetResult (interp, "Cannot create HMAC object.", TCL_STATIC); return ret; } Tcl_SetObjResult (interp, out); return TCL_OK; } static MHASH ns_mhash_HmacCreate (char *name, char *keyword, int key_size) { int hashid = -1; MHASH td = MHASH_FAILED; hashid = ns_mhash_GetHashId (name); if (hashid == -1) { return td; } if (mhash_get_hash_pblock (hashid) == 0) { return td; } td = mhash_hmac_init (hashid, keyword, key_size, mhash_get_hash_pblock (hashid)); return td; }