- if (state->ssh2) {
- ret = save_ssh2_pubkey(filename, &state->ssh2key);
- } else {
- ret = save_ssh1_pubkey(filename, &state->key);
- }
- if (ret <= 0) {
- MessageBox(hwnd, "Unable to save key file",
- "PuTTYgen Error", MB_OK | MB_ICONERROR);
- }
+ fp = fopen(filename, "w");
+ if (!fp) {
+ MessageBox(hwnd, "Unable to open key file",
+ "PuTTYgen Error", MB_OK | MB_ICONERROR);
+ } else {
+ if (state->ssh2) {
+ int bloblen;
+ unsigned char *blob;
+ blob = state->ssh2key.alg->public_blob
+ (state->ssh2key.data, &bloblen);
+ ssh2_write_pubkey(fp, state->ssh2key.comment,
+ blob, bloblen,
+ SSH_KEYTYPE_SSH2_PUBLIC_RFC4716);
+ } else {
+ ssh1_write_pubkey(fp, &state->key);
+ }
+ if (fclose(fp) < 0) {
+ MessageBox(hwnd, "Unable to save key file",
+ "PuTTYgen Error", MB_OK | MB_ICONERROR);
+ }
+ }