pike.git / src / post_modules / Nettle / hash.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hash.cmod:1:   /* hash.cmod -*- c -*- */      #include "global.h" - RCSID("$Id: hash.cmod,v 1.22 2004/04/29 12:23:17 nilsson Exp $"); + RCSID("$Id: hash.cmod,v 1.23 2004/04/30 20:19:53 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "threads.h"      /* For this_object() */   #include "object.h"   #include "module_support.h"      #include "nettle_config.h"   
pike.git/src/post_modules/Nettle/hash.cmod:21:   #include <nettle/md4.h>   #include <nettle/md2.h>   #endif   #include <nettle/sha.h>   #include <nettle/nettle-meta.h>      #include <assert.h>   #include <stdio.h>   #include <stdarg.h>   #include "fdlib.h" +    #if 0   static void   werror(const char *format, ...)   {    va_list args;       va_start(args, format);    vfprintf(stderr, format, args);    va_end(args);   }
pike.git/src/post_modules/Nettle/hash.cmod:125:       digest_length = meta->digest_size;    out = begin_shared_string(digest_length);    meta->digest(ctx, digest_length, out->str);    THREADS_DISALLOW();       pop_n_elems(args);    push_string(end_shared_string(out));    }    -  /*! @decl string hash(Stdio.File file) +  /*! @decl string hash(Stdio.File file, void|int bytes)    *!    *! Works as a (faster) shortcut for    *! @expr{obj->update(Stdio.read_file(file))->digest()@}.    *! -  +  *! @param bytes +  *! The number of bytes of the file object @[file] that should be +  *! hashed. Negative numbers are ignored and the whole file is +  *! hashed. +  *!    *! @seealso    *! @[Stdio.File], @[HashState()->update()] and    *! @[HashState()->digest()].    */ -  PIKEFUN string hash(object in) +  PIKEFUN string hash(object in, void|int bytes)    optflags OPT_EXTERNAL_DEPEND;    {    void *ctx;    int len, fd;    char *read_buffer;    PIKE_STAT_T st;    struct pike_string *out;    const struct nettle_hash *meta = THIS->meta;       if (!meta)
pike.git/src/post_modules/Nettle/hash.cmod:184:    ctx = (void *)alloca(meta->context_size);    if (!ctx)    Pike_error("Out of memory.\n");       read_buffer=(char *)malloc(8192);    if (!read_buffer)    Pike_error("Out of memory.\n");       THREADS_ALLOW();    meta->init(ctx); +  if(args==2 && bytes->u.integer>-1) { +  int bytes_left = bytes->u.integer; +  int read_bytes = MINIMUM(8192, bytes_left); +  while(read_bytes>0 && (len=fd_read(fd, read_buffer, read_bytes))>0) { +  meta->update(ctx, len, read_buffer); +  bytes_left -= read_bytes; +  read_bytes = MINIMUM(8192, bytes_left); +  } +  } +  else    while((len=fd_read(fd, read_buffer, 8192))>0)    meta->update(ctx, len, read_buffer);       free(read_buffer);       out = begin_shared_string(meta->digest_size);    meta->digest(ctx, meta->digest_size, out->str);    THREADS_DISALLOW();       pop_n_elems(args);