Skip to content

Commit

Permalink
Sample events.py: add a -f/--full argument
Browse files Browse the repository at this point in the history
By default only the getSlotInfo() data are displayed.
This allows to be faster since getSessionInfo() and getTokenInfo() can
be slow.
  • Loading branch information
LudovicRousseau committed May 6, 2019
1 parent 76ccd87 commit 9ff9caa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions samples/events.py
Expand Up @@ -31,12 +31,13 @@ def usage():
print("[-c lib][--lib=lib]", end=" ")
print("[-h][--help]", end=" ")
print("[-o][--opensession]")
print("[-f][--full]")

try:
opts, args = getopt.getopt(
sys.argv[1:],
"p:c:hom",
["pin=", "lib=", "help", "opensession", "mechanisms"],
"p:c:homf",
["pin=", "lib=", "help", "opensession", "mechanisms", "full"],
)
except getopt.GetoptError:
# print help information and exit:
Expand All @@ -48,6 +49,7 @@ def usage():
open_session = False
pin_available = False
list_mechanisms = False
full = False
for o, a in opts:
if o in ("-h", "--help"):
usage()
Expand All @@ -64,6 +66,8 @@ def usage():
open_session = True
if o in ("-m", "--mechanisms"):
list_mechanisms = True
if o in ("-f", "--full"):
full = True

gi = getinfo.getInfo(lib)
gi.getInfo()
Expand All @@ -75,14 +79,16 @@ def usage():
sys.exit(2)

while True:
print("waiting...")
slot = gi.pkcs11.waitForSlotEvent()

try:
print("Slot %d changed" % slot)
gi.getSlotInfo(slot, 0, len(slots))
gi.getSessionInfo(slot, pin)
gi.getTokenInfo(slot)
if list_mechanisms:
gi.getMechanismInfo(slot)
if full:
gi.getSessionInfo(slot, pin)
gi.getTokenInfo(slot)
if list_mechanisms:
gi.getMechanismInfo(slot)
except PyKCS11.PyKCS11Error as e:
print("Error:", e)

0 comments on commit 9ff9caa

Please sign in to comment.