mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-14 01:27:35 -05:00
cmdgen: add a --dump option.
Also spelled '-O text', this takes a public or private key as input, and produces on standard output a dump of all the actual numbers involved in the key: the exponent and modulus for RSA, the p,q,g,y parameters for DSA, the affine x and y coordinates of the public elliptic curve point for ECC keys, and all the extra bits and pieces in the private keys too. Partly I expect this to be useful to me for debugging: I've had to paste key files a few too many times through base64 decoders and hex dump tools, then manually decode SSH marshalling and paste the result into the Python REPL to get an integer object. Now I should be able to get _straight_ to text I can paste into Python. But also, it's a way that other applications can use the key generator: if you need to generate, say, an RSA key in some format I don't support (I've recently heard of an XML-based one, for example), then you can run 'puttygen -t rsa --dump' and have it print the elements of a freshly generated keypair on standard output, and then all you have to do is understand the output format.
This commit is contained in:
24
utils.c
24
utils.c
@ -1049,3 +1049,27 @@ size_t encode_utf8(void *output, unsigned long ch)
|
||||
}
|
||||
return p - start;
|
||||
}
|
||||
|
||||
void write_c_string_literal(FILE *fp, ptrlen str)
|
||||
{
|
||||
for (const char *p = str.ptr; p < (const char *)str.ptr + str.len; p++) {
|
||||
char c = *p;
|
||||
|
||||
if (c == '\n')
|
||||
fputs("\\n", fp);
|
||||
else if (c == '\r')
|
||||
fputs("\\r", fp);
|
||||
else if (c == '\t')
|
||||
fputs("\\t", fp);
|
||||
else if (c == '\b')
|
||||
fputs("\\b", fp);
|
||||
else if (c == '\\')
|
||||
fputs("\\\\", fp);
|
||||
else if (c == '"')
|
||||
fputs("\\\"", fp);
|
||||
else if (c >= 32 && c <= 126)
|
||||
fputc(c, fp);
|
||||
else
|
||||
fprintf(fp, "\\%03o", (unsigned char)c);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user