Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -115,10 +115,7 @@ class PubsubSigning:
|
|||
# et_sign_data_elt = xml_tools.domish_elt_2_et_elt(sign_data_elt, True)
|
||||
et_sign_data_elt = etree.fromstring(sign_data_elt.toXml())
|
||||
to_sign = etree.tostring(
|
||||
et_sign_data_elt,
|
||||
method="c14n2",
|
||||
with_comments=False,
|
||||
strip_text=True
|
||||
et_sign_data_elt, method="c14n2", with_comments=False, strip_text=True
|
||||
)
|
||||
# the data to sign is serialised, we cna restore original values
|
||||
item_elt["id"] = item_id
|
||||
|
|
@ -141,7 +138,7 @@ class PubsubSigning:
|
|||
jid.JID(service),
|
||||
node,
|
||||
item_id,
|
||||
data_format.deserialise(signature_data_s)
|
||||
data_format.deserialise(signature_data_s),
|
||||
)
|
||||
)
|
||||
d.addCallback(data_format.serialise)
|
||||
|
|
@ -155,9 +152,7 @@ class PubsubSigning:
|
|||
item_id: str,
|
||||
signature_data: Dict[str, Any],
|
||||
) -> Dict[str, Any]:
|
||||
items, __ = await self._p.get_items(
|
||||
client, service, node, item_ids=[item_id]
|
||||
)
|
||||
items, __ = await self._p.get_items(client, service, node, item_ids=[item_id])
|
||||
if not items != 1:
|
||||
raise exceptions.NotFound(
|
||||
f"target item not found for {item_id!r} at {node!r} for {service}"
|
||||
|
|
@ -172,7 +167,8 @@ class PubsubSigning:
|
|||
signer = jid.JID(signers[0])
|
||||
signature = base64.b64decode(signature_data["signature"])
|
||||
verification_keys = {
|
||||
k for k in await self._ox.import_all_public_keys(client, signer)
|
||||
k
|
||||
for k in await self._ox.import_all_public_keys(client, signer)
|
||||
if client.gpg_provider.can_sign(k)
|
||||
}
|
||||
signed_data = self.get_data_to_sign(item_elt, service, timestamp, signer.full())
|
||||
|
|
@ -200,9 +196,7 @@ class PubsubSigning:
|
|||
data: Dict[str, Any],
|
||||
) -> None:
|
||||
try:
|
||||
signature_elt = next(
|
||||
attachments_elt.elements(NS_PUBSUB_SIGNING, "signature")
|
||||
)
|
||||
signature_elt = next(attachments_elt.elements(NS_PUBSUB_SIGNING, "signature"))
|
||||
except StopIteration:
|
||||
pass
|
||||
else:
|
||||
|
|
@ -220,13 +214,12 @@ class PubsubSigning:
|
|||
"timestamp": timestamp,
|
||||
"signers": [
|
||||
str(s) for s in signature_elt.elements(NS_PUBSUB_SIGNING, "signer")
|
||||
]
|
||||
],
|
||||
}
|
||||
# FIXME: only OpenPGP signature is available for now, to be updated if and
|
||||
# when more algorithms are available.
|
||||
sign_elt = next(
|
||||
signature_elt.elements(NS_PUBSUB_SIGNING_OPENPGP, "sign"),
|
||||
None
|
||||
signature_elt.elements(NS_PUBSUB_SIGNING_OPENPGP, "sign"), None
|
||||
)
|
||||
if sign_elt is None:
|
||||
log.warning(
|
||||
|
|
@ -243,7 +236,7 @@ class PubsubSigning:
|
|||
self,
|
||||
client: SatXMPPEntity,
|
||||
attachments_data: Dict[str, Any],
|
||||
former_elt: Optional[domish.Element]
|
||||
former_elt: Optional[domish.Element],
|
||||
) -> Optional[domish.Element]:
|
||||
signature_data = attachments_data["extra"].get("signature")
|
||||
if signature_data is None:
|
||||
|
|
@ -277,7 +270,8 @@ class PubsubSigning:
|
|||
|
||||
sign_elt = signature_elt.addElement((NS_PUBSUB_SIGNING_OPENPGP, "sign"))
|
||||
signing_keys = {
|
||||
k for k in self._ox.list_secret_keys(client)
|
||||
k
|
||||
for k in self._ox.list_secret_keys(client)
|
||||
if client.gpg_provider.can_sign(k.public_key)
|
||||
}
|
||||
# the base64 encoded signature itself
|
||||
|
|
@ -298,7 +292,7 @@ class PubsubSigning:
|
|||
items: Optional[List[domish.Element]],
|
||||
options: Optional[dict],
|
||||
sender: jid.JID,
|
||||
extra: Dict[str, Any]
|
||||
extra: Dict[str, Any],
|
||||
) -> bool:
|
||||
if not items or not extra.get("signed"):
|
||||
return True
|
||||
|
|
@ -318,8 +312,8 @@ class PubsubSigning:
|
|||
"item_elt": item_elt,
|
||||
"signer": sender.userhost(),
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in a new issue