1# Copyright 2016 Google Inc. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Exceptions that can be raised by the pyu2f library. 16 17All exceptions that can be raised by the pyu2f library. Most of these 18are internal coditions, but U2FError and NoDeviceFoundError are public 19errors that clients should expect to handle. 20""" 21 22 23class NoDeviceFoundError(Exception): 24 pass 25 26 27class U2FError(Exception): 28 OK = 0 29 OTHER_ERROR = 1 30 BAD_REQUEST = 2 31 CONFIGURATION_UNSUPPORTED = 3 32 DEVICE_INELIGIBLE = 4 33 TIMEOUT = 5 34 35 def __init__(self, code, cause=None): 36 self.code = code 37 if cause: 38 self.cause = cause 39 super(U2FError, self).__init__("U2F Error code: %d (cause: %s)" % 40 (code, str(cause))) 41 42 43class HidError(Exception): 44 """Errors in the hid usb transport protocol.""" 45 pass 46 47 48class InvalidPacketError(HidError): 49 pass 50 51 52class HardwareError(Exception): 53 """Errors in the security key hardware that are transport independent.""" 54 pass 55 56 57class InvalidRequestError(HardwareError): 58 pass 59 60 61class ApduError(HardwareError): 62 63 def __init__(self, sw1, sw2): 64 self.sw1 = sw1 65 self.sw2 = sw2 66 super(ApduError, self).__init__("Device returned status: %d %d" % 67 (sw1, sw2)) 68 69 70class TUPRequiredError(HardwareError): 71 pass 72 73 74class InvalidKeyHandleError(HardwareError): 75 pass 76 77 78class UnsupportedVersionException(Exception): 79 pass 80 81 82class InvalidCommandError(Exception): 83 pass 84 85 86class InvalidResponseError(Exception): 87 pass 88 89 90class InvalidModelError(Exception): 91 pass 92 93 94class OsHidError(Exception): 95 pass 96 97 98class PluginError(Exception): 99 pass 100