argc = opt_num_rest();
argv = opt_rest();
private = pubin || pubout ? 0 : 1;
- if (text)
+ if (text && !pubin)
private = 1;
if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
goto end;
if (text) {
- assert(private);
+ assert(pubin || private);
if (!DSA_print(out, dsa, 0)) {
perror(outfile);
ERR_print_errors(bio_err);
pk = EVP_PKEY_new();
EVP_PKEY_set1_DSA(pk, dsa);
if (outformat == FORMAT_PVK) {
+ if (pubin) {
+ BIO_printf(bio_err, "PVK form impossible with public key input\n");
+ EVP_PKEY_free(pk);
+ goto end;
+ }
assert(private);
i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
}
argc = opt_num_rest();
argv = opt_rest();
private = param_out || pubin || pubout ? 0 : 1;
- if (text)
+ if (text && !pubin)
private = 1;
if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
EC_KEY_set_asn1_flag(eckey, asn1_flag);
if (text) {
- assert(private);
+ assert(pubin || private);
if (!EC_KEY_print(out, eckey, 0)) {
perror(outfile);
ERR_print_errors(bio_err);
if (!noout) {
if (outformat == FORMAT_PEM) {
- assert(private);
if (pubout)
PEM_write_bio_PUBKEY(out, pkey);
- else
+ else {
+ assert(private);
PEM_write_bio_PrivateKey(out, pkey, cipher,
NULL, 0, NULL, passout);
+ }
} else if (outformat == FORMAT_ASN1) {
- assert(private);
if (pubout)
i2d_PUBKEY_bio(out, pkey);
- else
+ else {
+ assert(private);
i2d_PrivateKey_bio(out, pkey);
+ }
} else {
BIO_printf(bio_err, "Bad format specified for key\n");
goto end;
}
argc = opt_num_rest();
argv = opt_rest();
- private = text || (!pubout && !noout) ? 1 : 0;
+ private = (text && !pubin) || (!pubout && !noout) ? 1 : 0;
if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
BIO_printf(bio_err, "Error getting passwords\n");
goto end;
if (text) {
- assert(private);
+ assert(pubin || private);
if (!RSA_print(out, rsa, 0)) {
perror(outfile);
ERR_print_errors(bio_err);
EVP_PKEY *pk;
pk = EVP_PKEY_new();
EVP_PKEY_set1_RSA(pk, rsa);
- if (outformat == FORMAT_PVK)
+ if (outformat == FORMAT_PVK) {
+ if (pubin) {
+ BIO_printf(bio_err, "PVK form impossible with public key input\n");
+ EVP_PKEY_free(pk);
+ goto end;
+ }
+ assert(private);
i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
- else if (pubin || pubout)
+ } else if (pubin || pubout) {
i = i2b_PublicKey_bio(out, pk);
- else {
+ } else {
assert(private);
i = i2b_PrivateKey_bio(out, pk);
}