Skip to content

Commit

Permalink
Per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Dec 5, 2023
1 parent 45067af commit 4884808
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
28 changes: 14 additions & 14 deletions crypto/pem/pem_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const char* SECRET = "test";

static int pem_password_callback(char *buf, int size, int rwflag, void *userdata) {
char* data = (char *)userdata;
int data_len = (int)strlen(data);
if(size + 1 < data_len) {
data_len = size-1;
buf[size-1] = 0;
int data_len = (int)strlen(data) + 1; // Add 1 for null terminator
if(size < data_len) {
data_len = size;
}
strncpy(buf, data, data_len);
return data_len;
if(data_len <= 0) {
return 0;
}
BUF_strlcpy(buf, data, data_len);
return data_len-1;
}

// Test that implausible ciphers, notably an IV-less RC4, aren't allowed in PEM.
Expand Down Expand Up @@ -80,17 +82,15 @@ TEST(PEMTest, WriteReadASN1IntegerPem) {
GTEST_SKIP();
#endif
// Numbers for testing
long nums[8] = {
std::vector<long> nums = {
0x00000001L,
0x00000100L,
0x00010000L,
0x01000000L,
-2L};

for(size_t i = 0; i < 8; i++) {
long original_value = nums[i];

// Create an ASN1_INTEGER with value 42
for(long original_value: nums) {
// Create an ASN1_INTEGER with value
bssl::UniquePtr<ASN1_INTEGER> asn1_int(ASN1_INTEGER_new());
ASSERT_TRUE(asn1_int.get());
ASSERT_TRUE(ASN1_INTEGER_set(asn1_int.get(), original_value));
Expand Down Expand Up @@ -130,7 +130,7 @@ TEST(PEMTest, ReadPrivateKeyPem) {
bssl::UniquePtr<BIO> read_bio(BIO_new_mem_buf(kPemRsaPrivateKey, strlen(kPemRsaPrivateKey)) );
ASSERT_TRUE(read_bio.get());
bssl::UniquePtr<EC_KEY> ec_key(PEM_read_bio_ECPrivateKey(read_bio.get(), nullptr, pem_password_callback, (void*)SECRET));
ASSERT_TRUE(ec_key);
ASSERT_TRUE(ec_key.get());
const EC_GROUP* p256 = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
ASSERT_EQ(p256, EC_KEY_get0_group(ec_key.get()));
}
Expand All @@ -142,7 +142,7 @@ TEST(PEMTest, WriteReadRSAPem) {
bssl::UniquePtr<BIGNUM> bn(BN_new());
ASSERT_TRUE(bn);
BN_set_u64(bn.get(), RSA_F4);
#ifdef BORINGSSL_FIPS
#if defined(BORINGSSL_FIPS)
ASSERT_TRUE(RSA_generate_key_fips(rsa.get(), 2048, nullptr));
#else
ASSERT_TRUE(RSA_generate_key_ex(rsa.get(), 2048, bn.get(), nullptr));
Expand Down Expand Up @@ -172,7 +172,7 @@ TEST(PEMTest, WriteReadECPem) {
ASSERT_TRUE(ec_group.get());
ASSERT_TRUE(EC_KEY_set_group(ec_key.get(), ec_group.get()));

#ifdef BORINGSSL_FIPS
#if defined(BORINGSSL_FIPS)
ASSERT_TRUE(EC_KEY_generate_key_fips(ec_key.get()));
#else
ASSERT_TRUE(EC_KEY_generate_key(ec_key.get()));
Expand Down
5 changes: 2 additions & 3 deletions crypto/x509/x509_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5716,7 +5716,7 @@ TEST(X509Test, SetSerialNumberCheckEndian) {
ASSERT_TRUE(root);

// Numbers for testing
int64_t nums[8] = {
std::vector<int64_t> nums = {
0x0000000000000001LL,
0x0000000000000100LL,
0x0000000000010000LL,
Expand All @@ -5726,8 +5726,7 @@ TEST(X509Test, SetSerialNumberCheckEndian) {
0x0001000000000000LL,
-2LL};

for(size_t i = 0; i < 8; i++) {
int64_t num = nums[i];
for(int64_t num: nums) {
bssl::UniquePtr<ASN1_INTEGER> serial(ASN1_INTEGER_new());
ASSERT_TRUE(serial);
// Set serial number for cert
Expand Down

0 comments on commit 4884808

Please sign in to comment.