Class: PKCS11::CK_ATTRIBUTE

Inherits:
Object
  • Object
show all
Defined in:
lib/pkcs11/extensions.rb,
ext/pk11.c

Overview

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

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
# File 'ext/pk11.c', line 1345

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;
}

Instance Method Details

#inspectObject



64
65
66
# File 'lib/pkcs11/extensions.rb', line 64

def inspect
  "#<#{self.class} #{ to_s ? "#{to_s} (#{type})" : type} value=#{value.inspect}>"
end

#membersArray<String>

Returns attribute names.

Returns:

  • (Array<String>)

    attribute names



48
49
50
# File 'lib/pkcs11/extensions.rb', line 48

def members
  ['type', 'value']
end

#to_hashHash

Returns with attribute names and current values.

Returns:

  • (Hash)

    with attribute names and current values



56
57
58
# File 'lib/pkcs11/extensions.rb', line 56

def to_hash
  members.inject({}){|h,v| h[v.intern] = send(v); h }
end

#to_sString?

Get the constant name as String of the given value.

Returns:

  • (String, nil)

    Returns nil if value is unknown



61
62
63
# File 'lib/pkcs11/extensions.rb', line 61

def to_s
  ATTRIBUTES[type]
end

#typeInteger

Returns attribute type PKCS11::CKA_*.

Returns:

  • (Integer)

    attribute type PKCS11::CKA_*



1391
1392
1393
1394
1395
1396
1397
# File 'ext/pk11.c', line 1391

static VALUE
ck_attr_type(VALUE self)
{
  CK_ATTRIBUTE *attr;
  Data_Get_Struct(self, CK_ATTRIBUTE, attr);
  return ULONG2NUM(attr->type);
}

#valueString, ...

Returns attribute value.

Returns:

  • (String, Integer, Boolean)

    attribute value

See Also:



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
# File 'ext/pk11.c', line 1404

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;
  case CKA_LABEL:
  case CKA_APPLICATION:
  case CKA_URL:
  case CKA_CHAR_SETS:
  case CKA_ENCODING_METHODS:
  case CKA_MIME_TYPES:
    return rb_enc_str_new(attr->pValue, attr->ulValueLen, rb_utf8_encoding());
  }
  return rb_str_new(attr->pValue, attr->ulValueLen);
}

#valuesArray<String, Boolean, Integer>

Returns attribute values.

Returns:

  • (Array<String, Boolean, Integer>)

    attribute values



52
53
54
# File 'lib/pkcs11/extensions.rb', line 52

def values
  members.inject([]){|a,v| a << send(v) }
end