There's a high chance that the padding ^ 0x1 will produce a 0x01
trailing byte which happens to be a valid padding. In such case make
sure that the length of the decrypted data is different.
Change-Id: I60b7f9e708d850c49dbddbdda64ff178d730b4f7
// broken padding
encrypted.back() ^= 0x1;
- BOOST_REQUIRE_THROW(key->decrypt(ca, encrypted), Exc::Crypto::InputParam);
+ try {
+ auto decrypted = key->decrypt(ca, encrypted);
+
+ /*
+ * There's a high chance that the above ^= 0x1 will produce a 0x01 trailing byte which
+ * happens to be a valid padding. In such case make sure that the length of the
+ * decrypted data is different.
+ */
+ BOOST_REQUIRE(decrypted.size() != data.size());
+ } catch (const Exc::Crypto::InputParam&) {
+ // This is fine
+ } catch (...) {
+ BOOST_FAIL("Exc::Crypto::InputParam expected");
+ }
}
POSITIVE_TEST_CASE(asymmetricEncryptDecrypt)