Skip to content

Commit

Permalink
feat(error-handling): add Pkcs11TokenNotPresent, Pkcs11TokenRemoved, …
Browse files Browse the repository at this point in the history
…bring in libpcsc-cpp error handling changes

Signed-off-by: Mart Sõmermaa <[email protected]>
  • Loading branch information
mrts committed Apr 14, 2021
1 parent 9a81db0 commit e71d631
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
12 changes: 12 additions & 0 deletions include/electronic-id/electronic-id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ class Pkcs11Error : public Error
using Error::Error;
};

/** Smart card was not present in its slot at the time that a PKCS#11 function was invoked. */
class Pkcs11TokenNotPresent : public Error
{
using Error::Error;
};

/** Smart card was removed from its slot during the execution of a PKCS#11 function. */
class Pkcs11TokenRemoved : public Error
{
using Error::Error;
};

/** Communicates why auto-select failed to the caller. */
class AutoSelectFailed : public Error
{
Expand Down
9 changes: 7 additions & 2 deletions src/electronic-ids/pkcs11/PKCS11CardManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,13 @@ class PKCS11CardManager
std::string(apiFunction) + ": token not recognized", file, line,
function);
case CKR_TOKEN_NOT_PRESENT:
THROW_WITH_CALLER_INFO(Pkcs11Error, std::string(apiFunction) + ": token not present",
file, line, function);
THROW_WITH_CALLER_INFO(Pkcs11TokenNotPresent,
std::string(apiFunction) + ": token not present", file, line,
function);
case CKR_DEVICE_REMOVED:
THROW_WITH_CALLER_INFO(Pkcs11TokenRemoved,
std::string(apiFunction) + ": token was removed", file, line,
function);
default:
THROW_WITH_CALLER_INFO(Pkcs11Error,
std::string(apiFunction) + " failed with return code "
Expand Down

0 comments on commit e71d631

Please sign in to comment.