summaryrefslogtreecommitdiffstats
path: root/security/nss/gtests/freebl_gtest/rsa_unittest.cc
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-06-06 21:27:04 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-06-06 21:27:04 +0200
commit4a71b30364a4b6d1eaf16fcfdc8e873e6697f293 (patch)
treea47014077c14579249859ad34afcc5a8f2f0730a /security/nss/gtests/freebl_gtest/rsa_unittest.cc
parentd7da72799521386c110dbba73b1e483b00a0a56a (diff)
parent2dad0ec41d0b69c0a815012e6ea4bdde81b2875b (diff)
downloadUXP-4a71b30364a4b6d1eaf16fcfdc8e873e6697f293.tar
UXP-4a71b30364a4b6d1eaf16fcfdc8e873e6697f293.tar.gz
UXP-4a71b30364a4b6d1eaf16fcfdc8e873e6697f293.tar.lz
UXP-4a71b30364a4b6d1eaf16fcfdc8e873e6697f293.tar.xz
UXP-4a71b30364a4b6d1eaf16fcfdc8e873e6697f293.zip
Merge branch 'NSS-335'
Diffstat (limited to 'security/nss/gtests/freebl_gtest/rsa_unittest.cc')
-rw-r--r--security/nss/gtests/freebl_gtest/rsa_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/security/nss/gtests/freebl_gtest/rsa_unittest.cc b/security/nss/gtests/freebl_gtest/rsa_unittest.cc
new file mode 100644
index 000000000..5c667a1d1
--- /dev/null
+++ b/security/nss/gtests/freebl_gtest/rsa_unittest.cc
@@ -0,0 +1,61 @@
+// 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));
+#ifdef NSS_FIPS_DISABLED
+ ASSERT_TRUE(key != nullptr);
+#else
+ ASSERT_TRUE(key == nullptr);
+#endif
+}