diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 20:06:18 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 20:06:18 +0000 |
commit | fdce4788af32cb9af8d77361cfddb96249263437 (patch) | |
tree | 30c6e4b04a7f46658a57a1265729e0b5ebd2de10 /crypto/encryptor_nss.cc | |
parent | 7d1025eeb76f1fe0e7bfe19f9f23b64974a63820 (diff) | |
download | chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.zip chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.gz chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.bz2 |
ake string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the without-'\0' string is non-empty. This replaces the conditional code added recently that makes this case return NULL. It's easier to understand if it's simply an error to call WriteInto() in this case at all.
Add DCHECK()s or conditionals as appropriate to callers in order to ensure this assertion holds.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8418034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/encryptor_nss.cc')
-rw-r--r-- | crypto/encryptor_nss.cc | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/crypto/encryptor_nss.cc b/crypto/encryptor_nss.cc index c4610903..cf4fa2a 100644 --- a/crypto/encryptor_nss.cc +++ b/crypto/encryptor_nss.cc @@ -72,13 +72,12 @@ bool Encryptor::Init(SymmetricKey* key, break; } - if (!param_.get()) - return false; - return true; + return param_ != NULL; } bool Encryptor::Encrypt(const base::StringPiece& plaintext, std::string* ciphertext) { + CHECK(!plaintext.empty() || (mode_ == CBC)); ScopedPK11Context context(PK11_CreateContextBySymKey(GetMechanism(mode_), CKA_ENCRYPT, key_->key(), @@ -86,34 +85,30 @@ bool Encryptor::Encrypt(const base::StringPiece& plaintext, if (!context.get()) return false; - if (mode_ == CTR) - return CryptCTR(context.get(), plaintext, ciphertext); - else - return Crypt(context.get(), plaintext, ciphertext); + return (mode_ == CTR) ? + CryptCTR(context.get(), plaintext, ciphertext) : + Crypt(context.get(), plaintext, ciphertext); } bool Encryptor::Decrypt(const base::StringPiece& ciphertext, std::string* plaintext) { - if (ciphertext.empty()) - return false; - + CHECK(!ciphertext.empty()); ScopedPK11Context context(PK11_CreateContextBySymKey( GetMechanism(mode_), (mode_ == CTR ? CKA_ENCRYPT : CKA_DECRYPT), key_->key(), param_.get())); if (!context.get()) return false; - if (mode_ == CTR) - return CryptCTR(context.get(), ciphertext, plaintext); - else - return Crypt(context.get(), ciphertext, plaintext); + return (mode_ == CTR) ? + CryptCTR(context.get(), ciphertext, plaintext) : + Crypt(context.get(), ciphertext, plaintext); } bool Encryptor::Crypt(PK11Context* context, const base::StringPiece& input, std::string* output) { size_t output_len = input.size() + AES_BLOCK_SIZE; - CHECK(output_len > input.size()) << "Output size overflow"; + CHECK_GT(output_len, input.size()); output->resize(output_len); uint8* output_data = @@ -160,7 +155,7 @@ bool Encryptor::CryptCTR(PK11Context* context, size_t output_len = ((input.size() + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE; - CHECK(output_len >= input.size()) << "Output size overflow"; + CHECK_GE(output_len, input.size()); output->resize(output_len); uint8* output_data = reinterpret_cast<uint8*>(const_cast<char*>(output->data())); @@ -180,7 +175,7 @@ bool Encryptor::CryptCTR(PK11Context* context, mask_len); if (SECSuccess != rv) return false; - CHECK(op_len == static_cast<int>(mask_len)); + CHECK_EQ(static_cast<int>(mask_len), op_len); unsigned int digest_len; rv = PK11_DigestFinal(context, |