Ejemplo n.º 1
0
    def sign(self, pk, data, mechanism):
        if not _is_valid_mechanism(mechanism):
            raise PyKCS11Error('Mechanism is not valid.')
        if not isinstance(data, bytes):
            raise TypeError()

        return b'signature'
Ejemplo n.º 2
0
 def _mock_getSlotInfo(self, slot):
     if slot not in SLOT_IDS:
         raise PyKCS11Error(PyKCS11.CKR_SLOT_ID_INVALID)
     slot_info = PyKCS11.CK_SLOT_INFO()
     slot_info.slotDescription = "slot {!s} description".format(slot)
     return slot_info
Ejemplo n.º 3
0
 def _mock_openSession(self, slot):
     if slot not in SLOT_IDS:
         raise PyKCS11Error(PyKCS11.CKR_SLOT_ID_INVALID)
     return self.session_mock
Ejemplo n.º 4
0
 def _new_side_effect(*args, **kwargs):
     if store.failures > 0:
         store.failures -= 1
         raise PyKCS11Error(error)
     return old_side_effect(*args, **kwargs)
Ejemplo n.º 5
0
    def openSession(self, slot, flags=0):
        if not self._able_to_open_session:
            raise PyKCS11Error('Could not open a session.')

        return _Session(self._able_to_login)
Ejemplo n.º 6
0
 def logout(self):
     if not self.logged_in:
         raise PyKCS11Error('Could not logout.')
     self.logged_in = False
Ejemplo n.º 7
0
 def login(self, pin, user_type=None):
     if not self._able_to_login or pin != VALID_PIN:
         raise PyKCS11Error('Could not login.')
     self.logged_in = True