Permalink
Browse files

do conversion of Hash to CK_C_INITIALIZE_ARGS in C_Initialize instead…

… of PKCS11#initialize, so that Hash-version can be used on both methods
  • Loading branch information...
1 parent f9e6969 commit 7f3fe7d1454582748fefc155f1da03b2e3575ed4 @larskanis committed Dec 20, 2011
Showing with 25 additions and 7 deletions.
  1. +6 −1 lib/pkcs11/library.rb
  2. +19 −6 test/test_pkcs11.rb
View
@@ -35,14 +35,19 @@ class Library
# pkcs11.C_GetFunctionList
# pkcs11.C_Initialize(args)
def initialize(so_path=nil, args={})
+ unwrapped_initialize(so_path, args)
+ end
+
+ alias unwrapped_C_Initialize C_Initialize
+ def C_Initialize(args=nil)
case args
when Hash
pargs = CK_C_INITIALIZE_ARGS.new
args.each{|k,v| pargs.send("#{k}=", v) }
else
pargs = args
end
- unwrapped_initialize(so_path, pargs)
+ unwrapped_C_Initialize(pargs)
end
alias unwrapped_C_GetInfo C_GetInfo
View
@@ -3,31 +3,34 @@
require "test/helper"
class TestPkcs11 < Test::Unit::TestCase
- def setup
+ attr_reader :pk
+
+ def open
@pk = open_softokn
end
- def teardown
+ def close
@pk.close
@pk = nil
GC.start
end
- def pk
- @pk
- end
-
def test_info
+ open
info = pk.info
assert info.inspect =~ /cryptokiVersion=/, 'There should be a version in the library info'
+ close
end
def test_slots
+ open
slots = pk.active_slots
assert slots.length>=1, 'Hope there is at least one active slot'
+ close
end
def test_close
+ open
pk.close
pk.unload_library
assert_raise(PKCS11::Error){ pk.info }
@@ -43,5 +46,15 @@ def test_close
pk.C_Initialize(pargs)
pk.info
+ close
+ end
+
+ def test_C_Initialize_with_Hash
+ pk = PKCS11.open
+ pk.load_library(find_softokn)
+ pk.C_GetFunctionList
+ pk.C_Initialize(:flags=>0, :pReserved=>softokn_params_string)
+ pk.info
+ pk.close
end
end

0 comments on commit 7f3fe7d

Please sign in to comment.