TuyaOS
cloud_storage.h
浏览该文件的文档.
1
12#ifndef __CLOUD_STORAGE_H__
13#define __CLOUD_STORAGE_H__
14
15#include "tuya_cloud_types.h"
16#include "ty_cJSON.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define AES128_CBC_LEN_WITH_PKCS7(len) ((len) + (16 - (len) % 16))
23#define CLOUD_STORAGE_ENC_LEN(len) AES128_CBC_LEN_WITH_PKCS7(len)
24
25struct storage_ctx;
26typedef struct storage_ctx storage_ctx;
27
39OPERATE_RET cloud_storage_backup_simple(CONST CHAR_T *dev_id,
40 CONST CHAR_T *scene_code,
41 CONST CHAR_T *file_name,
42 BOOL_T encrypt,
43 BYTE_T *data,
44 UINT_T data_len);
45
57OPERATE_RET cloud_storage_restore_simple(CONST CHAR_T *dev_id,
58 CONST CHAR_T *scene_code,
59 CONST CHAR_T *file_name,
60 BOOL_T encrypt,
61 BYTE_T **out_data,
62 UINT_T *out_len);
63
72OPERATE_RET cloud_storage_destory_simple(CONST CHAR_T *dev_id,
73 CONST CHAR_T *scene_code,
74 CONST CHAR_T *file_name);
75
85OPERATE_RET cloud_storage_is_backup_exist(CONST CHAR_T *dev_id,
86 CONST CHAR_T *scene_code,
87 CONST CHAR_T *file_name,
88 BOOL_T *exist);
89
99OPERATE_RET cloud_storage_meta_data_get(CONST CHAR_T *dev_id,
100 CONST CHAR_T *scene_code,
101 CONST CHAR_T * file_name,
102 ty_cJSON **result);
103
112storage_ctx *cloud_storage_ctx_new(CONST CHAR_T *dev_id,
113 CONST CHAR_T *scene_code,
114 CONST CHAR_T *file_name);
115
122OPERATE_RET cloud_storage_ctx_free(storage_ctx *ctx);
123
130OPERATE_RET cloud_storage_backup_prepare(storage_ctx *ctx);
131
141OPERATE_RET cloud_storage_backup(storage_ctx *ctx,
142 BYTE_T *data,
143 UINT_T data_len,
144 BOOL_T encrypt);
145
153OPERATE_RET cloud_storage_backup_raw_begin(storage_ctx *ctx, UINT_T data_total_len);
154
164OPERATE_RET cloud_storage_backup_raw_write(storage_ctx *ctx,
165 BYTE_T *data,
166 UINT_T data_len,
167 BOOL_T encrypt);
168
175OPERATE_RET cloud_storage_backup_raw_end(storage_ctx *ctx);
176
183OPERATE_RET cloud_storage_backup_post(storage_ctx *ctx);
184
191OPERATE_RET cloud_storage_restore_prepare(storage_ctx *ctx);
192
202OPERATE_RET cloud_storage_restore(storage_ctx *ctx,
203 BYTE_T **out_data,
204 UINT_T *out_len,
205 BOOL_T encrypt);
206
213OPERATE_RET cloud_storage_restore_post(storage_ctx *ctx);
214
221OPERATE_RET cloud_storage_destory_prepare(storage_ctx *ctx);
222
229OPERATE_RET cloud_storage_destory(storage_ctx *ctx);
230
237OPERATE_RET cloud_storage_destory_post(storage_ctx *ctx);
238
245CONST CHAR_T *cloud_storage_secret_key_get(IN CONST storage_ctx *ctx);
246
254VOID cloud_storage_secret_key_set(IN storage_ctx *ctx, IN CONST CHAR_T *key);
255
262BOOL_T cloud_storage_is_secret_key_exist(IN CONST storage_ctx *ctx);
263
270CONST CHAR_T *cloud_storage_secret_iv_get(IN CONST storage_ctx *ctx);
271
279VOID cloud_storage_secret_iv_set(IN storage_ctx *ctx, IN CONST CHAR_T *iv);
280
287CONST CHAR_T *cloud_storage_get_sign_url(IN CONST storage_ctx *ctx);
288
299OPERATE_RET cloud_storage_aes128_cbc_encrypt(IN CONST storage_ctx *ctx,
300 IN BYTE_T *data, IN CONST UINT_T len,
301 OUT BYTE_T **ec_data, OUT UINT_T *ec_len);
302
313OPERATE_RET cloud_storage_aes128_cbc_decrypt(IN CONST storage_ctx *ctx,
314 IN BYTE_T *data, IN CONST UINT_T len,
315 OUT BYTE_T **dec_data, OUT UINT_T *dec_len);
316#ifdef __cplusplus
317}
318#endif
319
320#endif
OPERATE_RET cloud_storage_is_backup_exist(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name, BOOL_T *exist)
Checking backup data exist
BOOL_T cloud_storage_is_secret_key_exist(IN CONST storage_ctx *ctx)
Checking secret key is exist
OPERATE_RET cloud_storage_destory_simple(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name)
Data destory(simple mode)
OPERATE_RET cloud_storage_restore_prepare(storage_ctx *ctx)
Prepare for data restore
OPERATE_RET cloud_storage_backup_raw_begin(storage_ctx *ctx, UINT_T data_total_len)
Backup data prepare
VOID cloud_storage_secret_iv_set(IN storage_ctx *ctx, IN CONST CHAR_T *iv)
OPERATE_RET cloud_storage_backup_raw_end(storage_ctx *ctx)
Data backup
OPERATE_RET cloud_storage_backup_prepare(storage_ctx *ctx)
backup prepare
OPERATE_RET cloud_storage_meta_data_get(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name, ty_cJSON **result)
Get file meta data(json formatted)
OPERATE_RET cloud_storage_destory_prepare(storage_ctx *ctx)
Data destory prepare
OPERATE_RET cloud_storage_restore(storage_ctx *ctx, BYTE_T **out_data, UINT_T *out_len, BOOL_T encrypt)
Data restore
storage_ctx * cloud_storage_ctx_new(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name)
create storage context
OPERATE_RET cloud_storage_aes128_cbc_decrypt(IN CONST storage_ctx *ctx, IN BYTE_T *data, IN CONST UINT_T len, OUT BYTE_T **dec_data, OUT UINT_T *dec_len)
AES128-CBC Decrypt
OPERATE_RET cloud_storage_restore_post(storage_ctx *ctx)
Data restore postpone
OPERATE_RET cloud_storage_backup_post(storage_ctx *ctx)
Data backup postpone
OPERATE_RET cloud_storage_backup_simple(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name, BOOL_T encrypt, BYTE_T *data, UINT_T data_len)
Data backup(simple mode)
VOID cloud_storage_secret_key_set(IN storage_ctx *ctx, IN CONST CHAR_T *key)
Set secret key
OPERATE_RET cloud_storage_backup_raw_write(storage_ctx *ctx, BYTE_T *data, UINT_T data_len, BOOL_T encrypt)
Backup data to the cloud in raw mode
OPERATE_RET cloud_storage_restore_simple(CONST CHAR_T *dev_id, CONST CHAR_T *scene_code, CONST CHAR_T *file_name, BOOL_T encrypt, BYTE_T **out_data, UINT_T *out_len)
Data restore(simple mode)
OPERATE_RET cloud_storage_ctx_free(storage_ctx *ctx)
release storage context resource
OPERATE_RET cloud_storage_aes128_cbc_encrypt(IN CONST storage_ctx *ctx, IN BYTE_T *data, IN CONST UINT_T len, OUT BYTE_T **ec_data, OUT UINT_T *ec_len)
AES128-CBC Encrypt
OPERATE_RET cloud_storage_destory_post(storage_ctx *ctx)
Data destory postpone
CONST CHAR_T * cloud_storage_secret_key_get(IN CONST storage_ctx *ctx)
Get secret key
OPERATE_RET cloud_storage_destory(storage_ctx *ctx)
Data destory
OPERATE_RET cloud_storage_backup(storage_ctx *ctx, BYTE_T *data, UINT_T data_len, BOOL_T encrypt)
backup uploading
CONST CHAR_T * cloud_storage_get_sign_url(IN CONST storage_ctx *ctx)
获取签名URL, 返回值生命周期与ctx关联
CONST CHAR_T * cloud_storage_secret_iv_get(IN CONST storage_ctx *ctx)
Fetch IV, for AES128-CBC
Definition: ty_cJSON.h:104