Changed the "serializer" property to private in the DigestAuth class.

This commit is contained in:
依瑪貓 2022-12-06 23:14:32 +08:00
parent 7ec56ee52d
commit 6e6ac8bbe7

View File

@ -41,7 +41,7 @@ class DigestAuth:
:param realm: The realm. :param realm: The realm.
""" """
self.serializer: URLSafeTimedSerializer \ self.__serializer: URLSafeTimedSerializer \
= URLSafeTimedSerializer(token_urlsafe(32)) = URLSafeTimedSerializer(token_urlsafe(32))
self.realm: str = "" if realm is None else realm self.realm: str = "" if realm is None else realm
self.algorithm: t.Optional[str] = None self.algorithm: t.Optional[str] = None
@ -152,7 +152,7 @@ class DigestAuth:
raise UnauthorizedException( raise UnauthorizedException(
"Missing \"opaque\" in the Authorization header") "Missing \"opaque\" in the Authorization header")
try: try:
self.serializer.loads( self.__serializer.loads(
authorization.opaque, salt="opaque", max_age=1800) authorization.opaque, salt="opaque", max_age=1800)
except BadData: except BadData:
raise UnauthorizedException("Invalid opaque") raise UnauthorizedException("Invalid opaque")
@ -173,7 +173,7 @@ class DigestAuth:
state.stale = False state.stale = False
raise UnauthorizedException("Incorrect response value") raise UnauthorizedException("Incorrect response value")
try: try:
self.serializer.loads( self.__serializer.loads(
authorization.nonce, authorization.nonce,
salt="nonce" if authorization.opaque is None salt="nonce" if authorization.opaque is None
else f"nonce-{authorization.opaque}") else f"nonce-{authorization.opaque}")
@ -197,10 +197,10 @@ class DigestAuth:
return None return None
if state.opaque is not None: if state.opaque is not None:
return state.opaque return state.opaque
return self.serializer.dumps(randbits(32), salt="opaque") return self.__serializer.dumps(randbits(32), salt="opaque")
opaque: t.Optional[str] = get_opaque() opaque: t.Optional[str] = get_opaque()
nonce: str = self.serializer.dumps( nonce: str = self.__serializer.dumps(
randbits(32), randbits(32),
salt="nonce" if opaque is None else f"nonce-{opaque}") salt="nonce" if opaque is None else f"nonce-{opaque}")