diff options
author | Martin Thomson <martin.thomson@gmail.com> | 2017-11-23 12:05:35 +1100 |
---|---|---|
committer | Martin Thomson <martin.thomson@gmail.com> | 2017-11-23 12:05:35 +1100 |
commit | 82f5248254af24e94dd0955297cd5259ca45b1b8 (patch) | |
tree | 9296417df06d845ad740f45b6ba9f1634a8bd656 /gtests | |
parent | 7bdd85eefb8ae0a63bf8228886b9c2b13a857dd1 (diff) | |
parent | 6280b248e57fa54bcd197edd6491962c9fc0e772 (diff) | |
download | nss-hg-82f5248254af24e94dd0955297cd5259ca45b1b8.tar.gz |
Merge NSS trunk to NSS_TLS13_DRAFT19_BRANCH
Diffstat (limited to 'gtests')
-rw-r--r-- | gtests/freebl_gtest/freebl_gtest.gyp | 1 | ||||
-rw-r--r-- | gtests/freebl_gtest/rsa_unittest.cc | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/gtests/freebl_gtest/freebl_gtest.gyp b/gtests/freebl_gtest/freebl_gtest.gyp index aa0810889..21a87c557 100644 --- a/gtests/freebl_gtest/freebl_gtest.gyp +++ b/gtests/freebl_gtest/freebl_gtest.gyp @@ -33,6 +33,7 @@ 'dh_unittest.cc', 'ecl_unittest.cc', 'ghash_unittest.cc', + 'rsa_unittest.cc', '<(DEPTH)/gtests/common/gtests.cc' ], 'dependencies': [ diff --git a/gtests/freebl_gtest/rsa_unittest.cc b/gtests/freebl_gtest/rsa_unittest.cc new file mode 100644 index 000000000..c2c435330 --- /dev/null +++ b/gtests/freebl_gtest/rsa_unittest.cc @@ -0,0 +1,57 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "gtest/gtest.h" + +#include <stdint.h> + +#include "blapi.h" +#include "secitem.h" + +template <class T> +struct ScopedDelete { + void operator()(T* ptr) { + if (ptr) { + PORT_FreeArena(ptr->arena, PR_TRUE); + } + } +}; + +typedef std::unique_ptr<RSAPrivateKey, ScopedDelete<RSAPrivateKey>> + ScopedRSAPrivateKey; + +class RSANewKeyTest : public ::testing::Test { + protected: + RSAPrivateKey* CreateKeyWithExponent(int keySizeInBits, + unsigned char publicExponent) { + SECItem exp = {siBuffer, 0, 0}; + unsigned char pubExp[1] = {publicExponent}; + exp.data = pubExp; + exp.len = 1; + + return RSA_NewKey(keySizeInBits, &exp); + } +}; + +TEST_F(RSANewKeyTest, expOneTest) { + ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x01)); + ASSERT_TRUE(key == nullptr); +} +TEST_F(RSANewKeyTest, expTwoTest) { + ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x02)); + ASSERT_TRUE(key == nullptr); +} +TEST_F(RSANewKeyTest, expFourTest) { + ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x04)); + ASSERT_TRUE(key == nullptr); +} +TEST_F(RSANewKeyTest, WrongKeysizeTest) { + ScopedRSAPrivateKey key(CreateKeyWithExponent(2047, 0x03)); + ASSERT_TRUE(key == nullptr); +} + +TEST_F(RSANewKeyTest, expThreeTest) { + ScopedRSAPrivateKey key(CreateKeyWithExponent(2048, 0x03)); + ASSERT_TRUE(key != nullptr); +} |