diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
commit | f4a12fc67689a830e9da1c87fd11afe5bc09deb3 (patch) | |
tree | 211ae0cd022a6c11b0026ecc7761a550c584583c /security/nss/gtests/der_gtest/der_quickder_unittest.cc | |
parent | f7d30133221896638f7bf4f66c504255c4b14f48 (diff) | |
download | UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.gz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.lz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.xz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.zip |
Issue #1338 - Part 2: Update NSS to 3.48-RTM
Diffstat (limited to 'security/nss/gtests/der_gtest/der_quickder_unittest.cc')
-rw-r--r-- | security/nss/gtests/der_gtest/der_quickder_unittest.cc | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/security/nss/gtests/der_gtest/der_quickder_unittest.cc b/security/nss/gtests/der_gtest/der_quickder_unittest.cc index 944117909..a5301f15c 100644 --- a/security/nss/gtests/der_gtest/der_quickder_unittest.cc +++ b/security/nss/gtests/der_gtest/der_quickder_unittest.cc @@ -16,17 +16,35 @@ #include "secerr.h" #include "secitem.h" -const SEC_ASN1Template mySEC_NullTemplate[] = { - {SEC_ASN1_NULL, 0, NULL, sizeof(SECItem)}}; - namespace nss_test { +struct TemplateAndInput { + const SEC_ASN1Template* t; + SECItem input; +}; + class QuickDERTest : public ::testing::Test, - public ::testing::WithParamInterface<SECItem> {}; + public ::testing::WithParamInterface<TemplateAndInput> {}; +static const uint8_t kBitstringTag = 0x03; static const uint8_t kNullTag = 0x05; static const uint8_t kLongLength = 0x80; +const SEC_ASN1Template kBitstringTemplate[] = { + {SEC_ASN1_BIT_STRING, 0, NULL, sizeof(SECItem)}, {0}}; + +// Empty bitstring with unused bits. +static uint8_t kEmptyBitstringUnused[] = {kBitstringTag, 1, 1}; + +// Bitstring with 8 unused bits. +static uint8_t kBitstring8Unused[] = {kBitstringTag, 3, 8, 0xff, 0x00}; + +// Bitstring with >8 unused bits. +static uint8_t kBitstring9Unused[] = {kBitstringTag, 3, 9, 0xff, 0x80}; + +const SEC_ASN1Template kNullTemplate[] = { + {SEC_ASN1_NULL, 0, NULL, sizeof(SECItem)}, {0}}; + // Length of zero wrongly encoded as 0x80 instead of 0x00. static uint8_t kOverlongLength_0_0[] = {kNullTag, kLongLength | 0}; @@ -53,14 +71,22 @@ static uint8_t kOverlongLength_16_0[] = {kNullTag, kLongLength | 0x10, 0x00, 0x00, 0x00, 0x00}; -static const SECItem kInvalidDER[] = { - {siBuffer, kOverlongLength_0_0, sizeof(kOverlongLength_0_0)}, - {siBuffer, kOverlongLength_1_0, sizeof(kOverlongLength_1_0)}, - {siBuffer, kOverlongLength_16_0, sizeof(kOverlongLength_16_0)}, +#define TI(t, x) \ + { \ + t, { siBuffer, x, sizeof(x) } \ + } +static const TemplateAndInput kInvalidDER[] = { + TI(kBitstringTemplate, kEmptyBitstringUnused), + TI(kBitstringTemplate, kBitstring8Unused), + TI(kBitstringTemplate, kBitstring9Unused), + TI(kNullTemplate, kOverlongLength_0_0), + TI(kNullTemplate, kOverlongLength_1_0), + TI(kNullTemplate, kOverlongLength_16_0), }; +#undef TI TEST_P(QuickDERTest, InvalidLengths) { - const SECItem& original_input(GetParam()); + const SECItem& original_input(GetParam().input); ScopedSECItem copy_of_input(SECITEM_AllocItem(nullptr, nullptr, 0U)); ASSERT_TRUE(copy_of_input); @@ -69,11 +95,10 @@ TEST_P(QuickDERTest, InvalidLengths) { PORTCheapArenaPool pool; PORT_InitCheapArena(&pool, DER_DEFAULT_CHUNKSIZE); - ScopedSECItem parsed_value(SECITEM_AllocItem(nullptr, nullptr, 0U)); - ASSERT_TRUE(parsed_value); + StackSECItem parsed_value; ASSERT_EQ(SECFailure, - SEC_QuickDERDecodeItem(&pool.arena, parsed_value.get(), - mySEC_NullTemplate, copy_of_input.get())); + SEC_QuickDERDecodeItem(&pool.arena, &parsed_value, GetParam().t, + copy_of_input.get())); ASSERT_EQ(SEC_ERROR_BAD_DER, PR_GetError()); PORT_DestroyCheapArena(&pool); } |