Ejemplo n.º 1
0
static mrb_digest*
init(mrb_state *mrb, mrb_value self) {
  mrb_digest *digest;
  char *err_msg;
  mrb_digest_conf *c;

  c = get_digest_conf(mrb_obj_classname(mrb, self));
  if (c == NULL) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  digest = alloc_instance_data(mrb, c->ctx_size);
  digest->block_size = c->block_size;
  digest->digest_size = c->digest_size;

  digest->handle = dlopen("libcrypto.so", RTLD_LAZY);
  if (digest->handle == NULL) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "cannot find library");
  }
  dlerror();

  digest->func_init = dlsym(digest->handle, c->init_func_name);
  if ((err_msg = dlerror()) != NULL)  {
    mrb_raise(mrb, E_RUNTIME_ERROR, "cannot find function");
  }
  dlerror();

  digest->func_update = dlsym(digest->handle, c->update_func_name);
  if ((err_msg = dlerror()) != NULL)  {
    mrb_raise(mrb, E_RUNTIME_ERROR, "cannot find function");
  }
  dlerror();

  digest->func_final = dlsym(digest->handle, c->final_func_name);
  if ((err_msg = dlerror()) != NULL)  {
    mrb_raise(mrb, E_RUNTIME_ERROR, "cannot find function");
  }
  dlerror();

  call_init(mrb, FFI_FN(digest->func_init), digest->ctx);

  return digest;
}
Ejemplo n.º 2
0
void
do_buffer_data(fcode_env_t *env, token_t *d, int instance)
{
	if (!*d) {	/* check if buffer not alloc'ed yet */
		token_t *buf;

		if (instance) {
			int n, off;

			n = TOKEN_ROUNDUP(d[1]);
			buf = alloc_instance_data(env, UINIT_DATA, n, &off);
			memset(buf, 0, d[1]);
		} else {
			buf = (token_t *)HERE;
			set_here(env, HERE + d[1], "do_buffer_data");
		}
		*d = (token_t)buf;
	}
	PUSH(DS, *d);
}