Skip to content

Commit 6b751a0

Browse files
kingstjojustsmth
authored andcommitted
Improve format validation in EC tool
- Use isStringUpperCaseEqual() for case-insensitive format checking - Simplify error messages to show only supported formats - Make format validation consistent with other tools
1 parent fd009c0 commit 6b751a0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tool-openssl/ec.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ bool ecTool(const args_list_t &args) {
4949
return true;
5050
}
5151

52-
if (inform_str == "PEM" || inform_str == "pem") {
53-
input_format = FORMAT_PEM;
54-
} else if (inform_str == "DER" || inform_str == "der") {
52+
if (isStringUpperCaseEqual(inform_str, "DER")) {
5553
input_format = FORMAT_DER;
54+
} else if (isStringUpperCaseEqual(inform_str, "PEM")) {
55+
input_format = FORMAT_PEM;
5656
} else {
57-
fprintf(stderr, "Error: Invalid input format '%s'. Must be PEM, pem, DER, or der\n", inform_str.c_str());
57+
fprintf(stderr, "Error: Invalid input format '%s'. Must be PEM or DER\n", inform_str.c_str());
5858
goto err;
5959
}
6060

61-
if (outform_str == "PEM" || outform_str == "pem") {
62-
output_format = FORMAT_PEM;
63-
} else if (outform_str == "DER" || outform_str == "der") {
61+
if (isStringUpperCaseEqual(outform_str, "DER")) {
6462
output_format = FORMAT_DER;
63+
} else if (isStringUpperCaseEqual(outform_str, "PEM")) {
64+
output_format = FORMAT_PEM;
6565
} else {
66-
fprintf(stderr, "Error: Invalid output format '%s'. Must be PEM, pem, DER, or der\n", outform_str.c_str());
66+
fprintf(stderr, "Error: Invalid output format '%s'. Must be PEM or DER\n", outform_str.c_str());
6767
goto err;
6868
}
6969

0 commit comments

Comments
 (0)