X-Git-Url: http://git.euphorik.ch/?p=rup.git;a=blobdiff_plain;f=src%2Fcrypto.rs;h=caf34f7cd10b7f2f50ee10ea0e83cbd3416d1ed4;hp=ddf257cd3b60d425a856792b4c10537ae86d4d5d;hb=f43bab0b61b36e53135569727476fc6f39a3deec;hpb=4579d6b4f5b3e764c3a7c9787ed3d48840777297 diff --git a/src/crypto.rs b/src/crypto.rs index ddf257c..caf34f7 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -19,6 +19,7 @@ pub enum EncryptError { pub enum DecryptError { KeyError(KeyError), WrongMessageVersion, + MessageToShort, UnableToDecodeBase64Message, UnableToDecrypt, UnableToDecodeMessageAsUTF8String, @@ -68,6 +69,8 @@ pub fn decrypt(key: &str, cipher_text: &str) -> Result { base64::decode(&cipher_text.as_bytes()[consts::CURRENT_MESSAGE_VERSION.as_bytes().len()..]) .map_err(|_e| DecryptError::UnableToDecodeBase64Message)?; + if cipher_text_bytes.len() <= 48 { return Err(DecryptError::MessageToShort) } + let iv = &cipher_text_bytes[0..16]; let hash = &cipher_text_bytes[16..48]; let encrypted_message = &cipher_text_bytes[48..];