fix: rfc4716_blob within the complexity limit (quality ratchet) #13

Merged
christianmanivong merged 1 commits from fix/rfc4716-complexity into main 2026-10-31 23:54:06 +00:00
+10 -5
View File
@@ -44,9 +44,18 @@ 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"):
return _rfc4716_body(lines[1:])
words = text.split()
if len(words) >= 2 and words[0].startswith(("ssh-", "ecdsa-", "sk-")):
return words[1]
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] = [] body: list[str] = []
header = False header = False
for line in lines[1:]: for line in lines:
if line.startswith("---- END SSH2 PUBLIC KEY"): if line.startswith("---- END SSH2 PUBLIC KEY"):
return "".join(body) or None return "".join(body) or None
if header or ":" in line: if header or ":" in line:
@@ -54,10 +63,6 @@ def rfc4716_blob(text: str) -> str | None:
continue continue
body.append(line) body.append(line)
return None return None
words = text.split()
if len(words) >= 2 and words[0].startswith(("ssh-", "ecdsa-", "sk-")):
return words[1]
return None
def _holds(keys: list[str] | None, blob: str | None) -> bool: def _holds(keys: list[str] | None, blob: str | None) -> bool: