• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _HKS_FILE_API_H
17 #define _HKS_FILE_API_H
18 
19 #include <stdint.h>
20 #include "hks_types.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct hks_file_callbacks {
27     /*
28      * Read data from file or flash
29      *
30      * filename: The path name of the file
31      * offset: param reserved for future use
32      * buf: The buffer used to store the content readed from the file
33      * len: The size count in buffer trying to read from the file
34      * return < 0 read error, return > 0 real read length,
35      * return == 0 secret key information does not exist in storage media
36      */
37     int32_t (*read)(const char *file_name, uint32_t offset,
38         uint8_t *buf, uint32_t len);
39 
40     /*
41      * Write data into file or flash
42      *
43      * filename: The path name of the file
44      * offset: param reserved for future use
45      * buf: The content which you want write into the file
46      * len: The size of the content
47      * return == 0 write ok, return < 0 other error
48      */
49     int32_t (*write)(const char *file_name, uint32_t offset,
50         const uint8_t *buf, uint32_t len);
51 
52     /*
53      * Get file size
54      *
55      * filename: The path name of the file
56      * return  < 0 error, >= 0 The size of the file
57      * flash can return a fixed value of 4096
58      */
59     int32_t (*file_size)(const char *file_name);
60 };
61 
62 /*
63  * Register file operation callbacks
64  *
65  * callbacks: The callback functions for file operation
66  * return 0 ok, other error
67  */
68 #ifndef HKS_API_PUBLIC
69 #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
70 #ifdef HKS_DLL_EXPORT
71 __declspec(dllexport) int32_t hks_register_file_callbacks(
72     struct hks_file_callbacks *callbacks);
73 #else
74 __declspec(dllimport) int32_t hks_register_file_callbacks(
75     struct hks_file_callbacks *callbacks);
76 #endif
77 #else
78 __attribute__((visibility("default"))) int32_t hks_register_file_callbacks(
79     struct hks_file_callbacks *callbacks);
80 #endif
81 #else
82 __attribute__((visibility("default"))) int32_t hks_register_file_callbacks(
83     struct hks_file_callbacks *callbacks);
84 #endif
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* _HKS_FILE_API_H */
91