maybe_sasl() -> sasl_auth(SASLParms)

This commit is contained in:
jesopo 2020-04-03 09:49:46 +01:00
parent 8cc3db5e58
commit 2d93e27feb
3 changed files with 11 additions and 11 deletions

View file

@ -6,7 +6,7 @@ from ircstates import Server
from irctokens import Line
from .matching import BaseResponse
from .params import ConnectionParams
from .params import ConnectionParams, SASLParams
class SendPriority(IntEnum):
HIGH = 0
@ -63,5 +63,5 @@ class IServer(Server):
def collect_caps(self) -> List[str]:
pass
async def maybe_sasl(self) -> bool:
async def sasl_auth(self, sasl: SASLParams) -> bool:
pass

View file

@ -83,8 +83,9 @@ class CAPContext(ServerContext):
if cap in caps:
caps.remove(cap)
if self.server.cap_agreed(CAP_SASL):
await self.server.maybe_sasl()
if (self.server.cap_agreed(CAP_SASL) and
not self.server.params.sasl is None):
await self.server.sasl_auth(self.server.params.sasl)
await self.server.send(build("CAP", ["END"]))
return True

View file

@ -9,7 +9,7 @@ from irctokens import build, Line, tokenise
from .ircv3 import CAPContext, CAPS, CAP_SASL
from .interface import (ConnectionParams, ICapability, IServer, SentLine,
SendPriority)
SendPriority, SASLParams)
from .matching import BaseResponse
from .sasl import SASLContext, SASLResult
from .security import ssl_context
@ -143,17 +143,16 @@ class Server(IServer):
async def _cap_new(self, emit: Emit):
if not emit.tokens is None:
tokens = [t.split("=", 1)[0] for t in emit.tokens]
if CAP_SASL.available(tokens):
await self.maybe_sasl()
if CAP_SASL.available(tokens) and not self.params.sasl is None:
await self.sasl_auth(self.params.sasl)
async def maybe_sasl(self) -> bool:
async def sasl_auth(self, params: SASLParams) -> bool:
if (self.sasl_state == SASLResult.NONE and
not self.params.sasl is None and
self.cap_agreed(CAP_SASL)):
res = await SASLContext(self).from_params(self.params.sasl)
res = await SASLContext(self).from_params(params)
self.sasl_state = res
return True
else:
return False
# /CAP-related