# -*- coding: utf-8 -*-
"""
Module containing all exceptions that Cryptnox SDK Python module can raise.
"""
[docs]
class CryptnoxException(Exception):
"""Base exception for the class exceptions."""
[docs]
class CardClosedException(Exception):
"""The card wasn't opened with PIN code or challenge-response"""
[docs]
class CardException(CryptnoxException):
"""No card was detected in the card reader."""
[docs]
class CardTypeException(CryptnoxException):
"""The detected card is not supported by this library"""
[docs]
class CertificateException(CryptnoxException):
"""There was an issue with the certification"""
[docs]
class ConnectionException(CryptnoxException):
"""An issue occurred in the communication with the reader"""
[docs]
class DataException(CryptnoxException):
"""The reader returned an empty message."""
[docs]
class DataValidationException(CryptnoxException):
"""The sent data is not valid."""
[docs]
class DerivationSelectionException(CryptnoxException):
"""Not a valid derivation selection."""
[docs]
class KeySelectionException(CryptnoxException):
"""Not a valid key type selection"""
[docs]
class EOSKeyError(CryptnoxException):
"""The signature wasn't compatible with EOS standard after 10 tries"""
[docs]
class FirmwareException(CryptnoxException):
"""There is an issue with the firmware on the card"""
[docs]
class GenuineCheckException(CryptnoxException):
"""The detected card is not a genuine Cryptnox product."""
[docs]
class GenericException(CryptnoxException):
"""
Generic exception that can mean multiple things depending on the call to the card
Process stats and throw a specific Exception from it.
"""
[docs]
def __init__(self, status: bytes):
self.status = status
[docs]
class InitializationException(CryptnoxException):
"""The card hasn't been initialized."""
[docs]
class KeyAlreadyGenerated(CryptnoxException):
"""Key can not be generated twice."""
[docs]
class SeedException(CryptnoxException):
"""Keys weren't found on the card."""
[docs]
class KeyGenerationException(CryptnoxException):
"""Error in key generation."""
[docs]
class PinAuthenticationException(CryptnoxException):
"""Error in turning off PIN authentication. There is no user key in the card"""
[docs]
class PinBlockedException(CryptnoxException):
"""PIN is fully blocked (0 retries remaining). Unblock the card before attempting this operation."""
[docs]
class PinException(CryptnoxException):
"""
Sent PIN code is not valid.
:param int number_of_retries: Number of retries to send the PIN code
before the card is locked.
:param str message: Optional message
"""
[docs]
def __init__(self, message: str = "Invalid PIN code was provided", number_of_retries: int = 0):
super().__init__(message)
self.number_of_retries = number_of_retries
[docs]
class PukException(CryptnoxException):
"""
Sent PUK code is not valid.
:param int number_of_retries: Number of retries to send the PIN code
before the card is locked.
:param str message: Optional message
"""
[docs]
def __init__(self, message: str = "Invalid PUK code was provided", number_of_retries: int = 0):
super().__init__(message)
self.number_of_retries = number_of_retries
[docs]
class ReadPublicKeyException(CryptnoxException):
"""Data received during public key reading is not valid."""
[docs]
class ReaderException(CryptnoxException):
"""Card reader wasn't found attached to the device."""
[docs]
class SecureChannelException(CryptnoxException):
"""Secure channel couldn't be established."""
[docs]
class SoftLock(CryptnoxException):
"""The card is soft locked, and requires power cycle before it can be opened"""
[docs]
class CardNotBlocked(CryptnoxException):
"""Trying to unlock unblocked card"""