class PKCS11::CK_MECHANISM

Describes a crypto mechanism CKM_* with optional parameters.

Public Class Methods

new(p1 = v1, p2 = v2) click to toggle source

Spezifies a particularly crypto mechanism. @param [Integer, nil] mechanism The mechanism to use (PKCS11::CKM_*) @param [String, Integer, PKCS11::CStruct, nil] pParameter optional parameter to the mechanism

static VALUE
cCK_MECHANISM_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE type, param;

  rb_scan_args(argc, argv, "02", &type, &param);
  rb_funcall(self, rb_intern("mechanism="), 1, type);
  rb_funcall(self, rb_intern("pParameter="), 1, param);

  return self;
}

Public Instance Methods

pParameter() click to toggle source

@see PKCS11::CK_MECHANISM#initialize

static VALUE
cCK_MECHANISM_get_pParameter(VALUE self)
{
  CK_MECHANISM_PTR m = DATA_PTR(self);
  if (!m->pParameter) return Qnil;
  else return rb_str_new(m->pParameter, m->ulParameterLen);
}
pParameter=() click to toggle source
static VALUE
cCK_MECHANISM_set_pParameter(VALUE self, VALUE value)
{
  CK_MECHANISM_PTR m = DATA_PTR(self);
  CK_ULONG ulong_val;

  switch(TYPE(value)){
  case T_NIL:
    m->pParameter = NULL_PTR;
    m->ulParameterLen = 0;
    break;
  case T_STRING:
    value = rb_obj_freeze(rb_str_dup(value));
    m->pParameter = RSTRING_PTR(value);
    m->ulParameterLen = RSTRING_LEN(value);
    break;
  case T_FIXNUM:
  case T_BIGNUM:
    ulong_val = NUM2ULONG(value);
    value = rb_obj_freeze(rb_str_new((char*)&ulong_val, sizeof(ulong_val)));
    m->pParameter = RSTRING_PTR(value);
    m->ulParameterLen = RSTRING_LEN(value);
    break;
  case T_DATA:
    m->pParameter = DATA_PTR(value);
    m->ulParameterLen = NUM2LONG(rb_const_get(rb_funcall(value, rb_intern("class"), 0), rb_intern("SIZEOF_STRUCT")));
    break;
  default:
    rb_raise(rb_eArgError, "invalid argument");
  }
  /* don't GC the value as long as this object is active */
  rb_iv_set(self, "pParameter", value);

  return value;
}