aboutsummaryrefslogtreecommitdiff
path: root/envelope
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-09 21:43:38 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-09 21:43:38 +0200
commitcbea7bc041e5c14670042e3e52f0786f9561af05 (patch)
tree4d646978f1ed984099828a65c92bcee0a72b47dc /envelope
parentd6dd94c63252ace898d9a60a539c7ab14d69f0ea (diff)
Better error handling (exceptions)
Diffstat (limited to 'envelope')
-rwxr-xr-xenvelope/envelopebin0 -> 121056 bytes
-rw-r--r--envelope/main.cpp23
2 files changed, 20 insertions, 3 deletions
diff --git a/envelope/envelope b/envelope/envelope
new file mode 100755
index 0000000..599c263
--- /dev/null
+++ b/envelope/envelope
Binary files differ
diff --git a/envelope/main.cpp b/envelope/main.cpp
index f0e544e..3889c2a 100644
--- a/envelope/main.cpp
+++ b/envelope/main.cpp
@@ -52,7 +52,13 @@ void mode_keygen(int keylength){
}
void mode_encrypt(const string &pubkeyrepr){
- RSA::Key key(RSA::importKey(pubkeyrepr));
+ RSA::Key key;
+ try {
+ key=RSA::importKey(pubkeyrepr);
+ } catch(invalid_argument){
+ cerr<<"The given public key is not a valid key!"<<endl;
+ exit(1);
+ }
string data;
char buf[1024];
while(cin){
@@ -65,7 +71,13 @@ void mode_encrypt(const string &pubkeyrepr){
}
void mode_decrypt(const string &privkeyrepr){
- RSA::Key key(RSA::importKey(privkeyrepr));
+ RSA::Key key;
+ try {
+ key=RSA::importKey(privkeyrepr);
+ } catch(invalid_argument){
+ cerr<<"The given private key is not a valid key!"<<endl;
+ exit(1);
+ }
string data;
char buf[1024];
while(cin){
@@ -74,7 +86,12 @@ void mode_decrypt(const string &privkeyrepr){
if(nread==0)continue;
data.append(buf,nread);
}
- cout<<Envelope::decrypt(Base64::decode(data),key)<<flush;
+ try {
+ cout<<Envelope::decrypt(Base64::decode(data),key)<<flush;
+ } catch(invalid_argument){
+ cerr<<"Private key doesn't match encrypted text!"<<endl;
+ exit(1);
+ }
}
int main(int argc,char **argv){