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'
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
def _mock_openSession(self, slot): if slot not in SLOT_IDS: raise PyKCS11Error(PyKCS11.CKR_SLOT_ID_INVALID) return self.session_mock
def _new_side_effect(*args, **kwargs): if store.failures > 0: store.failures -= 1 raise PyKCS11Error(error) return old_side_effect(*args, **kwargs)
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)
def logout(self): if not self.logged_in: raise PyKCS11Error('Could not logout.') self.logged_in = False
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