Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error if encryption is enabled but the algorithm isn't specified #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ string randomKey(int length);
string timestamp();
void echo(bool);
ofstream logFile;

//program entry point
int main(int argc, char **argv){

Expand Down Expand Up @@ -100,6 +101,7 @@ int main(int argc, char **argv){
int keyLength=0;
bool detail=false;
SCSIEncryptOptions drvOptions;
bool algorithmIndexSet = false;

//First load all of the options
for(int i=1;i<argc;i++){
Expand Down Expand Up @@ -168,16 +170,23 @@ int main(int argc, char **argv){
detail=true;
}
else if(thisCmd=="-a"){
if(nextCmd=="")errorOut("You must specify a numeric algorithm index when using the -a flag");
drvOptions.algorithmIndex=atoi(nextCmd.c_str());
if(nextCmd=="") {
errorOut("You must specify a numeric algorithm index when using the -a flag");
}
drvOptions.algorithmIndex=atoi(nextCmd.c_str());
algorithmIndexSet = true;
i++; //skip the next argument
}
else{
errorOut("Unknown command '"+thisCmd+"'");
}

}

// Done reading options. Validate.
if (drvOptions.cryptMode != CRYPTMODE_OFF && !algorithmIndexSet) {
errorOut("Encryption enabled but no algorithm index was set. Use 1 for 256-bit AES.");
}
// Done validating. Execute action.
if(action==2){//generate key
if(keyFile==""){
errorOut("Specify file to save into with the -k argument.");
Expand Down Expand Up @@ -334,6 +343,7 @@ int main(int argc, char **argv){
errorOut("Turning encryption off for '"+tapeDrive+"' failed!");
}
}

//exits to shell with an error message
void errorOut(string message){
cerr<<"Error: "<<message<<endl;
Expand Down