[IOT-2066] refactoring ConvertUuidToStr() 69/21669/7
authorv.riznyk <v.riznyk@samsung.com>
Fri, 28 Jul 2017 14:39:56 +0000 (17:39 +0300)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 8 Aug 2017 04:34:30 +0000 (04:34 +0000)
Change-Id: If5543c617c3f40193604349ea42df82be5645055
Signed-off-by: v.riznyk <v.riznyk@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21669
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/srmutility.c

index 53d7739..0bc6e18 100644 (file)
@@ -114,26 +114,16 @@ OCStackResult ConvertUuidToStr(const OicUuid_t* uuid, char** strUuid)
         return OC_STACK_INVALID_PARAM;
     }
 
-    size_t uuidIdx = 0;
-    size_t urnIdx = 0;
     const size_t urnBufSize = (UUID_LENGTH * 2) + 4 + 1;
     char* convertedUrn = (char*)OICCalloc(urnBufSize, sizeof(char));
     VERIFY_NOT_NULL(TAG, convertedUrn, ERROR);
-
-    for(uuidIdx=0, urnIdx=0;  uuidIdx < UUID_LENGTH && urnIdx < urnBufSize; uuidIdx++, urnIdx+=2)
+    if(OCConvertUuidToString(uuid->id,convertedUrn))
     {
-        // canonical format for UUID has '8-4-4-4-12'
-        if(uuidIdx==4 || uuidIdx==6 || uuidIdx==8 || uuidIdx==10)
-        {
-            snprintf(convertedUrn + urnIdx, 2, "%c", '-');
-            urnIdx++;
-        }
-        snprintf(convertedUrn + urnIdx, 3, "%02x", (uint8_t)(uuid->id[uuidIdx]));
+        *strUuid = convertedUrn;
+        return OC_STACK_OK;
     }
-    convertedUrn[urnBufSize - 1] = '\0';
 
-    *strUuid = convertedUrn;
-    return OC_STACK_OK;
+    return OC_STACK_INVALID_PARAM;
 
 exit:
     return OC_STACK_NO_MEMORY;