Branch: Tag:

2003-07-29

2003-07-29 03:44:39 by Martin Nilsson <mani@lysator.liu.se>

Simplify simple hashes by providing the hash function that does update and digest in one call.

Rev: src/post_modules/Nettle/hash.cmod:1.7

1:   /* hash.cmod -*- c -*- */      #include "global.h" - RCSID("$Id: hash.cmod,v 1.6 2003/05/08 11:17:17 grubba Exp $"); + RCSID("$Id: hash.cmod,v 1.7 2003/07/29 03:44:39 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   
170:    push_string(end_shared_string(digest));    }    +  /*! @decl string hash(string data) +  *! +  *! Works as a shortcut for @expr{obj->update(data)->digest()@}. +  *! +  *! @note +  *! The hash buffer will not be cleared before @[data] is added +  *! to the buffer, so data added with calls to @[update] will be +  *! prepended to the @[data]. +  *! +  *! @seealso +  *! @[update] and @[digest]. +  */ +  PIKEFUN string hash(string data) { +  f_HashState_update(args); +  pop_stack(); +  f_HashState_digest(0); +  } +     INIT    {    werror("HashState->INIT\n");
207:       if (HashInfo && !HashInfo->meta)    HashInfo->meta = &nettle_md5; -  else +  else {    /* Can't call Pike_error here.    * Pike_error("Can't initialize this object.\n"); */    werror("MD5_Info->INIT failed\n");    }    } -  + }      /*! @endclass MD5_Info */   
258:       if (HashInfo && !HashInfo->meta)    HashInfo->meta = &nettle_sha1; -  else +  else {    /* Can't call Pike_error here.    * Pike_error("Can't initialize this object.\n"); */    werror("SHA1_Info->INIT failed\n");    }    } -  + }      /*! @endclass SHA1_Info */