libthemis_sys/
lib.rs

1// Copyright 2018 (c) rust-themis developers
2//
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//! Raw FFI bindings to libthemis.
16
17#![allow(non_upper_case_globals)]
18#![allow(non_camel_case_types)]
19#![allow(non_snake_case)]
20// For some weird reasons Clippy gets run on this crate as it's a path dependency of themis.
21// This should not happen (see https://github.com/rust-lang-nursery/rust-clippy/issues/1066)
22// but until that's fixed again, disable all lints which get triggered by the code generated
23// by bindgen.
24#![allow(clippy::all)]
25
26// DO NOT EDIT.
27//
28// This file is automatically generated by "bindgen.sh".
29// Instead of editing it by hand, rerun the script.
30
31pub const THEMIS_SUCCESS: u32 = 0;
32pub const THEMIS_SSESSION_SEND_OUTPUT_TO_PEER: u32 = 1;
33pub const THEMIS_FAIL: u32 = 11;
34pub const THEMIS_INVALID_PARAMETER: u32 = 12;
35pub const THEMIS_NO_MEMORY: u32 = 13;
36pub const THEMIS_BUFFER_TOO_SMALL: u32 = 14;
37pub const THEMIS_DATA_CORRUPT: u32 = 15;
38pub const THEMIS_INVALID_SIGNATURE: u32 = 16;
39pub const THEMIS_NOT_SUPPORTED: u32 = 17;
40pub const THEMIS_SSESSION_KA_NOT_FINISHED: u32 = 19;
41pub const THEMIS_SSESSION_TRANSPORT_ERROR: u32 = 20;
42pub const THEMIS_SSESSION_GET_PUB_FOR_ID_CALLBACK_ERROR: u32 = 21;
43pub const THEMIS_SCOMPARE_SEND_OUTPUT_TO_PEER: u32 = 1;
44pub const THEMIS_SCOMPARE_MATCH: u32 = 21;
45pub const THEMIS_SCOMPARE_NO_MATCH: u32 = 22;
46pub const THEMIS_SCOMPARE_NOT_READY: u32 = 0;
47pub const STATE_IDLE: u32 = 0;
48pub const STATE_NEGOTIATING: u32 = 1;
49pub const STATE_ESTABLISHED: u32 = 2;
50pub type __uint8_t = ::std::os::raw::c_uchar;
51pub type __int32_t = ::std::os::raw::c_int;
52pub type __ssize_t = ::std::os::raw::c_long;
53pub type themis_status_t = i32;
54extern "C" {
55    pub fn themis_secure_cell_encrypt_seal(
56        master_key: *const u8,
57        master_key_length: usize,
58        user_context: *const u8,
59        user_context_length: usize,
60        message: *const u8,
61        message_length: usize,
62        encrypted_message: *mut u8,
63        encrypted_message_length: *mut usize,
64    ) -> themis_status_t;
65}
66extern "C" {
67    pub fn themis_secure_cell_decrypt_seal(
68        master_key: *const u8,
69        master_key_length: usize,
70        user_context: *const u8,
71        user_context_length: usize,
72        encrypted_message: *const u8,
73        encrypted_message_length: usize,
74        plain_message: *mut u8,
75        plain_message_length: *mut usize,
76    ) -> themis_status_t;
77}
78extern "C" {
79    pub fn themis_secure_cell_encrypt_seal_with_passphrase(
80        passphrase: *const u8,
81        passphrase_length: usize,
82        user_context: *const u8,
83        user_context_length: usize,
84        message: *const u8,
85        message_length: usize,
86        encrypted_message: *mut u8,
87        encrypted_message_length: *mut usize,
88    ) -> themis_status_t;
89}
90extern "C" {
91    pub fn themis_secure_cell_decrypt_seal_with_passphrase(
92        passphrase: *const u8,
93        passphrase_length: usize,
94        user_context: *const u8,
95        user_context_length: usize,
96        encrypted_message: *const u8,
97        encrypted_message_length: usize,
98        plain_message: *mut u8,
99        plain_message_length: *mut usize,
100    ) -> themis_status_t;
101}
102extern "C" {
103    pub fn themis_secure_cell_encrypt_token_protect(
104        master_key: *const u8,
105        master_key_length: usize,
106        user_context: *const u8,
107        user_context_length: usize,
108        message: *const u8,
109        message_length: usize,
110        context: *mut u8,
111        context_length: *mut usize,
112        encrypted_message: *mut u8,
113        encrypted_message_length: *mut usize,
114    ) -> themis_status_t;
115}
116extern "C" {
117    pub fn themis_secure_cell_decrypt_token_protect(
118        master_key: *const u8,
119        master_key_length: usize,
120        user_context: *const u8,
121        user_context_length: usize,
122        encrypted_message: *const u8,
123        encrypted_message_length: usize,
124        context: *const u8,
125        context_length: usize,
126        plain_message: *mut u8,
127        plain_message_length: *mut usize,
128    ) -> themis_status_t;
129}
130extern "C" {
131    pub fn themis_secure_cell_encrypt_context_imprint(
132        master_key: *const u8,
133        master_key_length: usize,
134        message: *const u8,
135        message_length: usize,
136        context: *const u8,
137        context_length: usize,
138        encrypted_message: *mut u8,
139        encrypted_message_length: *mut usize,
140    ) -> themis_status_t;
141}
142extern "C" {
143    pub fn themis_secure_cell_decrypt_context_imprint(
144        master_key: *const u8,
145        master_key_length: usize,
146        encrypted_message: *const u8,
147        encrypted_message_length: usize,
148        context: *const u8,
149        context_length: usize,
150        plain_message: *mut u8,
151        plain_message_length: *mut usize,
152    ) -> themis_status_t;
153}
154#[repr(C)]
155#[derive(Debug, Copy, Clone)]
156pub struct secure_comparator_type {
157    _unused: [u8; 0],
158}
159pub type secure_comparator_t = secure_comparator_type;
160extern "C" {
161    pub fn secure_comparator_create() -> *mut secure_comparator_t;
162}
163extern "C" {
164    pub fn secure_comparator_destroy(comp_ctx: *mut secure_comparator_t) -> themis_status_t;
165}
166extern "C" {
167    pub fn secure_comparator_append_secret(
168        comp_ctx: *mut secure_comparator_t,
169        secret_data: *const ::std::os::raw::c_void,
170        secret_data_length: usize,
171    ) -> themis_status_t;
172}
173extern "C" {
174    pub fn secure_comparator_begin_compare(
175        comp_ctx: *mut secure_comparator_t,
176        compare_data: *mut ::std::os::raw::c_void,
177        compare_data_length: *mut usize,
178    ) -> themis_status_t;
179}
180extern "C" {
181    pub fn secure_comparator_proceed_compare(
182        comp_ctx: *mut secure_comparator_t,
183        peer_compare_data: *const ::std::os::raw::c_void,
184        peer_compare_data_length: usize,
185        compare_data: *mut ::std::os::raw::c_void,
186        compare_data_length: *mut usize,
187    ) -> themis_status_t;
188}
189extern "C" {
190    pub fn secure_comparator_get_result(comp_ctx: *const secure_comparator_t) -> themis_status_t;
191}
192extern "C" {
193    pub fn themis_gen_sym_key(key: *mut u8, key_length: *mut usize) -> themis_status_t;
194}
195extern "C" {
196    pub fn themis_gen_rsa_key_pair(
197        private_key: *mut u8,
198        private_key_length: *mut usize,
199        public_key: *mut u8,
200        public_key_length: *mut usize,
201    ) -> themis_status_t;
202}
203extern "C" {
204    pub fn themis_gen_ec_key_pair(
205        private_key: *mut u8,
206        private_key_length: *mut usize,
207        public_key: *mut u8,
208        public_key_length: *mut usize,
209    ) -> themis_status_t;
210}
211#[repr(u32)]
212#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
213pub enum themis_key_kind {
214    THEMIS_KEY_INVALID = 0,
215    THEMIS_KEY_RSA_PRIVATE = 1,
216    THEMIS_KEY_RSA_PUBLIC = 2,
217    THEMIS_KEY_EC_PRIVATE = 3,
218    THEMIS_KEY_EC_PUBLIC = 4,
219}
220pub use self::themis_key_kind as themis_key_kind_t;
221extern "C" {
222    pub fn themis_get_asym_key_kind(key: *const u8, length: usize) -> themis_key_kind_t;
223}
224extern "C" {
225    pub fn themis_is_valid_asym_key(key: *const u8, length: usize) -> themis_status_t;
226}
227extern "C" {
228    pub fn themis_secure_message_encrypt(
229        private_key: *const u8,
230        private_key_length: usize,
231        public_key: *const u8,
232        public_key_length: usize,
233        message: *const u8,
234        message_length: usize,
235        encrypted_message: *mut u8,
236        encrypted_message_length: *mut usize,
237    ) -> themis_status_t;
238}
239extern "C" {
240    pub fn themis_secure_message_decrypt(
241        private_key: *const u8,
242        private_key_length: usize,
243        public_key: *const u8,
244        public_key_length: usize,
245        encrypted_message: *const u8,
246        encrypted_message_length: usize,
247        message: *mut u8,
248        message_length: *mut usize,
249    ) -> themis_status_t;
250}
251extern "C" {
252    pub fn themis_secure_message_sign(
253        private_key: *const u8,
254        private_key_length: usize,
255        message: *const u8,
256        message_length: usize,
257        signed_message: *mut u8,
258        signed_message_length: *mut usize,
259    ) -> themis_status_t;
260}
261extern "C" {
262    pub fn themis_secure_message_verify(
263        public_key: *const u8,
264        public_key_length: usize,
265        signed_message: *const u8,
266        signed_message_length: usize,
267        message: *mut u8,
268        message_length: *mut usize,
269    ) -> themis_status_t;
270}
271extern "C" {
272    pub fn themis_secure_message_wrap(
273        private_key: *const u8,
274        private_key_length: usize,
275        public_key: *const u8,
276        public_key_length: usize,
277        message: *const u8,
278        message_length: usize,
279        wrapped_message: *mut u8,
280        wrapped_message_length: *mut usize,
281    ) -> themis_status_t;
282}
283extern "C" {
284    pub fn themis_secure_message_unwrap(
285        private_key: *const u8,
286        private_key_length: usize,
287        public_key: *const u8,
288        public_key_length: usize,
289        wrapped_message: *const u8,
290        wrapped_message_length: usize,
291        message: *mut u8,
292        message_length: *mut usize,
293    ) -> themis_status_t;
294}
295pub type send_protocol_data_callback = ::std::option::Option<
296    unsafe extern "C" fn(
297        data: *const u8,
298        data_length: usize,
299        user_data: *mut ::std::os::raw::c_void,
300    ) -> isize,
301>;
302pub type receive_protocol_data_callback = ::std::option::Option<
303    unsafe extern "C" fn(
304        data: *mut u8,
305        data_length: usize,
306        user_data: *mut ::std::os::raw::c_void,
307    ) -> isize,
308>;
309pub type protocol_state_changed_callback = ::std::option::Option<
310    unsafe extern "C" fn(event: ::std::os::raw::c_int, user_data: *mut ::std::os::raw::c_void),
311>;
312pub type get_public_key_for_id_callback = ::std::option::Option<
313    unsafe extern "C" fn(
314        id: *const ::std::os::raw::c_void,
315        id_length: usize,
316        key_buffer: *mut ::std::os::raw::c_void,
317        key_buffer_length: usize,
318        user_data: *mut ::std::os::raw::c_void,
319    ) -> ::std::os::raw::c_int,
320>;
321#[repr(C)]
322#[derive(Debug, Copy, Clone)]
323pub struct secure_session_user_callbacks_type {
324    pub send_data: send_protocol_data_callback,
325    pub receive_data: receive_protocol_data_callback,
326    pub state_changed: protocol_state_changed_callback,
327    pub get_public_key_for_id: get_public_key_for_id_callback,
328    pub user_data: *mut ::std::os::raw::c_void,
329}
330pub type secure_session_user_callbacks_t = secure_session_user_callbacks_type;
331#[repr(C)]
332#[derive(Debug, Copy, Clone)]
333pub struct secure_session_type {
334    _unused: [u8; 0],
335}
336pub type secure_session_t = secure_session_type;
337extern "C" {
338    pub fn secure_session_create(
339        id: *const ::std::os::raw::c_void,
340        id_length: usize,
341        sign_key: *const ::std::os::raw::c_void,
342        sign_key_length: usize,
343        user_callbacks: *const secure_session_user_callbacks_t,
344    ) -> *mut secure_session_t;
345}
346extern "C" {
347    pub fn secure_session_destroy(session_ctx: *mut secure_session_t) -> themis_status_t;
348}
349extern "C" {
350    pub fn secure_session_connect(session_ctx: *mut secure_session_t) -> themis_status_t;
351}
352extern "C" {
353    pub fn secure_session_generate_connect_request(
354        session_ctx: *mut secure_session_t,
355        output: *mut ::std::os::raw::c_void,
356        output_length: *mut usize,
357    ) -> themis_status_t;
358}
359extern "C" {
360    pub fn secure_session_wrap(
361        session_ctx: *mut secure_session_t,
362        message: *const ::std::os::raw::c_void,
363        message_length: usize,
364        wrapped_message: *mut ::std::os::raw::c_void,
365        wrapped_message_length: *mut usize,
366    ) -> themis_status_t;
367}
368extern "C" {
369    pub fn secure_session_unwrap(
370        session_ctx: *mut secure_session_t,
371        wrapped_message: *const ::std::os::raw::c_void,
372        wrapped_message_length: usize,
373        message: *mut ::std::os::raw::c_void,
374        message_length: *mut usize,
375    ) -> themis_status_t;
376}
377extern "C" {
378    pub fn secure_session_send(
379        session_ctx: *mut secure_session_t,
380        message: *const ::std::os::raw::c_void,
381        message_length: usize,
382    ) -> isize;
383}
384extern "C" {
385    pub fn secure_session_receive(
386        session_ctx: *mut secure_session_t,
387        message: *mut ::std::os::raw::c_void,
388        message_length: usize,
389    ) -> isize;
390}
391extern "C" {
392    pub fn secure_session_save(
393        session_ctx: *const secure_session_t,
394        out: *mut ::std::os::raw::c_void,
395        out_length: *mut usize,
396    ) -> themis_status_t;
397}
398extern "C" {
399    pub fn secure_session_load(
400        session_ctx: *mut secure_session_t,
401        in_: *const ::std::os::raw::c_void,
402        in_length: usize,
403        user_callbacks: *const secure_session_user_callbacks_t,
404    ) -> themis_status_t;
405}
406extern "C" {
407    pub fn secure_session_is_established(session_ctx: *const secure_session_t) -> bool;
408}
409extern "C" {
410    pub fn secure_session_get_remote_id(
411        session_ctx: *const secure_session_t,
412        id: *mut u8,
413        id_length: *mut usize,
414    ) -> themis_status_t;
415}