fix: rfc4716_blob within the complexity limit (quality ratchet)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m19s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / test (3.13) (pull_request) Successful in 1m9s
driver / lowest (pull_request) Successful in 33s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m30s
CI / driver (pull_request) Successful in 3m16s
driver / publish (pull_request) Skipped

The RFC 4716 body moves into _rfc4716_body; rfc4716_blob only tells the
two key forms apart. main's ratchet job failed on complexity 11.
This commit is contained in:
Christian Manivong committed 2026-11-01 00:53:10 +01:00
1 parent 403899916f
commit a88e02ea56
1 file changed
+15 -10
+15 -10
View File
@@ -44,22 +44,27 @@ def rfc4716_blob(text: str) -> str | None:
"""The base64 of a public key, in OMV's RFC 4716 form or OpenSSH's one line.""" """The base64 of a public key, in OMV's RFC 4716 form or OpenSSH's one line."""
lines = [line.strip() for line in text.strip().splitlines()] lines = [line.strip() for line in text.strip().splitlines()]
if lines and lines[0].startswith("---- BEGIN SSH2 PUBLIC KEY"): if lines and lines[0].startswith("---- BEGIN SSH2 PUBLIC KEY"):
body: list[str] = [] return _rfc4716_body(lines[1:])
header = False
for line in lines[1:]:
if line.startswith("---- END SSH2 PUBLIC KEY"):
return "".join(body) or None
if header or ":" in line:
header = line.endswith("\\") # a header continues on the next line
continue
body.append(line)
return None
words = text.split() words = text.split()
if len(words) >= 2 and words[0].startswith(("ssh-", "ecdsa-", "sk-")): if len(words) >= 2 and words[0].startswith(("ssh-", "ecdsa-", "sk-")):
return words[1] return words[1]
return None return None
def _rfc4716_body(lines: list[str]) -> str | None:
"""The base64 between the headers and the END line; None without an END line."""
body: list[str] = []
header = False
for line in lines:
if line.startswith("---- END SSH2 PUBLIC KEY"):
return "".join(body) or None
if header or ":" in line:
header = line.endswith("\\") # a header continues on the next line
continue
body.append(line)
return None
def _holds(keys: list[str] | None, blob: str | None) -> bool: def _holds(keys: list[str] | None, blob: str | None) -> bool:
return blob is not None and any(rfc4716_blob(line) == blob for line in keys or []) return blob is not None and any(rfc4716_blob(line) == blob for line in keys or [])