Implement key record recreation

master
LEdoian 3 years ago
parent 134cae1db3
commit a7bc22c767

@ -49,6 +49,13 @@ class AuthorizedKey:
self.key_b64 = split[1] self.key_b64 = split[1]
self.coment = split[2] if len(split) >= 3 else None self.coment = split[2] if len(split) >= 3 else None
def to_string(self):
result = ''
if self.options is not None: result += self.options + ' '
result += f'{self.type} {self.key_b64}'
if self.comment is not None: result += ' ' + self.comment
return result
def parse_file(f: IO[str]) -> list[AuthorizedKey | str]: def parse_file(f: IO[str]) -> list[AuthorizedKey | str]:
result = [] result = []
for line in f: for line in f:
@ -61,3 +68,10 @@ def parse_file(f: IO[str]) -> list[AuthorizedKey | str]:
return result return result
# TODO: Implement option parsing, key validation and decoding to bytes. # TODO: Implement option parsing, key validation and decoding to bytes.
def dump_file(keys: list[AuthorizedKey | str], f: IO[str]) -> None:
for rec in keys:
if isinstance(rec, AuthorizedKey):
rec = rec.to_string()
f.write(rec)
f.write('\n')

Loading…
Cancel
Save