Skip to content

Commit

Permalink
do conversion of Hash to CK_C_INITIALIZE_ARGS in C_Initialize instead…
Browse files Browse the repository at this point in the history
… of PKCS11#initialize, so that Hash-version can be used on both methods
  • Loading branch information
larskanis committed Dec 20, 2011
1 parent f9e6969 commit 7f3fe7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/pkcs11/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions test/test_pkcs11.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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.