diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-10-09 21:43:38 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-10-09 21:43:38 +0200 |
commit | cbea7bc041e5c14670042e3e52f0786f9561af05 (patch) | |
tree | 4d646978f1ed984099828a65c92bcee0a72b47dc /envelope | |
parent | d6dd94c63252ace898d9a60a539c7ab14d69f0ea (diff) |
Better error handling (exceptions)
Diffstat (limited to 'envelope')
-rwxr-xr-x | envelope/envelope | bin | 0 -> 121056 bytes | |||
-rw-r--r-- | envelope/main.cpp | 23 |
2 files changed, 20 insertions, 3 deletions
diff --git a/envelope/envelope b/envelope/envelope Binary files differnew file mode 100755 index 0000000..599c263 --- /dev/null +++ b/envelope/envelope 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){ |