mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 02:05:00 -04:00
Run Black. (#5482)
This commit is contained in:
parent
7dcf984075
commit
32e7c9e7f2
376 changed files with 9142 additions and 10388 deletions
|
@ -42,6 +42,7 @@ logger = logging.getLogger(__name__)
|
|||
if hasattr(hmac, "compare_digest"):
|
||||
compare_digest = hmac.compare_digest
|
||||
else:
|
||||
|
||||
def compare_digest(a, b):
|
||||
return a == b
|
||||
|
||||
|
@ -80,6 +81,7 @@ class ConsentResource(Resource):
|
|||
For POST: required; gives the value to be recorded in the database
|
||||
against the user.
|
||||
"""
|
||||
|
||||
def __init__(self, hs):
|
||||
"""
|
||||
Args:
|
||||
|
@ -98,21 +100,20 @@ class ConsentResource(Resource):
|
|||
if self._default_consent_version is None:
|
||||
raise ConfigError(
|
||||
"Consent resource is enabled but user_consent section is "
|
||||
"missing in config file.",
|
||||
"missing in config file."
|
||||
)
|
||||
|
||||
consent_template_directory = hs.config.user_consent_template_dir
|
||||
|
||||
loader = jinja2.FileSystemLoader(consent_template_directory)
|
||||
self._jinja_env = jinja2.Environment(
|
||||
loader=loader,
|
||||
autoescape=jinja2.select_autoescape(['html', 'htm', 'xml']),
|
||||
loader=loader, autoescape=jinja2.select_autoescape(["html", "htm", "xml"])
|
||||
)
|
||||
|
||||
if hs.config.form_secret is None:
|
||||
raise ConfigError(
|
||||
"Consent resource is enabled but form_secret is not set in "
|
||||
"config file. It should be set to an arbitrary secret string.",
|
||||
"config file. It should be set to an arbitrary secret string."
|
||||
)
|
||||
|
||||
self._hmac_secret = hs.config.form_secret.encode("utf-8")
|
||||
|
@ -139,7 +140,7 @@ class ConsentResource(Resource):
|
|||
|
||||
self._check_hash(username, userhmac_bytes)
|
||||
|
||||
if username.startswith('@'):
|
||||
if username.startswith("@"):
|
||||
qualified_user_id = username
|
||||
else:
|
||||
qualified_user_id = UserID(username, self.hs.hostname).to_string()
|
||||
|
@ -153,7 +154,8 @@ class ConsentResource(Resource):
|
|||
|
||||
try:
|
||||
self._render_template(
|
||||
request, "%s.html" % (version,),
|
||||
request,
|
||||
"%s.html" % (version,),
|
||||
user=username,
|
||||
userhmac=userhmac,
|
||||
version=version,
|
||||
|
@ -180,7 +182,7 @@ class ConsentResource(Resource):
|
|||
|
||||
self._check_hash(username, userhmac)
|
||||
|
||||
if username.startswith('@'):
|
||||
if username.startswith("@"):
|
||||
qualified_user_id = username
|
||||
else:
|
||||
qualified_user_id = UserID(username, self.hs.hostname).to_string()
|
||||
|
@ -221,11 +223,13 @@ class ConsentResource(Resource):
|
|||
SynapseError if the hash doesn't match
|
||||
|
||||
"""
|
||||
want_mac = hmac.new(
|
||||
key=self._hmac_secret,
|
||||
msg=userid.encode('utf-8'),
|
||||
digestmod=sha256,
|
||||
).hexdigest().encode('ascii')
|
||||
want_mac = (
|
||||
hmac.new(
|
||||
key=self._hmac_secret, msg=userid.encode("utf-8"), digestmod=sha256
|
||||
)
|
||||
.hexdigest()
|
||||
.encode("ascii")
|
||||
)
|
||||
|
||||
if not compare_digest(want_mac, userhmac):
|
||||
raise SynapseError(http_client.FORBIDDEN, "HMAC incorrect")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue