pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:2192:       PIKEFUN mixed random(object o)    {    int f = low_find_lfun(o->prog, LFUN__RANDOM);    if (f < 0)    Pike_error("Calling undefined lfun::%s.\n", lfun_names[LFUN__RANDOM]);    apply_low(o, f, 0);    }   }    + #ifdef __NT__ + #include <wincrypt.h>   PIKECLASS RandomSystem   {    INHERIT RandomInterface; -  +  CVAR HCRYPTPROV handle; +  +  INIT +  { +  THIS->handle = NULL; +  } +  +  PIKEFUN string random_string(int(0..) len) +  { +  if(!crypto_handle) +  { +  if( !CryptAcquireContext(&THIS->handle, 0, 0, PROV_RSA_FULL, +  CRYPT_VERIFYCONTEXT|CRYPT_SILENT) ) +  Pike_error("Failed to set up Crypto Service.\n"); +  } +  +  struct pike_string *res = begin_shared_string(size); +  if( !CryptGenRandom(THIS->handle, size, (BYTE*)res->str) ) +  { +  do_free_unlinked_pike_string (res); +  Pike_error("Failed to create random data.\n"); +  } +  +  RETURN end_shared_string(res); +  } + } + #else + PIKECLASS RandomSystem + { +  INHERIT RandomInterface;    CVAR int fd;       INIT    {    THIS->fd = -1;    }       EXIT    {    close(THIS->fd);
pike.git/src/builtin.cmod:2229:    {    int sz = read(THIS->fd, str, len);    str += sz;    len -= sz;    }       pop_n_elems(args);    push_string(end_shared_string(ret));    }   } + #endif      /*! @decl mixed random(object o)    *! If random is called with an object, @[lfun::random] will be    *! called in the object.    *!    *! @seealso    *! @[lfun::_random()]    */      PMOD_EXPORT