pkcs11 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  #include "pk11_thread_funcs.h"
2
- #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
3
2
  void * tbf_C_Initialize( void *data ){
4
3
  struct tbr_C_Initialize_params *p = (struct tbr_C_Initialize_params*)data;
5
4
  p->retval = p->func( p->params.pInitArgs );
@@ -408,4 +407,3 @@
408
407
  return NULL;
409
408
  }
410
409
 
411
- #endif
@@ -1,7 +1,6 @@
1
1
  #ifndef EXT_PK11_THREAD_FUNCS_H
2
2
  #define EXT_PK11_THREAD_FUNCS_H
3
3
  #include "pk11.h"
4
- #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
5
4
  struct tbr_C_Initialize_params {
6
5
  CK_C_Initialize func;
7
6
  struct { CK_VOID_PTR pInitArgs; } params;
@@ -479,4 +478,3 @@
479
478
  void * tbf_C_WaitForSlotEvent( void *data );
480
479
 
481
480
  #endif
482
- #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef RUBY_PK11_VERSION_H
2
2
  #define RUBY_PK11_VERSION_H
3
3
 
4
- static const char *VERSION = "0.2.7";
4
+ static const char *VERSION = "0.3.0";
5
5
 
6
6
  #endif
@@ -84,7 +84,7 @@ module PKCS11
84
84
  # Modifies the value of one or more attributes of the object in a single call.
85
85
  #
86
86
  # @example
87
- # object.attributes = {:SUBJECT => cert_subject, PKCS11::CKA_VALUE => cert_data}
87
+ # object.attributes = {SUBJECT: cert_subject, PKCS11::CKA_VALUE => cert_data}
88
88
  # @return template
89
89
  def C_SetAttributeValue(template={})
90
90
  @pk.C_SetAttributeValue(@sess, @obj, to_attributes(template))
@@ -109,7 +109,7 @@ module PKCS11
109
109
  # @return [Array<PKCS11::Object>]
110
110
  #
111
111
  # @example prints subject of all certificates stored in the token:
112
- # session.find_objects(:CLASS => PKCS11::CKO_CERTIFICATE) do |obj|
112
+ # session.find_objects(CLASS: PKCS11::CKO_CERTIFICATE) do |obj|
113
113
  # p OpenSSL::X509::Name.new(obj[:SUBJECT])
114
114
  # end
115
115
  def find_objects(template={})
@@ -146,9 +146,9 @@ module PKCS11
146
146
  # @return [PKCS11::Object] the newly created object
147
147
  # @example Creating a 112 bit DES key from plaintext
148
148
  # secret_key = session.create_object(
149
- # :CLASS=>PKCS11::CKO_SECRET_KEY, :KEY_TYPE=>PKCS11::CKK_DES2,
150
- # :ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true,
151
- # :VALUE=>'0123456789abcdef', :LABEL=>'test_secret_key')
149
+ # CLASS: PKCS11::CKO_SECRET_KEY, KEY_TYPE: PKCS11::CKK_DES2,
150
+ # ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true,
151
+ # VALUE: '0123456789abcdef', LABEL: 'test_secret_key')
152
152
  def C_CreateObject(template={})
153
153
  handle = @pk.C_CreateObject(@sess, to_attributes(template))
154
154
  Object.new @pk, @sess, handle
@@ -302,12 +302,12 @@ module PKCS11
302
302
  #
303
303
  # @example for using single part operation
304
304
  # iv = "12345678"
305
- # cryptogram = session.encrypt( {:DES_CBC_PAD=>iv}, key, "block 1block 2" )
305
+ # cryptogram = session.encrypt( {DES_CBC_PAD: iv}, key, "block 1block 2" )
306
306
  #
307
307
  # @example for using multi part operation
308
308
  # iv = "12345678"
309
309
  # cryptogram = ''
310
- # cryptogram << session.encrypt( {:DES_CBC_PAD=>iv}, key ) do |cipher|
310
+ # cryptogram << session.encrypt( {DES_CBC_PAD: iv}, key ) do |cipher|
311
311
  # cryptogram << cipher.update("block 1")
312
312
  # cryptogram << cipher.update("block 2")
313
313
  # end
@@ -649,7 +649,7 @@ module PKCS11
649
649
  # @return [PKCS11::Object] key Object of the new created key.
650
650
  # @example generate 112 bit DES key
651
651
  # key = session.generate_key(:DES2_KEY_GEN,
652
- # {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true})
652
+ # {ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true})
653
653
  def C_GenerateKey(mechanism, template={})
654
654
  obj = @pk.C_GenerateKey(@sess, to_mechanism(mechanism), to_attributes(template))
655
655
  Object.new @pk, @sess, obj
@@ -664,8 +664,8 @@ module PKCS11
664
664
  # @return [Array<PKCS11::Object>] an two-items array of new created public and private key Object.
665
665
  # @example
666
666
  # pub_key, priv_key = session.generate_key_pair(:RSA_PKCS_KEY_PAIR_GEN,
667
- # {:ENCRYPT=>true, :VERIFY=>true, :WRAP=>true, :MODULUS_BITS=>768, :PUBLIC_EXPONENT=>3},
668
- # {:SUBJECT=>'test', :ID=>"ID", :DECRYPT=>true, :SIGN=>true, :UNWRAP=>true})
667
+ # {ENCRYPT: true, VERIFY: true, WRAP: true, MODULUS_BITS: 768, PUBLIC_EXPONENT: 3},
668
+ # {SUBJECT: 'test', ID: "ID", DECRYPT: true, SIGN: true, UNWRAP: true})
669
669
  def C_GenerateKeyPair(mechanism, pubkey_template={}, privkey_template={})
670
670
  objs = @pk.C_GenerateKeyPair(@sess, to_mechanism(mechanism), to_attributes(pubkey_template), to_attributes(privkey_template))
671
671
  objs.map{|obj| Object.new @pk, @sess, obj }
@@ -682,7 +682,7 @@ module PKCS11
682
682
  # @example Wrapping a secret key
683
683
  # wrapped_key_value = session.wrap_key(:DES3_ECB, secret_key, secret_key)
684
684
  # @example Wrapping a private key
685
- # wrapped_key_value = session.wrap_key({:DES3_CBC_PAD=>"\0"*8}, secret_key, rsa_priv_key)
685
+ # wrapped_key_value = session.wrap_key({DES3_CBC_PAD: "\0"*8}, secret_key, rsa_priv_key)
686
686
  def C_WrapKey(mechanism, wrapping_key, wrapped_key, out_size=nil)
687
687
  @pk.C_WrapKey(@sess, to_mechanism(mechanism), wrapping_key, wrapped_key, out_size)
688
688
  end
@@ -698,7 +698,7 @@ module PKCS11
698
698
  # @see Session#C_WrapKey
699
699
  # @example
700
700
  # unwrapped_key = session.unwrap_key(:DES3_ECB, secret_key, wrapped_key_value,
701
- # :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_DES2, :ENCRYPT=>true, :DECRYPT=>true)
701
+ # CLASS: CKO_SECRET_KEY, KEY_TYPE: CKK_DES2, ENCRYPT: true, DECRYPT: true)
702
702
  def C_UnwrapKey(mechanism, wrapping_key, wrapped_key, template={})
703
703
  obj = @pk.C_UnwrapKey(@sess, to_mechanism(mechanism), wrapping_key, wrapped_key, to_attributes(template))
704
704
  Object.new @pk, @sess, obj
@@ -713,8 +713,8 @@ module PKCS11
713
713
  # @return [PKCS11::Object] key object of the new created key.
714
714
  # @example Derive a AES key by XORing with some derivation data
715
715
  # deriv_data = "\0"*16
716
- # new_key = session.derive_key( {CKM_XOR_BASE_AND_DATA => {:pData => deriv_data}}, secret_key,
717
- # :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true )
716
+ # new_key = session.derive_key( {CKM_XOR_BASE_AND_DATA => {pData: deriv_data}}, secret_key,
717
+ # CLASS: CKO_SECRET_KEY, KEY_TYPE: CKK_AES, VALUE_LEN: 16, ENCRYPT: true )
718
718
  def C_DeriveKey(mechanism, base_key, template={})
719
719
  obj = @pk.C_DeriveKey(@sess, to_mechanism(mechanism), base_key, to_attributes(template))
720
720
  Object.new @pk, @sess, obj
@@ -1,8 +1,8 @@
1
1
  = PKCS #11/Ruby Interface for Safenet Luna HSM
2
2
 
3
- * Homepage: http://github.com/larskanis/pkcs11
4
- * API documentation: http://pkcs11.rubyforge.org/pkcs11/
5
- * Safenet[http://www.safenet-inc.com] - Luna HSM
3
+ home :: http://github.com/larskanis/pkcs11
4
+ API documentation :: http://pkcs11.rubyforge.org/pkcs11/
5
+ Safenet Luna HSM :: http://www.safenet-inc.com
6
6
 
7
7
  This ruby gem is an add-on to ruby-pkcs11[http://github.com/larskanis/pkcs11] .
8
8
  It allows to use Luna specific extensions, which are beyond the PKCS#11 standard.
@@ -1,8 +1,8 @@
1
1
  = PKCS #11/Ruby Interface for Safenet Protect Server HSM
2
2
 
3
- * Homepage: http://github.com/larskanis/pkcs11
4
- * API documentation: http://pkcs11.rubyforge.org/pkcs11/
5
- * Safenet[http://www.safenet-inc.com] - Protect Server HSM
3
+ home :: http://github.com/larskanis/pkcs11
4
+ API documentation: http://pkcs11.rubyforge.org/pkcs11/
5
+ Safenet Protect Server HSM : http://www.safenet-inc.com
6
6
 
7
7
  This ruby gem is an add-on to ruby-pkcs11[http://github.com/larskanis/pkcs11] .
8
8
  It allowes to use Protect Server specific extensions, which are beyond the PKCS#11 standard.
@@ -59,7 +59,7 @@ def open_softokn(so_path=nil)
59
59
  $stderr.puts "Using #{so} with params #{softokn_params_string.inspect}"
60
60
  $first_open = false
61
61
  end
62
- PKCS11.open(so, :flags=>0, :pReserved=>softokn_params_string)
62
+ PKCS11.open(so, flags: 0, pReserved: softokn_params_string)
63
63
  end
64
64
 
65
65
  $pkcs11 = nil
@@ -61,7 +61,7 @@ class TestPkcs11 < Minitest::Test
61
61
  pk = PKCS11.open
62
62
  pk.load_library(find_softokn)
63
63
  pk.C_GetFunctionList
64
- pk.C_Initialize(:flags=>0, :pReserved=>softokn_params_string)
64
+ pk.C_Initialize(flags: 0, pReserved: softokn_params_string)
65
65
  pk.info
66
66
  pk.close
67
67
  end
@@ -20,16 +20,16 @@ class TestPkcs11Crypt < Minitest::Test
20
20
  @session = slot.open
21
21
  # session.login(:USER, "")
22
22
 
23
- @rsa_pub_key = session.find_objects(:CLASS => CKO_PUBLIC_KEY,
24
- :KEY_TYPE => CKK_RSA).first
25
- @rsa_priv_key = session.find_objects(:CLASS => CKO_PRIVATE_KEY,
26
- :KEY_TYPE => CKK_RSA).first
23
+ @rsa_pub_key = session.find_objects(CLASS: CKO_PUBLIC_KEY,
24
+ KEY_TYPE: CKK_RSA).first
25
+ @rsa_priv_key = session.find_objects(CLASS: CKO_PRIVATE_KEY,
26
+ KEY_TYPE: CKK_RSA).first
27
27
  @secret_key = session.create_object(
28
- :CLASS=>CKO_SECRET_KEY,
29
- :KEY_TYPE=>CKK_DES2,
30
- :ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false,
31
- :VALUE=>'0123456789abcdef',
32
- :LABEL=>'test_secret_key')
28
+ CLASS: CKO_SECRET_KEY,
29
+ KEY_TYPE: CKK_DES2,
30
+ ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true, TOKEN: false,
31
+ VALUE: '0123456789abcdef',
32
+ LABEL: 'test_secret_key')
33
33
  end
34
34
 
35
35
  def teardown
@@ -54,18 +54,18 @@ class TestPkcs11Crypt < Minitest::Test
54
54
 
55
55
  def test_endecrypt_des
56
56
  plaintext1 = "secret message "
57
- cryptogram = session.encrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key, plaintext1)
57
+ cryptogram = session.encrypt( {DES3_CBC_PAD: "\0"*8}, secret_key, plaintext1)
58
58
  assert_equal 16, cryptogram.length, 'The cryptogram should contain some data'
59
59
  refute_equal cryptogram, plaintext1, 'The cryptogram should be different to plaintext'
60
60
 
61
61
  cryptogram2 = ''
62
- cryptogram2 << session.encrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key ) do |cipher|
62
+ cryptogram2 << session.encrypt( {DES3_CBC_PAD: "\0"*8}, secret_key ) do |cipher|
63
63
  cryptogram2 << cipher.update(plaintext1[0, 8])
64
64
  cryptogram2 << cipher.update(plaintext1[8..-1])
65
65
  end
66
66
  assert_equal cryptogram, cryptogram2, "Encrypt with and w/o block should be lead to the same result"
67
67
 
68
- plaintext2 = session.decrypt( {:DES3_CBC_PAD=>"\0"*8}, secret_key, cryptogram)
68
+ plaintext2 = session.decrypt( {DES3_CBC_PAD: "\0"*8}, secret_key, cryptogram)
69
69
  assert_equal plaintext1, plaintext2, 'Decrypted plaintext should be the same'
70
70
  end
71
71
 
@@ -139,7 +139,7 @@ class TestPkcs11Crypt < Minitest::Test
139
139
  wrapped_key_value = session.wrap_key(:DES3_ECB, secret_key, secret_key)
140
140
  assert_equal 16, wrapped_key_value.length, '112 bit 3DES key should have same size wrapped'
141
141
 
142
- unwrapped_key = session.unwrap_key(:DES3_ECB, secret_key, wrapped_key_value, :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_DES2, :ENCRYPT=>true, :DECRYPT=>true)
142
+ unwrapped_key = session.unwrap_key(:DES3_ECB, secret_key, wrapped_key_value, CLASS: CKO_SECRET_KEY, KEY_TYPE: CKK_DES2, ENCRYPT: true, DECRYPT: true)
143
143
 
144
144
  secret_key_kcv = session.encrypt( :DES3_ECB, secret_key, "\0"*8)
145
145
  unwrapped_key_kcv = session.encrypt( :DES3_ECB, unwrapped_key, "\0"*8)
@@ -147,30 +147,30 @@ class TestPkcs11Crypt < Minitest::Test
147
147
  end
148
148
 
149
149
  def test_wrap_private_key
150
- wrapped_key_value = session.wrap_key({:DES3_CBC_PAD=>"\0"*8}, secret_key, rsa_priv_key)
150
+ wrapped_key_value = session.wrap_key({DES3_CBC_PAD: "\0"*8}, secret_key, rsa_priv_key)
151
151
  assert wrapped_key_value.length>100, 'RSA private key should have bigger size wrapped'
152
152
  end
153
153
 
154
154
  def test_generate_secret_key
155
155
  key = session.generate_key(:DES2_KEY_GEN,
156
- {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
156
+ {ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true, TOKEN: false, LOCAL: true})
157
157
  assert_equal true, key[:LOCAL], 'Keys created on the token should be marked as local'
158
158
  assert_equal CKK_DES2, key[:KEY_TYPE], 'Should be a 2 key 3des key'
159
159
 
160
160
  # other ways to use mechanisms
161
161
  key = session.generate_key(CKM_DES2_KEY_GEN,
162
- {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
162
+ {ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true, TOKEN: false, LOCAL: true})
163
163
  assert_equal CKK_DES2, key[:KEY_TYPE], 'Should be a 2 key 3des key'
164
164
  key = session.generate_key(CK_MECHANISM.new(CKM_DES2_KEY_GEN, nil),
165
- {:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
165
+ {ENCRYPT: true, WRAP: true, DECRYPT: true, UNWRAP: true, TOKEN: false, LOCAL: true})
166
166
  assert_equal CKK_DES2, key[:KEY_TYPE], 'Should be a 2 key 3des key'
167
167
  end
168
168
 
169
169
  def test_generate_key_pair
170
170
  pub_key, priv_key = session.generate_key_pair(:RSA_PKCS_KEY_PAIR_GEN,
171
- {:ENCRYPT=>true, :VERIFY=>true, :WRAP=>true, :MODULUS_BITS=>768, :PUBLIC_EXPONENT=>[3].pack("N"), :TOKEN=>false},
172
- {:PRIVATE=>true, :SUBJECT=>'test', :ID=>[123].pack("n"),
173
- :SENSITIVE=>true, :DECRYPT=>true, :SIGN=>true, :UNWRAP=>true, :TOKEN=>false, :LOCAL=>true})
171
+ {ENCRYPT: true, VERIFY: true, WRAP: true, MODULUS_BITS: 768, PUBLIC_EXPONENT: [65537].pack("N"), TOKEN: false},
172
+ {PRIVATE: true, SUBJECT: 'test', ID: [123].pack("n"),
173
+ SENSITIVE: true, DECRYPT: true, SIGN: true, UNWRAP: true, TOKEN: false, LOCAL: true})
174
174
 
175
175
  assert_equal true, priv_key[:LOCAL], 'Private keys created on the token should be marked as local'
176
176
  assert_equal priv_key[:CLASS], CKO_PRIVATE_KEY
@@ -184,15 +184,15 @@ class TestPkcs11Crypt < Minitest::Test
184
184
 
185
185
  # Generate key side 2 with same prime and base as side 1
186
186
  pub_key2, priv_key2 = session.generate_key_pair(:DH_PKCS_KEY_PAIR_GEN,
187
- {:PRIME=>key1.p.to_s(2), :BASE=>key1.g.to_s(2), :TOKEN=>false},
188
- {:VALUE_BITS=>512, :DERIVE=>true, :TOKEN=>false})
187
+ {PRIME: key1.p.to_s(2), BASE: key1.g.to_s(2), TOKEN: false},
188
+ {VALUE_BITS: 512, DERIVE: true, TOKEN: false})
189
189
 
190
190
  # Derive secret DES key for side 1 with OpenSSL
191
191
  new_key1 = key1.compute_key(OpenSSL::BN.new pub_key2[:VALUE], 2)
192
192
 
193
193
  # Derive secret DES key for side 2 with softokn3
194
- new_key2 = session.derive_key( {:DH_PKCS_DERIVE=>key1.pub_key.to_s(2)}, priv_key2,
195
- :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true, :DECRYPT=>true, :SENSITIVE=>false )
194
+ new_key2 = session.derive_key( {DH_PKCS_DERIVE: key1.pub_key.to_s(2)}, priv_key2,
195
+ CLASS: CKO_SECRET_KEY, KEY_TYPE: CKK_AES, VALUE_LEN: 16, ENCRYPT: true, DECRYPT: true, SENSITIVE: false )
196
196
 
197
197
  # Some versions of softokn3 use left- and some use rightmost bits of exchanged key
198
198
  assert_operator [new_key1[0,16], new_key1[-16..-1]], :include?, new_key2[:VALUE], 'Exchanged session key should be equal'
@@ -200,15 +200,15 @@ class TestPkcs11Crypt < Minitest::Test
200
200
 
201
201
  def test_derive_key2
202
202
  deriv_data = "\0"*16
203
- new_key1 = session.derive_key( {CKM_XOR_BASE_AND_DATA => {:pData => deriv_data}}, secret_key,
204
- :CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true, :DECRYPT=>true, :SENSITIVE=>false )
203
+ new_key1 = session.derive_key( {CKM_XOR_BASE_AND_DATA => {pData: deriv_data}}, secret_key,
204
+ CLASS: CKO_SECRET_KEY, KEY_TYPE: CKK_AES, VALUE_LEN: 16, ENCRYPT: true, DECRYPT: true, SENSITIVE: false )
205
205
 
206
206
  assert_equal secret_key[:VALUE], new_key1[:VALUE], 'Derived key should have equal key value'
207
207
  end
208
208
 
209
209
  def test_ssl3
210
- pm_key = session.generate_key({:SSL3_PRE_MASTER_KEY_GEN => {:major=>3, :minor=>0}},
211
- {:TOKEN=>false})
210
+ pm_key = session.generate_key({SSL3_PRE_MASTER_KEY_GEN: {major: 3, minor: 0}},
211
+ {TOKEN: false})
212
212
  assert_equal 48, pm_key[:VALUE_LEN], "SSL3 pre master key should be 48 bytes long"
213
213
 
214
214
  dp = CK_SSL3_MASTER_KEY_DERIVE_PARAMS.new
@@ -21,10 +21,10 @@ class TestPkcs11Object < Minitest::Test
21
21
 
22
22
  # Create session object for tests.
23
23
  @object = session.create_object(
24
- :CLASS=>CKO_DATA,
25
- :TOKEN=>false,
26
- :APPLICATION=>'My Application',
27
- :VALUE=>'value')
24
+ CLASS: CKO_DATA,
25
+ TOKEN: false,
26
+ APPLICATION: 'My Application',
27
+ VALUE: 'value')
28
28
  end
29
29
 
30
30
  def teardown
@@ -42,7 +42,7 @@ class TestPkcs11Object < Minitest::Test
42
42
  assert_equal CKO_DATA, object.attributes(:CLASS).first.value, 'Resulting attribute should be Integer value CKO_DATA'
43
43
  assert_equal 3, object.attributes(:VALUE, :TOKEN, :PRIVATE).length, 'An object should have some attributes'
44
44
  assert_equal 3, object.attributes([:VALUE, :TOKEN, :APPLICATION]).length, 'Another way to retieve attributes'
45
- assert_equal 2, object.attributes(:VALUE=>nil, :TOKEN=>nil).length, 'Third way to retieve attributes'
45
+ assert_equal 2, object.attributes(VALUE: nil, TOKEN: nil).length, 'Third way to retieve attributes'
46
46
 
47
47
  # The C language way to retrieve the attribute values:
48
48
  template = [
@@ -59,6 +59,9 @@ class TestPkcs11Object < Minitest::Test
59
59
 
60
60
  def test_accessor
61
61
  assert_equal 'value', object[:VALUE], "Value should be readable"
62
+ assert_equal Encoding::BINARY, object[:VALUE].encoding
63
+ assert_equal 'My Application', object[:APPLICATION]
64
+ assert_equal Encoding::UTF_8, object[:APPLICATION].encoding
62
65
  assert_equal CKO_DATA, object[:CLASS], "Class should be readable"
63
66
  assert_equal ['value', CKO_DATA], object[:VALUE, :CLASS], "multiple values should be readable"
64
67
  assert_equal ['value', CKO_DATA], object[[:VALUE, :CLASS]], "multiple values should be readable"
@@ -80,15 +83,15 @@ class TestPkcs11Object < Minitest::Test
80
83
  end
81
84
 
82
85
  def test_set_attributes
83
- object.attributes = {:VALUE => 'value4', PKCS11::CKA_APPLICATION => 'app4'}
86
+ object.attributes = {VALUE: 'value4', PKCS11::CKA_APPLICATION => 'Äpp4'}
84
87
  assert_equal 'value4', object[:VALUE], "Value should have changed"
85
- assert_equal 'app4', object[:APPLICATION], "App should have changed"
88
+ assert_equal 'Äpp4', object[:APPLICATION], "App should have changed"
86
89
 
87
- object[:VALUE, PKCS11::CKA_APPLICATION] = 'value5', 'app5'
90
+ object[:VALUE, PKCS11::CKA_APPLICATION] = 'value5', 'äpp5'
88
91
  assert_equal 'value5', object[:VALUE], "Value should have changed"
89
- assert_equal 'app5', object[:APPLICATION], "App should have changed"
92
+ assert_equal 'äpp5', object[:APPLICATION], "App should have changed"
90
93
  assert_raises(ArgumentError) do
91
- object[:VALUE, PKCS11::CKA_APPLICATION, :CLASS] = 'value5', 'app5'
94
+ object[:VALUE, PKCS11::CKA_APPLICATION, :CLASS] = 'value5', 'äpp5'
92
95
  end
93
96
 
94
97
  object[] = []
@@ -106,7 +109,7 @@ class TestPkcs11Object < Minitest::Test
106
109
  end
107
110
 
108
111
  def test_copy_with_params
109
- new_obj = object.copy :APPLICATION=>'Copied object'
112
+ new_obj = object.copy APPLICATION: 'Copied object'
110
113
  assert_equal 'value', new_obj[:VALUE], "Value should be copied"
111
114
  assert_equal 'Copied object', new_obj[:APPLICATION], "Application should be changed"
112
115
  assert_equal 'My Application', object[:APPLICATION], "Original object should be unchanged"
@@ -32,11 +32,11 @@ class TestPkcs11Session < Minitest::Test
32
32
  end
33
33
 
34
34
  def test_find_objects
35
- obj = session.find_objects(:CLASS => CKO_CERTIFICATE)
35
+ obj = session.find_objects(CLASS: CKO_CERTIFICATE)
36
36
  assert obj.length>2, 'There should be some certificates in the test database'
37
37
  assert_equal PKCS11::Object, obj.first.class, 'Retuned objects should be class Object'
38
38
 
39
- session.find_objects(:CLASS => CKO_CERTIFICATE) do |obj2|
39
+ session.find_objects(CLASS: CKO_CERTIFICATE) do |obj2|
40
40
  assert obj2[:SUBJECT], 'A certificate should have a subject'
41
41
  assert OpenSSL::X509::Name.new(obj2[:SUBJECT]).to_s =~ /\/CN=/i, 'Every certificate should have a CN in the subject'
42
42
  end
@@ -57,25 +57,25 @@ class TestPkcs11Session < Minitest::Test
57
57
  end
58
58
 
59
59
  def test_create_data_object
60
- obj = session.create_object(
61
- :CLASS=>CKO_DATA,
62
- :TOKEN=>false,
63
- :APPLICATION=>'My Application',
64
- :VALUE=>'value')
60
+ _obj = session.create_object(
61
+ CLASS: CKO_DATA,
62
+ TOKEN: false,
63
+ APPLICATION: 'My Application',
64
+ VALUE: 'value')
65
65
  end
66
66
 
67
67
  def test_create_certificate_object
68
- obj1 = session.find_objects(:CLASS => CKO_CERTIFICATE, :ID=>TestCert_ID).first
68
+ obj1 = session.find_objects(CLASS: CKO_CERTIFICATE, ID: TestCert_ID).first
69
69
 
70
70
  obj = session.create_object(
71
- :CLASS=>CKO_CERTIFICATE,
72
- :SUBJECT=>obj1[:SUBJECT],
73
- :TOKEN=>false,
74
- :LABEL=>'test_create_object',
75
- :CERTIFICATE_TYPE=>CKC_X_509,
76
- :ISSUER=>obj1[:ISSUER],
77
- :VALUE=>obj1[:VALUE],
78
- :SERIAL_NUMBER=>'12345'
71
+ CLASS: CKO_CERTIFICATE,
72
+ SUBJECT: obj1[:SUBJECT],
73
+ TOKEN: false,
74
+ LABEL: 'test_create_object',
75
+ CERTIFICATE_TYPE: CKC_X_509,
76
+ ISSUER: obj1[:ISSUER],
77
+ VALUE: obj1[:VALUE],
78
+ SERIAL_NUMBER: '12345'
79
79
  )
80
80
 
81
81
  assert_equal '12345', obj[:SERIAL_NUMBER], 'Value as created'
@@ -85,12 +85,12 @@ class TestPkcs11Session < Minitest::Test
85
85
  rsa = OpenSSL::PKey::RSA.generate(512)
86
86
 
87
87
  obj = session.create_object(
88
- :CLASS=>CKO_PUBLIC_KEY,
89
- :KEY_TYPE=>CKK_RSA,
90
- :TOKEN=>false,
91
- :MODULUS=>rsa.n.to_s(2),
92
- :PUBLIC_EXPONENT=>rsa.e.to_s(2),
93
- :LABEL=>'test_create_public_key_object')
88
+ CLASS: CKO_PUBLIC_KEY,
89
+ KEY_TYPE: CKK_RSA,
90
+ TOKEN: false,
91
+ MODULUS: rsa.n.to_s(2),
92
+ PUBLIC_EXPONENT: rsa.e.to_s(2),
93
+ LABEL: 'test_create_public_key_object')
94
94
 
95
95
  assert_equal 'test_create_public_key_object', obj[:LABEL], 'Value as created'
96
96
  end
@@ -71,7 +71,7 @@ class TestPkcs11Slot < Minitest::Test
71
71
 
72
72
  def test_session2
73
73
  flags = CKF_SERIAL_SESSION #| CKF_RW_SESSION
74
- session = slot.open(flags)
74
+ _session = slot.open(flags)
75
75
  slot.close_all_sessions
76
76
  end
77
77
  end