Adding C++ wrapper and test case to set a seed value for UUID generation
authorsaurabh.s9 <saurabh.s9@samsung.com>
Mon, 16 Jan 2017 11:55:05 +0000 (17:25 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 7 Feb 2017 03:44:48 +0000 (03:44 +0000)
Change-Id: I14d20ce49b87741dfbef34631cb8f728f3c33b41
Signed-off-by: saurabh.s9 <saurabh.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16435
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
(cherry picked from commit d58a56bc2929f322b0997d2e6d52a8d2356192d2)
Reviewed-on: https://gerrit.iotivity.org/gerrit/16713

resource/include/OCProvisioningManager.hpp
resource/provisioning/src/OCProvisioningManager.cpp
resource/provisioning/unittests/OCProvisioningTest.cpp

index f38ce50..730057b 100644 (file)
@@ -521,6 +521,14 @@ namespace OC
              */
             static void certCallbackWrapper(void* ctx, uint16_t credId, uint8_t *trustCertChain,
                                 size_t chainSize);
+
+            /**
+             * Wrapper to save the seed value to generate device UUID
+             *
+             * @param[in] seed  buffer of seed value
+             * @param[in] seedSize byte length of seed
+             */
+             static OCStackResult setDeviceIdSeed(const uint8_t* seed, size_t seedSize);
 #endif // __WITH_DTLS__ || __WITH_TLS__
 
 
index d329f65..1e08a3c 100644 (file)
@@ -988,6 +988,30 @@ namespace OC
         }
         return result;
     }
+
+    OCStackResult OCSecure::setDeviceIdSeed(const uint8_t* seed, size_t seedSize)
+    {
+        if (!seed)
+        {
+            oclog() <<"seed can not be null";
+            return OC_STACK_INVALID_PARAM;
+        }
+
+        OCStackResult result;
+        auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+        if (cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = SetDeviceIdSeed(seed, seedSize);
+        }
+        else
+        {
+            oclog() <<"Mutex not found";
+            result = OC_STACK_ERROR;
+        }
+        return result;
+    }
 #endif // __WITH_DTLS__ || __WITH_TLS__
 
     void OCSecureResource::callbackWrapper(void* ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
index 61b4499..09086a1 100644 (file)
@@ -250,4 +250,25 @@ namespace OCProvisioningTest
         OCSecureResource device;
         EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionDirectPairing(nullptr, nullptr));
     }
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+    TEST(setDeviceIdSeed, NullParam)
+    {
+        EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setDeviceIdSeed(NULL, 0));
+    }
+
+    TEST(setDeviceIdSeed, InvalidParam)
+    {
+        uint8_t seed[1024] = {0};
+
+        EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setDeviceIdSeed(seed, 0));
+        EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setDeviceIdSeed(seed, sizeof(seed)));
+    }
+
+    TEST(setDeviceIdSeed, ValidValue)
+    {
+        uint8_t seed[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+                            0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10};
+        EXPECT_EQ(OC_STACK_OK, OCSecure::setDeviceIdSeed(seed, sizeof(seed)));
+    }
+#endif // __WITH_DTLS__ || __WITH_TLS__
 }