diff options
-rw-r--r-- | crypto/ec_private_key_nss.cc | 2 | ||||
-rw-r--r-- | crypto/nss_util_unittest.cc | 15 | ||||
-rw-r--r-- | crypto/signature_verifier_unittest.cc | 32 |
3 files changed, 27 insertions, 22 deletions
diff --git a/crypto/ec_private_key_nss.cc b/crypto/ec_private_key_nss.cc index b38c396..2daa0c0 100644 --- a/crypto/ec_private_key_nss.cc +++ b/crypto/ec_private_key_nss.cc @@ -340,7 +340,7 @@ ECPrivateKey* ECPrivateKey::CreateWithParams(PK11SlotInfo* slot, }; ec_parameters.data[0] = SEC_ASN1_OBJECT_ID; - ec_parameters.data[1] = oid_data->oid.len; + ec_parameters.data[1] = static_cast<unsigned char>(oid_data->oid.len); memcpy(ec_parameters.data + 2, oid_data->oid.data, oid_data->oid.len); result->key_ = PK11_GenerateKeyPair(slot, diff --git a/crypto/nss_util_unittest.cc b/crypto/nss_util_unittest.cc index b687885..2859191 100644 --- a/crypto/nss_util_unittest.cc +++ b/crypto/nss_util_unittest.cc @@ -19,14 +19,17 @@ TEST(NSSUtilTest, PRTimeConversion) { prxtime.tm_params.tp_gmt_offset = 0; prxtime.tm_params.tp_dst_offset = 0; base::Time::Exploded exploded; - prxtime.tm_year = exploded.year = 2011; + exploded.year = prxtime.tm_year = 2011; exploded.month = 12; prxtime.tm_month = 11; - prxtime.tm_wday = exploded.day_of_week = 0; // Should be unusued. - prxtime.tm_mday = exploded.day_of_month = 10; - prxtime.tm_hour = exploded.hour = 2; - prxtime.tm_min = exploded.minute = 52; - prxtime.tm_sec = exploded.second = 19; + // PRExplodedTime::tm_wday is a smaller type than Exploded::day_of_week, so + // assigning the two in this order instead of the reverse avoids potential + // warnings about type downcasting. + exploded.day_of_week = prxtime.tm_wday = 0; // Should be unused. + exploded.day_of_month = prxtime.tm_mday = 10; + exploded.hour = prxtime.tm_hour = 2; + exploded.minute = prxtime.tm_min = 52; + exploded.second = prxtime.tm_sec = 19; exploded.millisecond = 342; prxtime.tm_usec = 342000; diff --git a/crypto/signature_verifier_unittest.cc b/crypto/signature_verifier_unittest.cc index 3329799..f6c42e0 100644 --- a/crypto/signature_verifier_unittest.cc +++ b/crypto/signature_verifier_unittest.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "crypto/signature_verifier.h" + +#include "base/numerics/safe_conversions.h" #include "testing/gtest/include/gtest/gtest.h" TEST(SignatureVerifierTest, BasicTest) { @@ -1005,36 +1007,36 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n, public_key_info->insert(public_key_info->begin(), public_exponent_e.begin(), public_exponent_e.end()); - uint8 length = public_exponent_e.size(); - public_key_info->insert(public_key_info->begin(), length); + uint8 exponent_size = base::checked_cast<uint8>(public_exponent_e.size()); + public_key_info->insert(public_key_info->begin(), exponent_size); public_key_info->insert(public_key_info->begin(), kIntegerTag); // Encode the modulus n as an INTEGER. public_key_info->insert(public_key_info->begin(), modulus_n.begin(), modulus_n.end()); - uint16 length16 = modulus_n.size(); + uint16 modulus_size = base::checked_cast<uint16>(modulus_n.size()); if (modulus_n[0] & 0x80) { public_key_info->insert(public_key_info->begin(), 0x00); - length16++; + modulus_size++; } - public_key_info->insert(public_key_info->begin(), length16 & 0xff); - public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); + public_key_info->insert(public_key_info->begin(), modulus_size & 0xff); + public_key_info->insert(public_key_info->begin(), (modulus_size >> 8) & 0xff); public_key_info->insert(public_key_info->begin(), 0x82); public_key_info->insert(public_key_info->begin(), kIntegerTag); // Encode the RSAPublicKey SEQUENCE. - length16 = public_key_info->size(); - public_key_info->insert(public_key_info->begin(), length16 & 0xff); - public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); + uint16 info_size = base::checked_cast<uint16>(public_key_info->size()); + public_key_info->insert(public_key_info->begin(), info_size & 0xff); + public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff); public_key_info->insert(public_key_info->begin(), 0x82); public_key_info->insert(public_key_info->begin(), kSequenceTag); // Encode the BIT STRING. // Number of unused bits. public_key_info->insert(public_key_info->begin(), 0x00); - length16 = public_key_info->size(); - public_key_info->insert(public_key_info->begin(), length16 & 0xff); - public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); + info_size = base::checked_cast<uint16>(public_key_info->size()); + public_key_info->insert(public_key_info->begin(), info_size & 0xff); + public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff); public_key_info->insert(public_key_info->begin(), 0x82); public_key_info->insert(public_key_info->begin(), kBitStringTag); @@ -1049,9 +1051,9 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n, algorithm, algorithm + sizeof(algorithm)); // Encode the outermost SEQUENCE. - length16 = public_key_info->size(); - public_key_info->insert(public_key_info->begin(), length16 & 0xff); - public_key_info->insert(public_key_info->begin(), (length16 >> 8) & 0xff); + info_size = base::checked_cast<uint16>(public_key_info->size()); + public_key_info->insert(public_key_info->begin(), info_size & 0xff); + public_key_info->insert(public_key_info->begin(), (info_size >> 8) & 0xff); public_key_info->insert(public_key_info->begin(), 0x82); public_key_info->insert(public_key_info->begin(), kSequenceTag); |