2015-12-19 17:08:34 +00:00
|
|
|
import enum
|
|
|
|
import collections
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
2015-12-19 17:08:34 +00:00
|
|
|
@enum.unique
|
|
|
|
class Mechanisms(enum.Enum):
|
2015-12-20 12:47:30 +00:00
|
|
|
"""Enumeration for representing possible mechanisms."""
|
2021-02-22 18:02:13 +00:00
|
|
|
|
2015-12-19 17:08:34 +00:00
|
|
|
@classmethod
|
|
|
|
def as_string(cls, mech):
|
2021-02-22 18:02:13 +00:00
|
|
|
return {
|
|
|
|
cls.plain: "PLAIN",
|
|
|
|
cls.ecdsa_nist256p_challenge: "ECDSA-NIST256P-CHALLENGE",
|
|
|
|
cls.scram_sha_256: "SCRAM-SHA-256",
|
|
|
|
}[mech]
|
|
|
|
|
2015-12-19 17:08:34 +00:00
|
|
|
plain = 1
|
2015-12-20 01:59:17 +00:00
|
|
|
ecdsa_nist256p_challenge = 2
|
2017-01-10 23:07:25 +00:00
|
|
|
scram_sha_256 = 3
|
2015-12-19 17:08:34 +00:00
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
|
|
|
Authentication = collections.namedtuple(
|
|
|
|
"Authentication", "mechanisms username password ecdsa_key"
|
|
|
|
)
|
2015-12-19 17:08:34 +00:00
|
|
|
Authentication.__new__.__defaults__ = ([Mechanisms.plain], None, None, None)
|