3
3
// found in the LICENSE file.
4
4
5
5
#include " crypto/signature_verifier.h"
6
+
7
+ #include " base/numerics/safe_conversions.h"
6
8
#include " testing/gtest/include/gtest/gtest.h"
7
9
8
10
TEST (SignatureVerifierTest, BasicTest) {
@@ -1005,36 +1007,36 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
1005
1007
public_key_info->insert (public_key_info->begin (),
1006
1008
public_exponent_e.begin (),
1007
1009
public_exponent_e.end ());
1008
- uint8 length = public_exponent_e.size ();
1009
- public_key_info->insert (public_key_info->begin (), length );
1010
+ uint8 exponent_size = base::checked_cast<uint8>( public_exponent_e.size () );
1011
+ public_key_info->insert (public_key_info->begin (), exponent_size );
1010
1012
public_key_info->insert (public_key_info->begin (), kIntegerTag );
1011
1013
1012
1014
// Encode the modulus n as an INTEGER.
1013
1015
public_key_info->insert (public_key_info->begin (),
1014
1016
modulus_n.begin (), modulus_n.end ());
1015
- uint16 length16 = modulus_n.size ();
1017
+ uint16 modulus_size = base::checked_cast<uint16>( modulus_n.size () );
1016
1018
if (modulus_n[0 ] & 0x80 ) {
1017
1019
public_key_info->insert (public_key_info->begin (), 0x00 );
1018
- length16 ++;
1020
+ modulus_size ++;
1019
1021
}
1020
- public_key_info->insert (public_key_info->begin (), length16 & 0xff );
1021
- public_key_info->insert (public_key_info->begin (), (length16 >> 8 ) & 0xff );
1022
+ public_key_info->insert (public_key_info->begin (), modulus_size & 0xff );
1023
+ public_key_info->insert (public_key_info->begin (), (modulus_size >> 8 ) & 0xff );
1022
1024
public_key_info->insert (public_key_info->begin (), 0x82 );
1023
1025
public_key_info->insert (public_key_info->begin (), kIntegerTag );
1024
1026
1025
1027
// Encode the RSAPublicKey SEQUENCE.
1026
- length16 = public_key_info->size ();
1027
- public_key_info->insert (public_key_info->begin (), length16 & 0xff );
1028
- public_key_info->insert (public_key_info->begin (), (length16 >> 8 ) & 0xff );
1028
+ uint16 info_size = base::checked_cast<uint16>( public_key_info->size () );
1029
+ public_key_info->insert (public_key_info->begin (), info_size & 0xff );
1030
+ public_key_info->insert (public_key_info->begin (), (info_size >> 8 ) & 0xff );
1029
1031
public_key_info->insert (public_key_info->begin (), 0x82 );
1030
1032
public_key_info->insert (public_key_info->begin (), kSequenceTag );
1031
1033
1032
1034
// Encode the BIT STRING.
1033
1035
// Number of unused bits.
1034
1036
public_key_info->insert (public_key_info->begin (), 0x00 );
1035
- length16 = public_key_info->size ();
1036
- public_key_info->insert (public_key_info->begin (), length16 & 0xff );
1037
- public_key_info->insert (public_key_info->begin (), (length16 >> 8 ) & 0xff );
1037
+ info_size = base::checked_cast<uint16>( public_key_info->size () );
1038
+ public_key_info->insert (public_key_info->begin (), info_size & 0xff );
1039
+ public_key_info->insert (public_key_info->begin (), (info_size >> 8 ) & 0xff );
1038
1040
public_key_info->insert (public_key_info->begin (), 0x82 );
1039
1041
public_key_info->insert (public_key_info->begin (), kBitStringTag );
1040
1042
@@ -1049,9 +1051,9 @@ static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n,
1049
1051
algorithm, algorithm + sizeof (algorithm));
1050
1052
1051
1053
// Encode the outermost SEQUENCE.
1052
- length16 = public_key_info->size ();
1053
- public_key_info->insert (public_key_info->begin (), length16 & 0xff );
1054
- public_key_info->insert (public_key_info->begin (), (length16 >> 8 ) & 0xff );
1054
+ info_size = base::checked_cast<uint16>( public_key_info->size () );
1055
+ public_key_info->insert (public_key_info->begin (), info_size & 0xff );
1056
+ public_key_info->insert (public_key_info->begin (), (info_size >> 8 ) & 0xff );
1055
1057
public_key_info->insert (public_key_info->begin (), 0x82 );
1056
1058
public_key_info->insert (public_key_info->begin (), kSequenceTag );
1057
1059
0 commit comments