diff options
author | Simon Tatham <anakin@pobox.com> | 2022-04-18 12:06:31 +0300 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2022-04-24 10:39:04 +0300 |
commit | 62bc6c5448514fc77386526b773fc4508945d9cd (patch) | |
tree | 94b47f5fb5ccc99e54cf60af471c2a6f560a0a23 /cmdgen.c | |
parent | 68514ac8a1fd6b588dedd6c88cd3003b88947783 (diff) |
New key component type KCT_BINARY.
This stores its data in the same format as the existing KCT_TEXT, but
it displays differently in puttygen --dump, expecting that the data
will be full of horrible control characters, invalid UTF-8, etc.
The displayed data is of the form b64("..."), so you get a hint about
what the encoding is, and can still paste into Python by defining the
identifier 'b64' to be base64.b64decode or equivalent.
Diffstat (limited to 'cmdgen.c')
-rw-r--r-- | cmdgen.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -1327,6 +1327,38 @@ int main(int argc, char **argv) write_c_string_literal(fp, ptrlen_from_strbuf(comp->str)); fputs("\"\n", fp); break; + case KCT_BINARY: { + /* + * Display format for binary key components is to show + * them as base64, with a wrapper so that the actual + * printed string is along the lines of + * 'b64("aGVsbG8sIHdvcmxkCg==")'. + * + * That's a compromise between not being too verbose + * for a human reader, and still being reasonably + * friendly to people pasting the output of this + * 'puttygen --dump' option into Python code (which + * the format is designed to permit in general). + * + * Python users pasting a dump containing one of these + * will have to define a function 'b64' in advance + * which takes a string, which you can do most easily + * using this import statement, as seen in + * cryptsuite.py: + * + * from base64 import b64decode as b64 + */ + fputs("b64(\"", fp); + char b64[4]; + for (size_t j = 0; j < comp->str->len; j += 3) { + size_t len = comp->str->len - j; + if (len > 3) len = 3; + base64_encode_atom(comp->str->u + j, len, b64); + fwrite(b64, 1, 4, fp); + } + fputs("\")\n", fp); + break; + } default: unreachable("bad key component type"); } |