class PKCS11::CK_ATTRIBUTE

Struct to hold an attribute type and it's value.

@see PKCS11::Object

Public Class Methods

new(p1 = v1, p2 = v2) click to toggle source
static VALUE
ck_attr_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE type, value;
  CK_ATTRIBUTE *attr;

  rb_scan_args(argc, argv, "02", &type, &value);
  Data_Get_Struct(self, CK_ATTRIBUTE, attr);
  if (argc == 0) return self;
  attr->type = NUM2HANDLE(type);
  attr->pValue = NULL;
  switch(TYPE(value)){
  case T_TRUE:
    attr->pValue = (CK_BYTE_PTR)malloc(sizeof(CK_BBOOL));
    *((CK_BBOOL*)attr->pValue) = TRUE;
    attr->ulValueLen = sizeof(CK_BBOOL);
    break;
  case T_FALSE:
    attr->pValue = (CK_BYTE_PTR)malloc(sizeof(CK_BBOOL));
    *((CK_BBOOL*)attr->pValue) = FALSE;
    attr->ulValueLen = sizeof(CK_BBOOL);
    break;
  case T_NIL:
    attr->pValue = (CK_BYTE_PTR)NULL;
    attr->ulValueLen = 0;
    break;
  case T_FIXNUM:
  case T_BIGNUM:
    attr->pValue = (CK_BYTE_PTR)malloc(sizeof(CK_OBJECT_CLASS));
    *((CK_OBJECT_CLASS*)attr->pValue) = NUM2ULONG(value);
    attr->ulValueLen = sizeof(CK_OBJECT_CLASS);
    break;
  default:
    StringValue(value);
    attr->pValue = (CK_BYTE_PTR)malloc(RSTRING_LEN(value));
    memcpy(attr->pValue, RSTRING_PTR(value), RSTRING_LEN(value));
    attr->ulValueLen = RSTRING_LEN(value);
    break;
  }
  return self;
}

Public Instance Methods

inspect() click to toggle source
# File lib/pkcs11/extensions.rb, line 64
def inspect
  "#<#{self.class} #{ to_s ? "#{to_s} (#{type})" : type} value=#{value.inspect}>"
end
members() click to toggle source

@return [Array<String>] attribute names

# File lib/pkcs11/extensions.rb, line 48
def members
  ['type', 'value']
end
to_hash() click to toggle source

@return [Hash] with attribute names and current values

# File lib/pkcs11/extensions.rb, line 56
def to_hash
  members.inject({}){|h,v| h[v.intern] = send(v); h }
end
to_s() click to toggle source

Get the constant name as String of the given value. @return [String, nil] Returns nil if value is unknown

# File lib/pkcs11/extensions.rb, line 61
def to_s
  ATTRIBUTES[type]
end
type() click to toggle source

@return [Integer] attribute type PKCS11::CKA_*

static VALUE
ck_attr_type(VALUE self)
{
  CK_ATTRIBUTE *attr;
  Data_Get_Struct(self, CK_ATTRIBUTE, attr);
  return ULONG2NUM(attr->type);
}
Also aliased as: type
value() click to toggle source

@return [String, Integer, Boolean] attribute value @see PKCS11::Object#[]

static VALUE
ck_attr_value(VALUE self)
{
  CK_ATTRIBUTE *attr;
  Data_Get_Struct(self, CK_ATTRIBUTE, attr);
  if (attr->ulValueLen == 0) return Qnil;
  switch(attr->type){
  case CKA_ALWAYS_AUTHENTICATE:
  case CKA_ALWAYS_SENSITIVE:
  case CKA_COLOR:
/*  case CKA_COPYABLE: v2.3 */
  case CKA_DECRYPT:
  case CKA_DERIVE:
  case CKA_ENCRYPT:
  case CKA_EXTRACTABLE:
  case CKA_HAS_RESET:
  case CKA_LOCAL:
  case CKA_MODIFIABLE:
  case CKA_NEVER_EXTRACTABLE:
  case CKA_OTP_USER_FRIENDLY_MODE:
  case CKA_PRIVATE:
  case CKA_SENSITIVE:
  case CKA_SIGN:
  case CKA_SIGN_RECOVER:
  case CKA_TOKEN:
  case CKA_TRUSTED:
  case CKA_UNWRAP:
  case CKA_VERIFY:
  case CKA_VERIFY_RECOVER:
  case CKA_WRAP:
  case CKA_WRAP_WITH_TRUSTED:
    if (attr->ulValueLen == sizeof(CK_BBOOL))
      return (*(CK_BBOOL*)(attr->pValue)) == CK_TRUE ? Qtrue : Qfalse;
    break;
  case CKA_BITS_PER_PIXEL:
  case CKA_CERTIFICATE_CATEGORY:
  case CKA_CERTIFICATE_TYPE:
  case CKA_CHAR_COLUMNS:
  case CKA_CHAR_ROWS:
  case CKA_CLASS:
  case CKA_HW_FEATURE_TYPE:
  case CKA_JAVA_MIDP_SECURITY_DOMAIN:
  case CKA_KEY_TYPE:
  case CKA_MECHANISM_TYPE:
  case CKA_MODULUS_BITS:
  case CKA_OTP_CHALLENGE_REQUIREMENT:
  case CKA_OTP_COUNTER_REQUIREMENT:
  case CKA_OTP_FORMAT:
  case CKA_OTP_LENGTH:
  case CKA_OTP_PIN_REQUIREMENT:
  case CKA_OTP_TIME_INTERVAL:
  case CKA_OTP_TIME_REQUIREMENT:
  case CKA_OTP_SERVICE_LOGO_TYPE:
  case CKA_PIXEL_X:
  case CKA_PIXEL_Y:
  case CKA_PRIME_BITS:
  case CKA_RESOLUTION:
  case CKA_SUBPRIME_BITS:
  case CKA_VALUE_BITS:
  case CKA_VALUE_LEN:
  if (attr->ulValueLen == sizeof(CK_ULONG))
      return ULONG2NUM(*(CK_ULONG_PTR)(attr->pValue));
    break;
  }
  return rb_str_new(attr->pValue, attr->ulValueLen);
}
Also aliased as: value
values() click to toggle source

@return [Array<String, Boolean, Integer>] attribute values

# File lib/pkcs11/extensions.rb, line 52
def values
  members.inject([]){|a,v| a << send(v) }
end