Skip to main content

ohos_crypto_sys/sym_cipher/
sym_cipher_ffi.rs

1// automatically generated by rust-bindgen 0.71.1
2
3#![allow(non_upper_case_globals)]
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6use crate::common::{CryptoResult, Crypto_CipherMode, Crypto_DataBlob};
7use crate::sym_key::OH_CryptoSymKey;
8
9#[cfg(feature = "api-12")]
10#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
11impl CryptoSymCipher_ParamsType {
12    /// Indicates the parameters such as iv.
13    pub const CRYPTO_IV_DATABLOB: CryptoSymCipher_ParamsType = CryptoSymCipher_ParamsType(100);
14    /// Indicates the additional Authenticated Data in GCM mode.
15    pub const CRYPTO_AAD_DATABLOB: CryptoSymCipher_ParamsType = CryptoSymCipher_ParamsType(101);
16    /// Indicates the output tag from the encryption operation. The tag is used for integrity check.
17    pub const CRYPTO_TAG_DATABLOB: CryptoSymCipher_ParamsType = CryptoSymCipher_ParamsType(102);
18}
19#[repr(transparent)]
20/// Define the cipher param type.
21///
22///
23/// Available since API-level: 12
24#[cfg(feature = "api-12")]
25#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
26#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
27pub struct CryptoSymCipher_ParamsType(pub ::core::ffi::c_uint);
28/// Define the symmetric key cipher structure.
29///
30///
31/// Available since API-level: 12
32#[cfg(feature = "api-12")]
33#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
34#[repr(C)]
35pub struct OH_CryptoSymCipher {
36    _unused: [u8; 0],
37}
38/// Define the symmetric key cipher params structure.
39///
40///
41/// Available since API-level: 12
42#[cfg(feature = "api-12")]
43#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
44#[repr(C)]
45pub struct OH_CryptoSymCipherParams {
46    _unused: [u8; 0],
47}
48extern "C" {
49    /// Create a symmetric key cipher params.
50    ///
51    /// # Arguments
52    ///
53    /// * `params` - Indicates the pointer to the cipher params context.
54    ///
55    /// # Returns
56    ///
57    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
58    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
59    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
60    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
61    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
62    ///
63    /// Available since API-level: 12
64    #[cfg(feature = "api-12")]
65    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
66    pub fn OH_CryptoSymCipherParams_Create(
67        params: *mut *mut OH_CryptoSymCipherParams,
68    ) -> CryptoResult;
69    /// Set a parameter to the cipher params context.
70    ///
71    /// # Arguments
72    ///
73    /// * `params` - Indicates the parameters context.
74    ///
75    /// * `paramsType` - Set cipher parameters.
76    ///
77    /// * `value` - Indicates the setParam result.
78    ///
79    /// # Returns
80    ///
81    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
82    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
83    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
84    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
85    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
86    ///
87    /// Available since API-level: 12
88    #[cfg(feature = "api-12")]
89    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
90    pub fn OH_CryptoSymCipherParams_SetParam(
91        params: *mut OH_CryptoSymCipherParams,
92        paramsType: CryptoSymCipher_ParamsType,
93        value: *mut Crypto_DataBlob,
94    ) -> CryptoResult;
95    /// Destroy the cipher params context.
96    ///
97    /// # Arguments
98    ///
99    /// * `params` - Indicates the parameters context.
100    ///
101    /// Available since API-level: 12
102    #[cfg(feature = "api-12")]
103    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
104    pub fn OH_CryptoSymCipherParams_Destroy(params: *mut OH_CryptoSymCipherParams);
105    /// Create a symmetric key cipher context according to the given algorithm name.
106    ///
107    /// # Arguments
108    ///
109    /// * `algoName` - Indicates the algorithm name used to generate the symmetric key cipher context.
110    /// Example AES128|GCM|PKCS7.
111    ///
112    /// * `ctx` - Indicates the pointer to the symmetric key cipher context.
113    ///
114    /// # Returns
115    ///
116    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
117    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
118    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
119    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
120    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
121    ///
122    /// Available since API-level: 12
123    #[cfg(feature = "api-12")]
124    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
125    pub fn OH_CryptoSymCipher_Create(
126        algoName: *const ::core::ffi::c_char,
127        ctx: *mut *mut OH_CryptoSymCipher,
128    ) -> CryptoResult;
129    /// Init the crypto operation with the given crypto mode, key and parameters.
130    ///
131    /// # Arguments
132    ///
133    /// * `ctx` - Indicates the symmetric key cipher context.
134    ///
135    /// * `mod` - Indicates the crypto mode is encryption or decryption.
136    ///
137    /// * `key` - Indicates the symmetric key or the asymmetric key.
138    ///
139    /// * `params` - Indicates the algorithm parameters such as IV.
140    ///
141    /// # Returns
142    ///
143    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
144    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
145    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
146    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
147    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
148    /// [`OH_CryptoSymCipher_Update`] [`OH_CryptoSymCipher_Final`]
149    /// Available since API-level: 12
150    #[cfg(feature = "api-12")]
151    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
152    pub fn OH_CryptoSymCipher_Init(
153        ctx: *mut OH_CryptoSymCipher,
154        mod_: Crypto_CipherMode,
155        key: *mut OH_CryptoSymKey,
156        params: *mut OH_CryptoSymCipherParams,
157    ) -> CryptoResult;
158    /// Update the crypto operation with the input data, and feed back the encrypted or decrypted data.
159    ///
160    /// # Arguments
161    ///
162    /// * `ctx` - Indicates the symmetric key cipher context.
163    ///
164    /// * `in` - Indicates the data to be encrypted or decrypted.
165    ///
166    /// * `out` - Indicates the data to be update encrypted or decrypted.
167    ///
168    /// # Returns
169    ///
170    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
171    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
172    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
173    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
174    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
175    /// [`OH_CryptoSymCipher_Init`] [`OH_CryptoSymCipher_Final`]
176    /// Available since API-level: 12
177    #[cfg(feature = "api-12")]
178    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
179    pub fn OH_CryptoSymCipher_Update(
180        ctx: *mut OH_CryptoSymCipher,
181        in_: *mut Crypto_DataBlob,
182        out: *mut Crypto_DataBlob,
183    ) -> CryptoResult;
184    /// Finish the crypto operation, encrypt or decrypt the input data, and then feed back the output data.
185    ///
186    /// # Arguments
187    ///
188    /// * `ctx` - Indicates the symmetric key cipher context.
189    ///
190    /// * `in` - Indicates the data to be encrypted or decrypted.
191    ///
192    /// * `out` - Indicates the data to be finally encrypted or decrypted.
193    ///
194    /// # Returns
195    ///
196    /// * [`OH_Crypto_ErrCode#CRYPTO_SUCCESS`] 0 - If the operation is successful.
197    /// [`OH_Crypto_ErrCode#CRYPTO_INVALID_PARAMS`] 401 - If parameter is invalid.
198    /// [`OH_Crypto_ErrCode#CRYPTO_NOT_SUPPORTED`] 801 - If the operation is not supported.
199    /// [`OH_Crypto_ErrCode#CRYPTO_MEMORY_ERROR`] 17620001 - If memory operation failed.
200    /// [`OH_Crypto_ErrCode#CRYPTO_OPERTION_ERROR`] 17630001 - If crypto opertion failed.
201    /// [`OH_CryptoSymCipher_Init`] [`OH_CryptoSymCipher_Update`]
202    /// Available since API-level: 12
203    #[cfg(feature = "api-12")]
204    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
205    pub fn OH_CryptoSymCipher_Final(
206        ctx: *mut OH_CryptoSymCipher,
207        in_: *mut Crypto_DataBlob,
208        out: *mut Crypto_DataBlob,
209    ) -> CryptoResult;
210    /// Get the algorithm name of the symmetric key cipher context.
211    ///
212    /// # Arguments
213    ///
214    /// * `ctx` - Indicates the symmetric key context.
215    ///
216    /// # Returns
217    ///
218    /// * Return symmetric key cipher algorithm name.
219    ///
220    /// Available since API-level: 12
221    #[cfg(feature = "api-12")]
222    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
223    pub fn OH_CryptoSymCipher_GetAlgoName(
224        ctx: *mut OH_CryptoSymCipher,
225    ) -> *const ::core::ffi::c_char;
226    /// Destroy the symmetric key cipher context.
227    ///
228    /// # Arguments
229    ///
230    /// * `ctx` - Indicates the symmetric key context.
231    ///
232    /// Available since API-level: 12
233    #[cfg(feature = "api-12")]
234    #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))]
235    pub fn OH_CryptoSymCipher_Destroy(ctx: *mut OH_CryptoSymCipher);
236}