replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / psinterface.h
index 493690a..ae228bf 100644 (file)
 #ifndef IOTVT_SRM_PSI_H
 #define IOTVT_SRM_PSI_H
 
+#if defined (__TIZENRT__)
+#include <apps/netutils/cJSON.h>
+#else
 #include "cJSON.h"
+#endif
+
+// Persistent Storage status definition
+typedef enum
+{
+    PS_NORMAL = 0,      // Persistent Storage operating normally
+    PS_OPEN_FAIL,       // Failed to open persistent storage
+    PS_PARSE_FAIL,     // Failed to cbor parse persistent storage
+    PS_NO_EXTERNAL_DB_SET = 99, // no external DB set (initial state)
+} PSStatus_t;
 
 /**
  * Reads the Secure Virtual Database from PS into dynamically allocated
@@ -61,6 +74,20 @@ OCStackResult UpdateSVRDatabase(const char* rsrcName, cJSON* jsonObj);
 OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **data, size_t *size);
 
 /**
+ * Gets the Secure Virtual Database from the Persistent Storage
+ *
+ * @param ps - Persistent Storage handler
+ * @param rsrcName - pointer of character string for the SVR name (e.g. "acl")
+ * @param data - pointer of the returned Secure Virtual Resource(s)
+ * @param size - pointer of the returned size of Secure Virtual Resource(s)
+ *
+ * @return OCStackResult - result of getting Secure Virtual Resource(s)
+ */
+OCStackResult GetSecureVirtualDatabaseFromPS2(OCPersistentStorage* ps, const char *rsrcName,
+                                              uint8_t **data, size_t *size);
+
+
+/**
  * This method converts updates the persistent storage.
  *
  * @param rsrcName is the name of the secure resource that will be updated.
@@ -69,7 +96,7 @@ OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **dat
  *
  * @return ::OC_STACK_OK for Success, otherwise some error value
  */
-OCStackResult UpdateSecureResourceInPS(const char* rsrcName, uint8_t* cborPayload, size_t size);
+OCStackResult UpdateSecureResourceInPS(const char* rsrcName, const uint8_t* cborPayload, size_t size);
 
 /**
  * This method resets the secure resources according to the reset profile.
@@ -88,4 +115,41 @@ OCStackResult ResetSecureResourceInPS(void);
  */
 OCStackResult CreateResetProfile(void);
 
+/**
+ * This method sets the persistent storage status.
+ *
+ * @param status is the current persistent storage status
+ */
+void SetPSStatus(PSStatus_t status);
+
+/**
+ * This method prints debug log that displays persistent storage status.
+ */
+void PrintPSStatus(void);
+
+/**
+ * Init the Persistent Storage Database.
+ */
+OCStackResult InitPersistentStorageInterface(void);
+
+/**
+ * DeInit the Persistent Storage Database.
+ */
+void DeinitPersistentStorageInterface(void);
+
+/**
+ * API to encrypt the un-encrypted DB file before OCRegisterPersistentStorageHandler
+ * If the API is successful, un-encrypted file will be removed, and if the encrypted file
+ * is currupted, then it restores encrypted file using rescue file.
+ *
+ * @param[in] key key used for encryption
+ * @param[in] psPlain OCPersistentStorage for the plain DB
+ * @param[in] psEnc OCPersistentStorage for the encrypted DB
+ * @param[in] psRescue OCPersistentStorage for the rescue DB
+ *
+ * @return ::OC_STACK_OK on success and other value otherwise.
+ */
+OCStackResult setSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
+        const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue);
+
 #endif //IOTVT_SRM_PSI_H