Merge pull request 'fix: rfc4716_blob within the complexity limit (quality ratchet)' (#13) from fix/rfc4716-complexity into main
driver / standard (push) Successful in 16s
driver / lint (push) Successful in 14s
driver / types (push) Successful in 1m14s
driver / test (3.12) (push) Successful in 1m12s
driver / test (3.13) (push) Successful in 59s
driver / lowest (push) Successful in 30s
driver / build (push) Successful in 35s
driver / security (push) Successful in 1m11s
CI / driver (push) Successful in 2m47s
driver / publish (push) Skipped

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
christianmanivong committed 2026-10-31 23:54:06 +00:00
commit 57feb44a76
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."""
lines = [line.strip() for line in text.strip().splitlines()]
if lines and lines[0].startswith("---- BEGIN SSH2 PUBLIC KEY"):
body: list[str] = []
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
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] = []
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:
return blob is not None and any(rfc4716_blob(line) == blob for line in keys or [])