fix: rfc4716_blob within the complexity limit (quality ratchet) #13
@@ -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 [])
|
||||
|
||||
|
||||
Reference in new issue
Block a user