Skip to content

Commit ccb6c27

Browse files
author
Dominikus Gierlach
committed
fix formatting, add tests for init_pin
1 parent edbd164 commit ccb6c27

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkcs11/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,9 @@ def set_pin(self, old_pin, new_pin):
577577

578578
def init_pin(self, pin):
579579
"""
580-
Initializes the user PIN.
580+
Initializes the user PIN.
581581
582-
Differs from set_pin in that it sets the user PIN for the first time.
582+
Differs from set_pin in that it sets the user PIN for the first time.
583583
Once set, the pin can be changed using set_pin.
584584
"""
585585
raise NotImplementedError()

tests/test_sessions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
PKCS#11 Sessions
33
"""
4+
45
import pkcs11
56
from pkcs11 import (
67
Attribute,
@@ -318,3 +319,25 @@ def test_set_pin(self):
318319
session.set_pin(old_token_pin, "")
319320
with self.assertRaises(PinIncorrect):
320321
session.set_pin("", new_token_pin)
322+
323+
@Only.softhsm2
324+
def test_init_pin(self):
325+
new_token_pin = f"{TOKEN_PIN}56"
326+
327+
with self.token.open(rw=True, so_pin=TOKEN_SO_PIN) as session:
328+
session.init_pin(new_token_pin)
329+
330+
with self.token.open(rw=True, user_pin=new_token_pin) as session:
331+
self.assertIsInstance(session, pkcs11.Session)
332+
333+
with self.token.open(rw=True, so_pin=TOKEN_SO_PIN) as session:
334+
session.init_pin(TOKEN_PIN)
335+
336+
with self.token.open(rw=True, user_pin=TOKEN_PIN) as session:
337+
self.assertIsInstance(session, pkcs11.Session)
338+
339+
with self.token.open(rw=True, so_pin=TOKEN_SO_PIN) as session:
340+
with self.assertRaises(AttributeError):
341+
session.init_pin(None)
342+
with self.assertRaises(PinLenRange):
343+
session.init_pin("")

0 commit comments

Comments
 (0)