Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: crypto/encryptor_mac.cc

Issue 8511050: Unify the error checking of crypto::Encryptor and add WARN_UNUSED_RESULT to prevent misuse. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/encryptor.cc ('k') | crypto/encryptor_nss.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/encryptor_mac.cc
diff --git a/crypto/encryptor_mac.cc b/crypto/encryptor_mac.cc
index 6be373a5d92028052b1de94d5f1d85739b54ffcf..972fc0432403a0ba7379f04d1de2957af6b7aa70 100644
--- a/crypto/encryptor_mac.cc
+++ b/crypto/encryptor_mac.cc
@@ -23,8 +23,10 @@ Encryptor::~Encryptor() {
bool Encryptor::Init(SymmetricKey* key,
Mode mode,
const base::StringPiece& iv) {
- DCHECK(key);
- DCHECK_EQ(CBC, mode) << "Unsupported mode of operation";
+ DCHECK_EQ(CBC, mode);
+ if (!key)
+ return false;
+
CSSM_DATA raw_key = key->cssm_data();
if (raw_key.Length != kCCKeySizeAES128 &&
raw_key.Length != kCCKeySizeAES192 &&
@@ -42,15 +44,17 @@ bool Encryptor::Init(SymmetricKey* key,
bool Encryptor::Crypt(int /*CCOperation*/ op,
const base::StringPiece& input,
std::string* output) {
- DCHECK(key_);
+ if (!key_)
+ return false;
+
CSSM_DATA raw_key = key_->cssm_data();
// CommonCryptor.h: "A general rule for the size of the output buffer which
// must be provided by the caller is that for block ciphers, the output
// length is never larger than the input length plus the block size."
-
size_t output_size = input.size() + iv_.size();
- CHECK_GT(output_size, 0u);
- CHECK_GT(output_size + 1, input.size());
+ if (output_size == 0 || output_size + 1 < input.size())
+ return false;
+
CCCryptorStatus err = CCCrypt(op,
kCCAlgorithmAES128,
kCCOptionPKCS7Padding,
@@ -61,7 +65,6 @@ bool Encryptor::Crypt(int /*CCOperation*/ op,
output_size,
&output_size);
if (err) {
- output->clear();
LOG(ERROR) << "CCCrypt returned " << err;
return false;
}
@@ -71,13 +74,15 @@ bool Encryptor::Crypt(int /*CCOperation*/ op,
bool Encryptor::Encrypt(const base::StringPiece& plaintext,
std::string* ciphertext) {
- CHECK(!plaintext.empty() || (mode_ == CBC));
+ if (plaintext.empty() && mode_ != CBC)
+ return false;
return Crypt(kCCEncrypt, plaintext, ciphertext);
}
bool Encryptor::Decrypt(const base::StringPiece& ciphertext,
std::string* plaintext) {
- CHECK(!ciphertext.empty());
+ if (ciphertext.empty())
+ return false;
return Crypt(kCCDecrypt, ciphertext, plaintext);
}
« no previous file with comments | « crypto/encryptor.cc ('k') | crypto/encryptor_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698