codekingpro/portable-devtools
114k
1"""2All exceptions and warnings thrown by ``service-identity``.3 4Separated into an own package for nicer tracebacks, you should still import5them from __init__.py.6"""7 8from __future__ import annotations9 10from typing import TYPE_CHECKING, Sequence11 12 13if TYPE_CHECKING:14 from .hazmat import ServiceID15 16import attr17 18 19class SubjectAltNameWarning(DeprecationWarning):20 """21 This warning is not used anymore and will be removed in a future version.22 23 Formerly:24 25 Server Certificate does not contain a ``SubjectAltName``.26 27 Hostname matching is performed on the ``CommonName`` which is deprecated.28 29 .. deprecated:: 23.1.030 """31 32 33@attr.s(slots=True)34class Mismatch:35 mismatched_id: ServiceID = attr.ib()36 37 38class DNSMismatch(Mismatch):39 """40 No matching DNSPattern could be found.41 """42 43 44class SRVMismatch(Mismatch):45 """46 No matching SRVPattern could be found.47 """48 49 50class URIMismatch(Mismatch):51 """52 No matching URIPattern could be found.53 """54 55 56class IPAddressMismatch(Mismatch):57 """58 No matching IPAddressPattern could be found.59 """60 61 62@attr.s(auto_exc=True)63class VerificationError(Exception):64 """65 Service identity verification failed.66 """67 68 errors: Sequence[Mismatch] = attr.ib()69 70 def __str__(self) -> str:71 return self.__repr__()72 73 74class CertificateError(Exception):75 r"""76 Certificate contains invalid or unexpected data.77 78 This includes the case where s certificate contains no79 ``subjectAltName``\ s.80 """81 