- if (outfile)
- fp = f_open(outfilename, "w");
- else
- fp = stdout;
- dec1 = bignum_decimal(ssh1key->exponent);
- dec2 = bignum_decimal(ssh1key->modulus);
- fprintf(fp, "%d %s %s %s\n", bignum_bitcount(ssh1key->modulus),
- dec1, dec2, ssh1key->comment);
- sfree(dec1);
- sfree(dec2);
- if (outfile)
- fclose(fp);
- } else if (outtype == PUBLIC) {
- if (!ssh2blob) {
- assert(ssh2key);
- ssh2blob = ssh2key->alg->public_blob(ssh2key->data,
- &ssh2bloblen);
- }
- save_ssh2_pubkey(outfile, ssh2key ? ssh2key->comment : origcomment,
- ssh2blob, ssh2bloblen);
- } else if (outtype == PUBLICO) {
- char *buffer, *p;
- int i;
- FILE *fp;
-
- if (!ssh2blob) {
- assert(ssh2key);
- ssh2blob = ssh2key->alg->public_blob(ssh2key->data,
- &ssh2bloblen);
- }
- if (!ssh2alg) {
- assert(ssh2key);
- ssh2alg = ssh2key->alg->name;
- }
- if (ssh2key)
- comment = ssh2key->comment;
- else
- comment = origcomment;
-
- buffer = snewn(strlen(ssh2alg) +
- 4 * ((ssh2bloblen+2) / 3) +
- strlen(comment) + 3, char);
- strcpy(buffer, ssh2alg);
- p = buffer + strlen(buffer);
- *p++ = ' ';
- i = 0;
- while (i < ssh2bloblen) {
- int n = (ssh2bloblen - i < 3 ? ssh2bloblen - i : 3);
- base64_encode_atom(ssh2blob + i, n, p);
- i += n;
- p += 4;
- }
- if (*comment) {
- *p++ = ' ';
- strcpy(p, comment);
- } else
- *p++ = '\0';
-
- if (outfile)
- fp = f_open(outfilename, "w");
- else
- fp = stdout;
- fprintf(fp, "%s\n", buffer);