Move example app to documentation 77/234777/9
authorDariusz Michaluk <d.michaluk@samsung.com>
Thu, 28 May 2020 11:55:34 +0000 (13:55 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Mon, 6 Jul 2020 09:59:38 +0000 (11:59 +0200)
Change-Id: I73832e912bc78ed55c9a4a57550b76173f06d861

README.md
doc/device_certificate_manager_doc.h
doc/device_certificate_manager_example.c [new file with mode: 0644]
packaging/device-certificate-manager.spec
tests/CMakeLists.txt
tests/example_capi.c [deleted file]

index 6c5f2aa..7990f6e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -39,11 +39,9 @@ The most important item is to implement the *libdcm-backend-api.so* library and
 The DCM daemon does not need to be modified.
 
 ##Testing
-
-There are currently two general testing applications and one KONAI SE specific tool:
+There is currently one general testing application and one KONAI SE specific tool:
 - *dcm_api_test*
-- *dcm_example_capi*
-All testing applications should be executed after implementing changes to the DCM or to the DCM backend repository.
+Testing application should be executed after implementing changes to the DCM or to the DCM backend repository.
 
 There is also one KONAI SE specific tool: *dcm_konaise_tool* used to test the KONAI SE backend implementation.
 The list of examples of execution of the *dcm_konaise_tool* is displayed after running the tool in the command line without any arguments.
index abe943f..02150df 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************
  *
- * Copyright 2018 Samsung Electronics All Rights Reserved.
+ * Copyright 2018 - 2020 Samsung Electronics All Rights Reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
   * To ensure your application is running only on devices with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
   * More details on using features in your application can be found in the <a href="https://docs.tizen.org/application/tizen-studio/native-tools/manifest-text-editor#feature-element"><b>feature element description</b></a>.
   *
-  * @section CAPI_PRIVACY_PRIVILEGE_MANAGER_MODULE_OVERVIEW Overview
+  * @section CAPI_DEVICE_CERTIFICATE_MANAGER_MODULE_OVERVIEW Overview
   * Device Certificate Manager provides cryptography services (digital certificates and keys)
   * for authentication and secure communication with another system.
   * Device certificate and key was embedded in device storage.
   *
+  * @section CAPI_DEVICE_CERTIFICATE_MANAGER_MODULE_EXAMPLES Examples
+  * Device Certificate Manager API example
+  * @snippet device_certificate_manager_example.c Device Certificate Manager API example
+  *
   */
 
 #endif /* __TIZEN_CORE_DEVICE_CERTIFICATE_MANAGER_DOC_H__ */
diff --git a/doc/device_certificate_manager_example.c b/doc/device_certificate_manager_example.c
new file mode 100644 (file)
index 0000000..291aeaa
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************
+ *
+ * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+/**
+ * @file device_certificate_manager_example.c
+ * @brief Device Certificate Manager API example.
+ */
+
+//! [Device Certificate Manager API example]
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "device_certificate_manager.h"
+
+int main()
+{
+    int result;
+    void *key_ctx = NULL;
+    char *key_type = NULL;
+    size_t key_len;
+    char *cert_chain = NULL;
+    size_t cert_chain_len;
+    char *signature = NULL;
+    size_t signature_len;
+
+    result = dcm_create_key_context("example_client", "test_usage", "", &key_ctx);
+    if (result != DCM_ERROR_NONE) {
+        printf("Can't create context\n");
+        goto exit;
+    }
+
+    result = dcm_get_certificate_chain(key_ctx, &cert_chain, &cert_chain_len);
+    if (result != DCM_ERROR_NONE) {
+        printf("Can't get cert chain\n");
+        goto exit;
+    }
+    printf("Cert is %zu bytes\n", cert_chain_len);
+    printf("Received cert %s\n", cert_chain);
+
+    result = dcm_get_key_type(key_ctx, &key_type);
+    if (result != DCM_ERROR_NONE) {
+        printf("Can't get key type\n");
+        goto exit;
+    }
+
+    result = dcm_get_key_bit_length(key_ctx, &key_len);
+    if (result != DCM_ERROR_NONE) {
+        printf("Can't get key length\n");
+        goto exit;
+    }
+    printf("Private key is %zu bits\n", key_len);
+    printf("Private key is %s\n", key_type);
+
+    result = dcm_create_signature(key_ctx, DCM_DIGEST_SHA256, "12345678901234567890123456789012", 32, &signature, &signature_len);
+    if (result != DCM_ERROR_NONE) {
+        printf("Can't create signature\n");
+        goto exit;
+    }
+
+    for(unsigned int i = 0; i < signature_len; i++) {
+        printf("%x ", (int)(*(unsigned char*)(&signature[i])));
+    }
+    printf("\n");
+
+exit:
+    free(signature);
+    free(cert_chain);
+    free(key_type);
+    dcm_free_key_context(key_ctx);
+
+    return result;
+}
+//! [Device Certificate Manager API example]
index 60d355f..77b2120 100644 (file)
@@ -126,4 +126,3 @@ fi
 %manifest %{name}.manifest
 %license LICENSE
 %{_bindir}/dcm_api_test
-%{_bindir}/dcm_example_capi
index 370cbec..b0425f5 100644 (file)
@@ -27,15 +27,11 @@ INCLUDE_DIRECTORIES(../dcm-client)
 ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
 ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
 
-ADD_EXECUTABLE(dcm_example_capi example_capi.c)
-TARGET_LINK_LIBRARIES(dcm_example_capi device-certificate-manager)
-
 ADD_EXECUTABLE(dcm_api_test api_test.cpp)
 TARGET_LINK_LIBRARIES(dcm_api_test
        device-certificate-manager
        ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
 
 INSTALL(TARGETS
-       dcm_example_capi
        dcm_api_test
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/tests/example_capi.c b/tests/example_capi.c
deleted file mode 100644 (file)
index 852dfc3..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/******************************************************************
- *
- * Copyright 2017 - 2019 Samsung Electronics All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "device_certificate_manager.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-int main()
-{
-       int result;
-       void *key_ctx = NULL;
-       char *key_type = NULL;
-       size_t key_len;
-       char *cert_chain = NULL;
-       size_t cert_chain_len;
-       char *signature = NULL;
-       size_t signature_len;
-
-       result = dcm_create_key_context("example_client", "test_usage", "", &key_ctx);
-       if(result != DCM_ERROR_NONE) {
-               printf("Can't create context\n");
-               goto exit;
-       }
-
-       result = dcm_get_key_type(key_ctx, &key_type);
-       if(result != DCM_ERROR_NONE) {
-               printf("Can't get key type\n");
-               goto exit;
-       }
-       printf("Using key type %s\n", key_type);
-
-       result = dcm_get_certificate_chain(key_ctx, &cert_chain, &cert_chain_len);
-       if(result != DCM_ERROR_NONE) {
-               printf("Can't get cert chain\n");
-               goto exit;
-       }
-       printf("Cert is %zu bytes\n", cert_chain_len);
-       printf("Received cert %s\n", cert_chain);
-
-       result = dcm_get_key_bit_length(key_ctx, &key_len);
-       if(result != DCM_ERROR_NONE) {
-               printf("Can't get key length\n");
-               goto exit;
-       }
-       printf("Private key is %zu bits\n", key_len);
-       printf("Private key is %s\n", key_type);
-
-       result = dcm_create_signature(key_ctx, DCM_DIGEST_SHA256, "12345678901234567890123456789012", 32, &signature, &signature_len);
-       if(result != DCM_ERROR_NONE) {
-               printf("Can't create signature\n");
-               goto exit;
-       }
-
-       for(unsigned int i = 0; i < signature_len; i++) {
-               printf("%x ", (int)(*(unsigned char*)(&signature[i])));
-       }
-       printf("\n");
-
-exit:
-       free(signature);
-       free(cert_chain);
-       free(key_type);
-       dcm_free_key_context(key_ctx);
-
-       return result;
-}