1extern "C" {
4 #[doc = " The number of slots in the password safe."]
5 pub static NK_PWS_SLOT_COUNT: u8;
6}
7pub const MAXIMUM_STR_REPLY_LENGTH: ::std::os::raw::c_int = 8192;
8#[doc = " Use, if no supported device is connected"]
9pub const NK_device_model_NK_DISCONNECTED: NK_device_model = 0;
10#[doc = " Nitrokey Pro."]
11pub const NK_device_model_NK_PRO: NK_device_model = 1;
12#[doc = " Nitrokey Storage."]
13pub const NK_device_model_NK_STORAGE: NK_device_model = 2;
14#[doc = " Librem Key."]
15pub const NK_device_model_NK_LIBREM: NK_device_model = 3;
16#[doc = " The Nitrokey device models supported by the API."]
17pub type NK_device_model = ::std::os::raw::c_uint;
18#[doc = " The connection info for a Nitrokey device as a linked list."]
19#[repr(C)]
20#[derive(Debug, Copy, Clone)]
21pub struct NK_device_info {
22 #[doc = " The model of the Nitrokey device."]
23 pub model: NK_device_model,
24 #[doc = " The USB device path for NK_connect_with_path."]
25 pub path: *mut ::std::os::raw::c_char,
26 #[doc = " The serial number."]
27 pub serial_number: *mut ::std::os::raw::c_char,
28 #[doc = " The pointer to the next element of the linked list or null"]
29 #[doc = " if this is the last element in the list."]
30 pub next: *mut NK_device_info,
31}
32impl Default for NK_device_info {
33 fn default() -> Self {
34 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
35 unsafe {
36 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
37 s.assume_init()
38 }
39 }
40}
41#[doc = " Stores the common device status for all Nitrokey devices."]
42#[repr(C)]
43#[derive(Debug, Default, Copy, Clone)]
44pub struct NK_status {
45 #[doc = " The major firmware version, e. g. 0 in v0.40."]
46 pub firmware_version_major: u8,
47 #[doc = " The minor firmware version, e. g. 40 in v0.40."]
48 pub firmware_version_minor: u8,
49 #[doc = " The serial number of the smart card."]
50 pub serial_number_smart_card: u32,
51 #[doc = " The HOTP slot to generate a password from if the numlock"]
52 #[doc = " key is pressed twice (slot 0-1, or any other value to"]
53 #[doc = " disable the function)."]
54 pub config_numlock: u8,
55 #[doc = " The HOTP slot to generate a password from if the capslock"]
56 #[doc = " key is pressed twice (slot 0-1, or any other value to"]
57 #[doc = " disable the function)."]
58 pub config_capslock: u8,
59 #[doc = " The HOTP slot to generate a password from if the scrolllock"]
60 #[doc = " key is pressed twice (slot 0-1, or any other value to"]
61 #[doc = " disable the function)."]
62 pub config_scrolllock: u8,
63 #[doc = " Indicates whether the user password is required to generate"]
64 #[doc = " an OTP value."]
65 pub otp_user_password: bool,
66}
67#[doc = " Stores the status of a Storage device."]
68#[repr(C)]
69#[derive(Debug, Default, Copy, Clone)]
70pub struct NK_storage_status {
71 #[doc = " Indicates whether the unencrypted volume is read-only."]
72 pub unencrypted_volume_read_only: bool,
73 #[doc = " Indicates whether the unencrypted volume is active."]
74 pub unencrypted_volume_active: bool,
75 #[doc = " Indicates whether the encrypted volume is read-only."]
76 pub encrypted_volume_read_only: bool,
77 #[doc = " Indicates whether the encrypted volume is active."]
78 pub encrypted_volume_active: bool,
79 #[doc = " Indicates whether the hidden volume is read-only."]
80 pub hidden_volume_read_only: bool,
81 #[doc = " Indicates whether the hidden volume is active."]
82 pub hidden_volume_active: bool,
83 #[doc = " The major firmware version, e. g. 0 in v0.40."]
84 pub firmware_version_major: u8,
85 #[doc = " The minor firmware version, e. g. 40 in v0.40."]
86 pub firmware_version_minor: u8,
87 #[doc = " Indicates whether the firmware is locked."]
88 pub firmware_locked: bool,
89 #[doc = " The serial number of the SD card in the Storage stick."]
90 pub serial_number_sd_card: u32,
91 #[doc = " The serial number of the smart card in the Storage stick."]
92 pub serial_number_smart_card: u32,
93 #[doc = " The number of remaining login attempts for the user PIN."]
94 pub user_retry_count: u8,
95 #[doc = " The number of remaining login attempts for the admin PIN."]
96 pub admin_retry_count: u8,
97 #[doc = " Indicates whether a new SD card was found."]
98 pub new_sd_card_found: bool,
99 #[doc = " Indicates whether the SD card is filled with random characters."]
100 pub filled_with_random: bool,
101 #[doc = " Indicates whether the stick has been initialized by generating"]
102 #[doc = " the AES keys."]
103 pub stick_initialized: bool,
104}
105#[doc = " Data about the usage of the SD card."]
106#[repr(C)]
107#[derive(Debug, Default, Copy, Clone)]
108pub struct NK_SD_usage_data {
109 #[doc = " The minimum write level, as a percentage of the total card"]
110 #[doc = " size."]
111 pub write_level_min: u8,
112 #[doc = " The maximum write level, as a percentage of the total card"]
113 #[doc = " size."]
114 pub write_level_max: u8,
115}
116#[doc = " The general configuration of a Nitrokey device."]
117#[repr(C)]
118#[derive(Debug, Default, Copy, Clone)]
119pub struct NK_config {
120 #[doc = " value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock"]
121 #[doc = " or outside the range to disable this function"]
122 pub numlock: u8,
123 #[doc = " similar to numlock but with capslock"]
124 pub capslock: u8,
125 #[doc = " similar to numlock but with scrolllock"]
126 pub scrolllock: u8,
127 #[doc = " True to enable OTP PIN protection (require PIN each OTP code request)"]
128 pub enable_user_password: bool,
129 #[doc = " Unused."]
130 pub disable_user_password: bool,
131}
132#[repr(C)]
133#[derive(Debug, Default, Copy, Clone)]
134pub struct NK_storage_ProductionTest {
135 pub FirmwareVersion_au8: [u8; 2usize],
136 pub FirmwareVersionInternal_u8: u8,
137 pub SD_Card_Size_u8: u8,
138 pub CPU_CardID_u32: u32,
139 pub SmartCardID_u32: u32,
140 pub SD_CardID_u32: u32,
141 pub SC_UserPwRetryCount: u8,
142 pub SC_AdminPwRetryCount: u8,
143 pub SD_Card_ManufacturingYear_u8: u8,
144 pub SD_Card_ManufacturingMonth_u8: u8,
145 pub SD_Card_OEM_u16: u16,
146 pub SD_WriteSpeed_u16: u16,
147 pub SD_Card_Manufacturer_u8: u8,
148}
149extern "C" {
150 pub fn NK_get_storage_production_info(
151 out: *mut NK_storage_ProductionTest,
152 ) -> ::std::os::raw::c_int;
153}
154extern "C" {
155 #[doc = " Set debug level of messages written on stderr"]
156 #[doc = " @param state state=True - most messages, state=False - only errors level"]
157 pub fn NK_set_debug(state: bool);
158}
159extern "C" {
160 #[doc = " Set debug level of messages written on stderr"]
161 #[doc = " @param level (int) 0-lowest verbosity, 5-highest verbosity"]
162 pub fn NK_set_debug_level(level: ::std::os::raw::c_int);
163}
164#[doc = " Callback function for NK_set_log_function. The first argument is"]
165#[doc = " the log level (0 = Error, 1 = Warn, 2 = Info, 3 = DebugL1,"]
166#[doc = " 4 = Debug, 5 = DebugL2) and the second argument is the log message."]
167pub type NK_log_function = ::std::option::Option<
168 unsafe extern "C" fn(arg1: ::std::os::raw::c_int, arg2: *const ::std::os::raw::c_char),
169>;
170extern "C" {
171 #[doc = " Set a custom log function."]
172 #[doc = ""]
173 #[doc = " The log function is called for every log message that matches the"]
174 #[doc = " log level settings (see NK_set_debug and NK_set_debug_level)."]
175 pub fn NK_set_log_function(fn_: NK_log_function);
176}
177extern "C" {
178 #[doc = " Get the major library version, e. g. the 3 in v3.2."]
179 #[doc = " @return the major library version"]
180 pub fn NK_get_major_library_version() -> ::std::os::raw::c_uint;
181}
182extern "C" {
183 #[doc = " Get the minor library version, e. g. the 2 in v3.2."]
184 #[doc = " @return the minor library version"]
185 pub fn NK_get_minor_library_version() -> ::std::os::raw::c_uint;
186}
187extern "C" {
188 #[doc = " Get the library version as a string. This is the output of"]
189 #[doc = " `git describe --always` at compile time, for example \"v3.3\" or"]
190 #[doc = " \"v3.3-19-gaee920b\"."]
191 #[doc = " The return value is a string literal and must not be freed."]
192 #[doc = " @return the library version as a string"]
193 pub fn NK_get_library_version() -> *const ::std::os::raw::c_char;
194}
195extern "C" {
196 #[doc = " Connect to device of given model. Currently library can be connected only to one device at once."]
197 #[doc = " @param device_model char 'S': Nitrokey Storage, 'P': Nitrokey Pro"]
198 #[doc = " @return 1 if connected, 0 if wrong model or cannot connect"]
199 pub fn NK_login(device_model: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int;
200}
201extern "C" {
202 #[doc = " Connect to device of given model. Currently library can be connected only to one device at once."]
203 #[doc = " @param device_model NK_device_model: NK_PRO: Nitrokey Pro, NK_STORAGE: Nitrokey Storage, NK_LIBREM: Librem Key"]
204 #[doc = " @return 1 if connected, 0 if wrong model or cannot connect"]
205 pub fn NK_login_enum(device_model: NK_device_model) -> ::std::os::raw::c_int;
206}
207extern "C" {
208 #[doc = " Connect to first available device, starting checking from Pro 1st to Storage 2nd."]
209 #[doc = " @return 1 if connected, 0 if wrong model or cannot connect"]
210 pub fn NK_login_auto() -> ::std::os::raw::c_int;
211}
212extern "C" {
213 #[doc = " Disconnect from the device."]
214 #[doc = " @return command processing error code"]
215 pub fn NK_logout() -> ::std::os::raw::c_int;
216}
217extern "C" {
218 #[doc = " Query the model of the connected device."]
219 #[doc = " Returns the model of the connected device or NK_DISCONNECTED."]
220 #[doc = ""]
221 #[doc = " @return true if a device is connected and the out argument has been set"]
222 pub fn NK_get_device_model() -> NK_device_model;
223}
224extern "C" {
225 #[doc = " Return the debug status string. Debug purposes. This function is"]
226 #[doc = " deprecated in favor of NK_get_status_as_string."]
227 #[doc = " @return string representation of the status or an empty string"]
228 #[doc = " if the command failed"]
229 #[deprecated(since = "3.5.0", note = "use `NK_get_status_as_string` instead")]
230 pub fn NK_status() -> *mut ::std::os::raw::c_char;
231}
232extern "C" {
233 #[doc = " Return the debug status string. Debug purposes."]
234 #[doc = " @return string representation of the status or an empty string"]
235 #[doc = " if the command failed"]
236 pub fn NK_get_status_as_string() -> *mut ::std::os::raw::c_char;
237}
238extern "C" {
239 #[doc = " Get the stick status common to all Nitrokey devices and return the"]
240 #[doc = " command processing error code. If the code is zero, i. e. the"]
241 #[doc = " command was successful, the storage status is written to the output"]
242 #[doc = " pointer's target. The output pointer must not be null."]
243 #[doc = ""]
244 #[doc = " @param out the output pointer for the status"]
245 #[doc = " @return command processing error code"]
246 pub fn NK_get_status(out: *mut NK_status) -> ::std::os::raw::c_int;
247}
248extern "C" {
249 #[doc = " Return the device's serial number string in hex."]
250 #[doc = " @return string device's serial number in hex"]
251 pub fn NK_device_serial_number() -> *mut ::std::os::raw::c_char;
252}
253extern "C" {
254 #[doc = " Return the device's serial number string as an integer. Use"]
255 #[doc = " NK_last_command_status to check for an error if this function"]
256 #[doc = " returns zero."]
257 #[doc = " @return device's serial number as an integer"]
258 pub fn NK_device_serial_number_as_u32() -> u32;
259}
260extern "C" {
261 #[doc = " Get last command processing status. Useful for commands which returns the results of their own and could not return"]
262 #[doc = " an error code."]
263 #[doc = " @return previous command processing error code"]
264 pub fn NK_get_last_command_status() -> u8;
265}
266extern "C" {
267 #[doc = " Lock device - cancel any user device unlocking."]
268 #[doc = " @return command processing error code"]
269 pub fn NK_lock_device() -> ::std::os::raw::c_int;
270}
271extern "C" {
272 #[doc = " Authenticates the user on USER privilages with user_password and sets user's temporary password on device to user_temporary_password."]
273 #[doc = " @param user_password char[25] current user password"]
274 #[doc = " @param user_temporary_password char[25] user temporary password to be set on device for further communication (authentication command)"]
275 #[doc = " @return command processing error code"]
276 pub fn NK_user_authenticate(
277 user_password: *const ::std::os::raw::c_char,
278 user_temporary_password: *const ::std::os::raw::c_char,
279 ) -> ::std::os::raw::c_int;
280}
281extern "C" {
282 #[doc = " Authenticates the user on ADMIN privilages with admin_password and sets user's temporary password on device to admin_temporary_password."]
283 #[doc = " @param admin_password char[25] current administrator PIN"]
284 #[doc = " @param admin_temporary_password char[25] admin temporary password to be set on device for further communication (authentication command)"]
285 #[doc = " @return command processing error code"]
286 pub fn NK_first_authenticate(
287 admin_password: *const ::std::os::raw::c_char,
288 admin_temporary_password: *const ::std::os::raw::c_char,
289 ) -> ::std::os::raw::c_int;
290}
291extern "C" {
292 #[doc = " Execute a factory reset."]
293 #[doc = " @param admin_password char[20] current administrator PIN"]
294 #[doc = " @return command processing error code"]
295 pub fn NK_factory_reset(admin_password: *const ::std::os::raw::c_char)
296 -> ::std::os::raw::c_int;
297}
298extern "C" {
299 #[doc = " Generates AES key on the device"]
300 #[doc = " @param admin_password char[20] current administrator PIN"]
301 #[doc = " @return command processing error code"]
302 pub fn NK_build_aes_key(admin_password: *const ::std::os::raw::c_char)
303 -> ::std::os::raw::c_int;
304}
305extern "C" {
306 #[doc = " Unlock user PIN locked after 3 incorrect codes tries."]
307 #[doc = " @param admin_password char[20] current administrator PIN"]
308 #[doc = " @return command processing error code"]
309 pub fn NK_unlock_user_password(
310 admin_password: *const ::std::os::raw::c_char,
311 new_user_password: *const ::std::os::raw::c_char,
312 ) -> ::std::os::raw::c_int;
313}
314extern "C" {
315 #[doc = " Write general config to the device"]
316 #[doc = " @param numlock set value in range [0-1] to send HOTP code from slot 'numlock' after double pressing numlock"]
317 #[doc = " or outside the range to disable this function"]
318 #[doc = " @param capslock similar to numlock but with capslock"]
319 #[doc = " @param scrolllock similar to numlock but with scrolllock"]
320 #[doc = " @param enable_user_password set True to enable OTP PIN protection (require PIN each OTP code request)"]
321 #[doc = " @param delete_user_password (unused)"]
322 #[doc = " @param admin_temporary_password current admin temporary password"]
323 #[doc = " @return command processing error code"]
324 pub fn NK_write_config(
325 numlock: u8,
326 capslock: u8,
327 scrolllock: u8,
328 enable_user_password: bool,
329 delete_user_password: bool,
330 admin_temporary_password: *const ::std::os::raw::c_char,
331 ) -> ::std::os::raw::c_int;
332}
333extern "C" {
334 #[doc = " Write general config to the device"]
335 #[doc = " @param config the configuration data"]
336 #[doc = " @param admin_temporary_password current admin temporary password"]
337 #[doc = " @return command processing error code"]
338 pub fn NK_write_config_struct(
339 config: NK_config,
340 admin_temporary_password: *const ::std::os::raw::c_char,
341 ) -> ::std::os::raw::c_int;
342}
343extern "C" {
344 #[doc = " Get currently set config - status of function Numlock/Capslock/Scrollock OTP sending and is enabled PIN protected OTP"]
345 #[doc = " The return value must be freed using NK_free_config."]
346 #[doc = " @see NK_write_config"]
347 #[doc = " @return uint8_t general_config[5]:"]
348 #[doc = " uint8_t numlock;"]
349 #[doc = "uint8_t capslock;"]
350 #[doc = "uint8_t scrolllock;"]
351 #[doc = "uint8_t enable_user_password;"]
352 #[doc = "uint8_t delete_user_password;"]
353 #[doc = ""]
354 pub fn NK_read_config() -> *mut u8;
355}
356extern "C" {
357 #[doc = " Free a value returned by NK_read_config. May be called with a NULL"]
358 #[doc = " argument."]
359 pub fn NK_free_config(config: *mut u8);
360}
361extern "C" {
362 #[doc = " Get currently set config and write it to the given pointer."]
363 #[doc = " @see NK_read_config"]
364 #[doc = " @see NK_write_config_struct"]
365 #[doc = " @param out a pointer to the struct that should be written to"]
366 #[doc = " @return command processing error code"]
367 pub fn NK_read_config_struct(out: *mut NK_config) -> ::std::os::raw::c_int;
368}
369extern "C" {
370 #[doc = " Get name of given TOTP slot"]
371 #[doc = " @param slot_number TOTP slot number, slot_number<15"]
372 #[doc = " @return char[20] the name of the slot"]
373 pub fn NK_get_totp_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char;
374}
375extern "C" {
376 #[doc = " @param slot_number HOTP slot number, slot_number<3"]
377 #[doc = " @return char[20] the name of the slot"]
378 pub fn NK_get_hotp_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char;
379}
380extern "C" {
381 #[doc = " Erase HOTP slot data from the device"]
382 #[doc = " @param slot_number HOTP slot number, slot_number<3"]
383 #[doc = " @param temporary_password admin temporary password"]
384 #[doc = " @return command processing error code"]
385 pub fn NK_erase_hotp_slot(
386 slot_number: u8,
387 temporary_password: *const ::std::os::raw::c_char,
388 ) -> ::std::os::raw::c_int;
389}
390extern "C" {
391 #[doc = " Erase TOTP slot data from the device"]
392 #[doc = " @param slot_number TOTP slot number, slot_number<15"]
393 #[doc = " @param temporary_password admin temporary password"]
394 #[doc = " @return command processing error code"]
395 pub fn NK_erase_totp_slot(
396 slot_number: u8,
397 temporary_password: *const ::std::os::raw::c_char,
398 ) -> ::std::os::raw::c_int;
399}
400extern "C" {
401 #[doc = " Write HOTP slot data to the device"]
402 #[doc = " @param slot_number HOTP slot number, slot_number<3, 0-numbered"]
403 #[doc = " @param slot_name char[15] desired slot name. C string (requires ending '\\0'; 16 bytes)."]
404 #[doc = " @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\\0'; 41 bytes)."]
405 #[doc = " See NitrokeyManager::is_320_OTP_secret_supported."]
406 #[doc = " @param hotp_counter uint32_t starting value of HOTP counter"]
407 #[doc = " @param use_8_digits should returned codes be 6 (false) or 8 digits (true)"]
408 #[doc = " @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock"]
409 #[doc = " @param use_tokenID @see token_ID"]
410 #[doc = " @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section"]
411 #[doc = " @param temporary_password char[25] admin temporary password"]
412 #[doc = " @return command processing error code"]
413 pub fn NK_write_hotp_slot(
414 slot_number: u8,
415 slot_name: *const ::std::os::raw::c_char,
416 secret: *const ::std::os::raw::c_char,
417 hotp_counter: u64,
418 use_8_digits: bool,
419 use_enter: bool,
420 use_tokenID: bool,
421 token_ID: *const ::std::os::raw::c_char,
422 temporary_password: *const ::std::os::raw::c_char,
423 ) -> ::std::os::raw::c_int;
424}
425extern "C" {
426 #[doc = " Write TOTP slot data to the device"]
427 #[doc = " @param slot_number TOTP slot number, slot_number<15, 0-numbered"]
428 #[doc = " @param slot_name char[15] desired slot name. C string (requires ending '\\0'; 16 bytes)."]
429 #[doc = " @param secret char[40] 160-bit or 320-bit (currently Pro v0.8 only) secret as a hex string. C string (requires ending '\\0'; 41 bytes)."]
430 #[doc = " See NitrokeyManager::is_320_OTP_secret_supported."]
431 #[doc = " @param time_window uint16_t time window for this TOTP"]
432 #[doc = " @param use_8_digits should returned codes be 6 (false) or 8 digits (true)"]
433 #[doc = " @param use_enter press ENTER key after sending OTP code using double-pressed scroll/num/capslock"]
434 #[doc = " @param use_tokenID @see token_ID"]
435 #[doc = " @param token_ID @see https://openauthentication.org/token-specs/, 'Class A' section"]
436 #[doc = " @param temporary_password char[20] admin temporary password"]
437 #[doc = " @return command processing error code"]
438 pub fn NK_write_totp_slot(
439 slot_number: u8,
440 slot_name: *const ::std::os::raw::c_char,
441 secret: *const ::std::os::raw::c_char,
442 time_window: u16,
443 use_8_digits: bool,
444 use_enter: bool,
445 use_tokenID: bool,
446 token_ID: *const ::std::os::raw::c_char,
447 temporary_password: *const ::std::os::raw::c_char,
448 ) -> ::std::os::raw::c_int;
449}
450extern "C" {
451 #[doc = " Get HOTP code from the device"]
452 #[doc = " @param slot_number HOTP slot number, slot_number<3"]
453 #[doc = " @return HOTP code"]
454 pub fn NK_get_hotp_code(slot_number: u8) -> *mut ::std::os::raw::c_char;
455}
456extern "C" {
457 #[doc = " Get HOTP code from the device (PIN protected)"]
458 #[doc = " @param slot_number HOTP slot number, slot_number<3"]
459 #[doc = " @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled,"]
460 #[doc = " otherwise should be set to empty string - ''"]
461 #[doc = " @return HOTP code"]
462 pub fn NK_get_hotp_code_PIN(
463 slot_number: u8,
464 user_temporary_password: *const ::std::os::raw::c_char,
465 ) -> *mut ::std::os::raw::c_char;
466}
467extern "C" {
468 #[doc = " Get TOTP code from the device"]
469 #[doc = " @param slot_number TOTP slot number, slot_number<15"]
470 #[doc = " @param challenge TOTP challenge -- unused"]
471 #[doc = " @param last_totp_time last time -- unused"]
472 #[doc = " @param last_interval last interval --unused"]
473 #[doc = " @return TOTP code"]
474 pub fn NK_get_totp_code(
475 slot_number: u8,
476 challenge: u64,
477 last_totp_time: u64,
478 last_interval: u8,
479 ) -> *mut ::std::os::raw::c_char;
480}
481extern "C" {
482 #[doc = " Get TOTP code from the device (PIN protected)"]
483 #[doc = " @param slot_number TOTP slot number, slot_number<15"]
484 #[doc = " @param challenge TOTP challenge -- unused"]
485 #[doc = " @param last_totp_time last time -- unused"]
486 #[doc = " @param last_interval last interval -- unused"]
487 #[doc = " @param user_temporary_password char[25] user temporary password if PIN protected OTP codes are enabled,"]
488 #[doc = " otherwise should be set to empty string - ''"]
489 #[doc = " @return TOTP code"]
490 pub fn NK_get_totp_code_PIN(
491 slot_number: u8,
492 challenge: u64,
493 last_totp_time: u64,
494 last_interval: u8,
495 user_temporary_password: *const ::std::os::raw::c_char,
496 ) -> *mut ::std::os::raw::c_char;
497}
498extern "C" {
499 #[doc = " Set time on the device (for TOTP requests)"]
500 #[doc = " @param time seconds in unix epoch (from 01.01.1970)"]
501 #[doc = " @return command processing error code"]
502 pub fn NK_totp_set_time(time: u64) -> ::std::os::raw::c_int;
503}
504extern "C" {
505 #[doc = " Set the device time used for TOTP to the given time. Contrary to"]
506 #[doc = " {@code set_time(uint64_t)}, this command fails if {@code old_time}"]
507 #[doc = " > {@code time} or if {@code old_time} is zero (where {@code"]
508 #[doc = " old_time} is the current time on the device)."]
509 #[doc = ""]
510 #[doc = " @param time new device time as Unix timestamp (seconds since"]
511 #[doc = " 1970-01-01)"]
512 #[doc = " @return command processing error code"]
513 pub fn NK_totp_set_time_soft(time: u64) -> ::std::os::raw::c_int;
514}
515extern "C" {
516 #[deprecated(since = "3.4.0", note = "use `NK_totp_set_time_soft` instead")]
517 pub fn NK_totp_get_time() -> ::std::os::raw::c_int;
518}
519extern "C" {
520 #[doc = " Change administrator PIN"]
521 #[doc = " @param current_PIN char[25] current PIN"]
522 #[doc = " @param new_PIN char[25] new PIN"]
523 #[doc = " @return command processing error code"]
524 pub fn NK_change_admin_PIN(
525 current_PIN: *const ::std::os::raw::c_char,
526 new_PIN: *const ::std::os::raw::c_char,
527 ) -> ::std::os::raw::c_int;
528}
529extern "C" {
530 #[doc = " Change user PIN"]
531 #[doc = " @param current_PIN char[25] current PIN"]
532 #[doc = " @param new_PIN char[25] new PIN"]
533 #[doc = " @return command processing error code"]
534 pub fn NK_change_user_PIN(
535 current_PIN: *const ::std::os::raw::c_char,
536 new_PIN: *const ::std::os::raw::c_char,
537 ) -> ::std::os::raw::c_int;
538}
539extern "C" {
540 #[doc = " Get retry count of user PIN"]
541 #[doc = " @return user PIN retry count"]
542 pub fn NK_get_user_retry_count() -> u8;
543}
544extern "C" {
545 #[doc = " Get retry count of admin PIN"]
546 #[doc = " @return admin PIN retry count"]
547 pub fn NK_get_admin_retry_count() -> u8;
548}
549extern "C" {
550 #[doc = " Enable password safe access"]
551 #[doc = " @param user_pin char[30] current user PIN"]
552 #[doc = " @return command processing error code"]
553 pub fn NK_enable_password_safe(
554 user_pin: *const ::std::os::raw::c_char,
555 ) -> ::std::os::raw::c_int;
556}
557extern "C" {
558 #[doc = " Get password safe slots' status"]
559 #[doc = " The return value must be freed using NK_free_password_safe_slot_status."]
560 #[doc = " @return uint8_t[16] slot statuses - each byte represents one slot with 0 (not programmed) and 1 (programmed)"]
561 pub fn NK_get_password_safe_slot_status() -> *mut u8;
562}
563extern "C" {
564 #[doc = " Free a value returned by NK_get_password_safe_slot_status. May be"]
565 #[doc = " called with a NULL argument."]
566 pub fn NK_free_password_safe_slot_status(status: *mut u8);
567}
568extern "C" {
569 #[doc = " Get password safe slot name"]
570 #[doc = " @param slot_number password safe slot number, slot_number<16"]
571 #[doc = " @return slot name"]
572 pub fn NK_get_password_safe_slot_name(slot_number: u8) -> *mut ::std::os::raw::c_char;
573}
574extern "C" {
575 #[doc = " Get password safe slot login"]
576 #[doc = " @param slot_number password safe slot number, slot_number<16"]
577 #[doc = " @return login from the PWS slot"]
578 pub fn NK_get_password_safe_slot_login(slot_number: u8) -> *mut ::std::os::raw::c_char;
579}
580extern "C" {
581 #[doc = " Get the password safe slot password"]
582 #[doc = " @param slot_number password safe slot number, slot_number<16"]
583 #[doc = " @return password from the PWS slot"]
584 pub fn NK_get_password_safe_slot_password(slot_number: u8) -> *mut ::std::os::raw::c_char;
585}
586extern "C" {
587 #[doc = " Write password safe data to the slot"]
588 #[doc = " @param slot_number password safe slot number, slot_number<16"]
589 #[doc = " @param slot_name char[11] name of the slot"]
590 #[doc = " @param slot_login char[32] login string"]
591 #[doc = " @param slot_password char[20] password string"]
592 #[doc = " @return command processing error code"]
593 pub fn NK_write_password_safe_slot(
594 slot_number: u8,
595 slot_name: *const ::std::os::raw::c_char,
596 slot_login: *const ::std::os::raw::c_char,
597 slot_password: *const ::std::os::raw::c_char,
598 ) -> ::std::os::raw::c_int;
599}
600extern "C" {
601 #[doc = " Erase the password safe slot from the device"]
602 #[doc = " @param slot_number password safe slot number, slot_number<16"]
603 #[doc = " @return command processing error code"]
604 pub fn NK_erase_password_safe_slot(slot_number: u8) -> ::std::os::raw::c_int;
605}
606extern "C" {
607 #[doc = " Check whether AES is supported by the device"]
608 #[doc = " @return 0 for no and 1 for yes"]
609 pub fn NK_is_AES_supported(
610 user_password: *const ::std::os::raw::c_char,
611 ) -> ::std::os::raw::c_int;
612}
613extern "C" {
614 #[doc = " Get device's major firmware version"]
615 #[doc = " @return major part of the version number (e.g. 0 from 0.48, 0 from 0.7 etc.)"]
616 pub fn NK_get_major_firmware_version() -> u8;
617}
618extern "C" {
619 #[doc = " Get device's minor firmware version"]
620 #[doc = " @return minor part of the version number (e.g. 7 from 0.7, 48 from 0.48 etc.)"]
621 pub fn NK_get_minor_firmware_version() -> u8;
622}
623extern "C" {
624 #[doc = " Function to determine unencrypted volume PIN type"]
625 #[doc = " @param minor_firmware_version"]
626 #[doc = " @return Returns 1, if set unencrypted volume ro/rw pin type is User, 0 otherwise."]
627 pub fn NK_set_unencrypted_volume_rorw_pin_type_user() -> ::std::os::raw::c_int;
628}
629extern "C" {
630 #[doc = " This command is typically run to initiate"]
631 #[doc = " communication with the device (altough not required)."]
632 #[doc = " It sets time on device and returns its current status"]
633 #[doc = " - a combination of set_time and get_status_storage commands"]
634 #[doc = " Storage only"]
635 #[doc = " @param seconds_from_epoch date and time expressed in seconds"]
636 pub fn NK_send_startup(seconds_from_epoch: u64) -> ::std::os::raw::c_int;
637}
638extern "C" {
639 #[doc = " Unlock encrypted volume."]
640 #[doc = " Storage only"]
641 #[doc = " @param user_pin user pin 20 characters"]
642 #[doc = " @return command processing error code"]
643 pub fn NK_unlock_encrypted_volume(
644 user_pin: *const ::std::os::raw::c_char,
645 ) -> ::std::os::raw::c_int;
646}
647extern "C" {
648 #[doc = " Locks encrypted volume"]
649 #[doc = " @return command processing error code"]
650 pub fn NK_lock_encrypted_volume() -> ::std::os::raw::c_int;
651}
652extern "C" {
653 #[doc = " Unlock hidden volume and lock encrypted volume."]
654 #[doc = " Requires encrypted volume to be unlocked."]
655 #[doc = " Storage only"]
656 #[doc = " @param hidden_volume_password 20 characters"]
657 #[doc = " @return command processing error code"]
658 pub fn NK_unlock_hidden_volume(
659 hidden_volume_password: *const ::std::os::raw::c_char,
660 ) -> ::std::os::raw::c_int;
661}
662extern "C" {
663 #[doc = " Locks hidden volume"]
664 #[doc = " @return command processing error code"]
665 pub fn NK_lock_hidden_volume() -> ::std::os::raw::c_int;
666}
667extern "C" {
668 #[doc = " Create hidden volume."]
669 #[doc = " Requires encrypted volume to be unlocked."]
670 #[doc = " Storage only"]
671 #[doc = " @param slot_nr slot number in range 0-3"]
672 #[doc = " @param start_percent volume begin expressed in percent of total available storage, int in range 0-99"]
673 #[doc = " @param end_percent volume end expressed in percent of total available storage, int in range 1-100"]
674 #[doc = " @param hidden_volume_password 20 characters"]
675 #[doc = " @return command processing error code"]
676 pub fn NK_create_hidden_volume(
677 slot_nr: u8,
678 start_percent: u8,
679 end_percent: u8,
680 hidden_volume_password: *const ::std::os::raw::c_char,
681 ) -> ::std::os::raw::c_int;
682}
683extern "C" {
684 #[doc = " Make unencrypted volume read-only."]
685 #[doc = " Device hides unencrypted volume for a second therefore make sure"]
686 #[doc = " buffers are flushed before running."]
687 #[doc = " Does nothing if firmware version is not matched"]
688 #[doc = " Firmware range: Storage v0.50, v0.48 and below"]
689 #[doc = " Storage only"]
690 #[doc = " @param user_pin 20 characters User PIN"]
691 #[doc = " @return command processing error code"]
692 #[deprecated(
693 since = "3.6.0",
694 note = "use `set_unencrypted_read_only_admin` instead"
695 )]
696 pub fn NK_set_unencrypted_read_only(
697 user_pin: *const ::std::os::raw::c_char,
698 ) -> ::std::os::raw::c_int;
699}
700extern "C" {
701 #[doc = " Make unencrypted volume read-write."]
702 #[doc = " Device hides unencrypted volume for a second therefore make sure"]
703 #[doc = " buffers are flushed before running."]
704 #[doc = " Does nothing if firmware version is not matched"]
705 #[doc = " Firmware range: Storage v0.50, v0.48 and below"]
706 #[doc = " Storage only"]
707 #[doc = " @param user_pin 20 characters User PIN"]
708 #[doc = " @return command processing error code"]
709 #[deprecated(
710 since = "3.6.0",
711 note = "use `set_unencrypted_read_write_admin` instead"
712 )]
713 pub fn NK_set_unencrypted_read_write(
714 user_pin: *const ::std::os::raw::c_char,
715 ) -> ::std::os::raw::c_int;
716}
717extern "C" {
718 #[doc = " Make unencrypted volume read-only."]
719 #[doc = " Device hides unencrypted volume for a second therefore make sure"]
720 #[doc = " buffers are flushed before running."]
721 #[doc = " Does nothing if firmware version is not matched"]
722 #[doc = " Firmware range: Storage v0.49, v0.51+"]
723 #[doc = " Storage only"]
724 #[doc = " @param admin_pin 20 characters Admin PIN"]
725 #[doc = " @return command processing error code"]
726 pub fn NK_set_unencrypted_read_only_admin(
727 admin_pin: *const ::std::os::raw::c_char,
728 ) -> ::std::os::raw::c_int;
729}
730extern "C" {
731 #[doc = " Make unencrypted volume read-write."]
732 #[doc = " Device hides unencrypted volume for a second therefore make sure"]
733 #[doc = " buffers are flushed before running."]
734 #[doc = " Does nothing if firmware version is not matched"]
735 #[doc = " Firmware range: Storage v0.49, v0.51+"]
736 #[doc = " Storage only"]
737 #[doc = " @param admin_pin 20 characters Admin PIN"]
738 #[doc = " @return command processing error code"]
739 pub fn NK_set_unencrypted_read_write_admin(
740 admin_pin: *const ::std::os::raw::c_char,
741 ) -> ::std::os::raw::c_int;
742}
743extern "C" {
744 #[doc = " Make encrypted volume read-only."]
745 #[doc = " Device hides encrypted volume for a second therefore make sure"]
746 #[doc = " buffers are flushed before running."]
747 #[doc = " Firmware range: v0.49 only, future (see firmware release notes)"]
748 #[doc = " Storage only"]
749 #[doc = " @param admin_pin 20 characters"]
750 #[doc = " @return command processing error code"]
751 pub fn NK_set_encrypted_read_only(
752 admin_pin: *const ::std::os::raw::c_char,
753 ) -> ::std::os::raw::c_int;
754}
755extern "C" {
756 #[doc = " Make encrypted volume read-write."]
757 #[doc = " Device hides encrypted volume for a second therefore make sure"]
758 #[doc = " buffers are flushed before running."]
759 #[doc = " Firmware range: v0.49 only, future (see firmware release notes)"]
760 #[doc = " Storage only"]
761 #[doc = " @param admin_pin 20 characters"]
762 #[doc = " @return command processing error code"]
763 pub fn NK_set_encrypted_read_write(
764 admin_pin: *const ::std::os::raw::c_char,
765 ) -> ::std::os::raw::c_int;
766}
767extern "C" {
768 #[doc = " Exports device's firmware to unencrypted volume."]
769 #[doc = " Storage only"]
770 #[doc = " @param admin_pin 20 characters"]
771 #[doc = " @return command processing error code"]
772 pub fn NK_export_firmware(admin_pin: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int;
773}
774extern "C" {
775 #[doc = " Clear new SD card notification. It is set after factory reset."]
776 #[doc = " Storage only"]
777 #[doc = " @param admin_pin 20 characters"]
778 #[doc = " @return command processing error code"]
779 pub fn NK_clear_new_sd_card_warning(
780 admin_pin: *const ::std::os::raw::c_char,
781 ) -> ::std::os::raw::c_int;
782}
783extern "C" {
784 #[doc = " Fill SD card with random data."]
785 #[doc = " Should be done on first stick initialization after creating keys."]
786 #[doc = " Storage only"]
787 #[doc = " @param admin_pin 20 characters"]
788 #[doc = " @return command processing error code"]
789 pub fn NK_fill_SD_card_with_random_data(
790 admin_pin: *const ::std::os::raw::c_char,
791 ) -> ::std::os::raw::c_int;
792}
793extern "C" {
794 #[doc = " Change update password."]
795 #[doc = " Update password is used for entering update mode, where firmware"]
796 #[doc = " could be uploaded using dfu-programmer or other means."]
797 #[doc = " Storage only"]
798 #[doc = " @param current_update_password 20 characters"]
799 #[doc = " @param new_update_password 20 characters"]
800 #[doc = " @return command processing error code"]
801 pub fn NK_change_update_password(
802 current_update_password: *const ::std::os::raw::c_char,
803 new_update_password: *const ::std::os::raw::c_char,
804 ) -> ::std::os::raw::c_int;
805}
806extern "C" {
807 #[doc = " Enter update mode. Needs update password."]
808 #[doc = " When device is in update mode it no longer accepts any HID commands until"]
809 #[doc = " firmware is launched (regardless of being updated or not)."]
810 #[doc = " Smartcard (through CCID interface) and its all volumes are not visible as well."]
811 #[doc = " Its VID and PID are changed to factory-default (03eb:2ff1 Atmel Corp.)"]
812 #[doc = " to be detected by flashing software. Result of this command can be reversed"]
813 #[doc = " by using 'launch' command."]
814 #[doc = " For dfu-programmer it would be: 'dfu-programmer at32uc3a3256s launch'."]
815 #[doc = " Storage only"]
816 #[doc = " @param update_password 20 characters"]
817 #[doc = " @return command processing error code"]
818 pub fn NK_enable_firmware_update(
819 update_password: *const ::std::os::raw::c_char,
820 ) -> ::std::os::raw::c_int;
821}
822extern "C" {
823 #[doc = " Get Storage stick status as string."]
824 #[doc = " Storage only"]
825 #[doc = " @return string with devices attributes"]
826 pub fn NK_get_status_storage_as_string() -> *mut ::std::os::raw::c_char;
827}
828extern "C" {
829 #[doc = " Get the Storage stick status and return the command processing"]
830 #[doc = " error code. If the code is zero, i. e. the command was successful,"]
831 #[doc = " the storage status is written to the output pointer's target."]
832 #[doc = " The output pointer must not be null."]
833 #[doc = ""]
834 #[doc = " @param out the output pointer for the storage status"]
835 #[doc = " @return command processing error code"]
836 pub fn NK_get_status_storage(out: *mut NK_storage_status) -> ::std::os::raw::c_int;
837}
838extern "C" {
839 #[doc = " Get SD card usage attributes. Usable during hidden volumes creation."]
840 #[doc = " If the command was successful (return value 0), the usage data is"]
841 #[doc = " written to the output pointer's target. The output pointer must"]
842 #[doc = " not be null."]
843 #[doc = " Storage only"]
844 #[doc = " @param out the output pointer for the usage data"]
845 #[doc = " @return command processing error code"]
846 pub fn NK_get_SD_usage_data(out: *mut NK_SD_usage_data) -> ::std::os::raw::c_int;
847}
848extern "C" {
849 #[doc = " Get SD card usage attributes as string."]
850 #[doc = " Usable during hidden volumes creation."]
851 #[doc = " Storage only"]
852 #[doc = " @return string with SD card usage attributes"]
853 pub fn NK_get_SD_usage_data_as_string() -> *mut ::std::os::raw::c_char;
854}
855extern "C" {
856 #[doc = " Get progress value of current long operation."]
857 #[doc = " Storage only"]
858 #[doc = " @return int in range 0-100 or -1 if device is not busy or -2 if an"]
859 #[doc = " error occured"]
860 pub fn NK_get_progress_bar_value() -> ::std::os::raw::c_int;
861}
862extern "C" {
863 #[doc = " Returns a list of connected devices' id's, delimited by ';' character. Empty string is returned on no device found."]
864 #[doc = " Each ID could consist of:"]
865 #[doc = " 1. SC_id:SD_id_p_path (about 40 bytes)"]
866 #[doc = " 2. path (about 10 bytes)"]
867 #[doc = " where 'path' is USB path (bus:num), 'SC_id' is smartcard ID, 'SD_id' is storage card ID and"]
868 #[doc = " '_p_' and ':' are field delimiters."]
869 #[doc = " Case 2 (USB path only) is used, when the device cannot be asked about its status data (e.g. during a long operation,"]
870 #[doc = " like clearing SD card."]
871 #[doc = " Internally connects to all available devices and creates a map between ids and connection objects."]
872 #[doc = " Side effects: changes active device to last detected Storage device."]
873 #[doc = " Storage only"]
874 #[doc = " @example Example of returned data: '00005d19:dacc2cb4_p_0001:0010:02;000037c7:4cf12445_p_0001:000f:02;0001:000c:02'"]
875 #[doc = " @return string delimited id's of connected devices"]
876 pub fn NK_list_devices_by_cpuID() -> *mut ::std::os::raw::c_char;
877}
878extern "C" {
879 #[doc = " Returns a linked list of all connected devices, or null if no devices"]
880 #[doc = " are connected or an error occured. The linked list must be freed by"]
881 #[doc = " calling NK_free_device_info."]
882 #[doc = " @return a linked list of all connected devices"]
883 pub fn NK_list_devices() -> *mut NK_device_info;
884}
885extern "C" {
886 #[doc = " Free a linked list returned by NK_list_devices."]
887 #[doc = " @param the linked list to free or null"]
888 pub fn NK_free_device_info(device_info: *mut NK_device_info);
889}
890extern "C" {
891 #[doc = " Connects to the device with given ID. ID's list could be created with NK_list_devices_by_cpuID."]
892 #[doc = " Requires calling to NK_list_devices_by_cpuID first. Connecting to arbitrary ID/USB path is not handled."]
893 #[doc = " On connection requests status from device and disconnects it / removes from map on connection failure."]
894 #[doc = " Storage only"]
895 #[doc = " @param id Target device ID (example: '00005d19:dacc2cb4_p_0001:0010:02')"]
896 #[doc = " @return 1 on successful connection, 0 otherwise"]
897 pub fn NK_connect_with_ID(id: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int;
898}
899extern "C" {
900 #[doc = " Connects to a device with the given path. The path is a USB device"]
901 #[doc = " path as returned by hidapi."]
902 #[doc = " @param path the device path"]
903 #[doc = " @return 1 on successful connection, 0 otherwise"]
904 pub fn NK_connect_with_path(path: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int;
905}
906extern "C" {
907 #[doc = " Blink red and green LED alternatively and infinitely (until device is reconnected)."]
908 #[doc = " @return command processing error code"]
909 pub fn NK_wink() -> ::std::os::raw::c_int;
910}
911extern "C" {
912 #[doc = " Enable update mode on Nitrokey Pro."]
913 #[doc = " Supported from v0.11."]
914 #[doc = " @param update_password 20 bytes update password"]
915 #[doc = " @return command processing error code"]
916 pub fn NK_enable_firmware_update_pro(
917 update_password: *const ::std::os::raw::c_char,
918 ) -> ::std::os::raw::c_int;
919}
920extern "C" {
921 #[doc = " Change update-mode password on Nitrokey Pro."]
922 #[doc = " Supported from v0.11."]
923 #[doc = " @param current_firmware_password 20 bytes update password"]
924 #[doc = " @param new_firmware_password 20 bytes update password"]
925 #[doc = " @return command processing error code"]
926 pub fn NK_change_firmware_password_pro(
927 current_firmware_password: *const ::std::os::raw::c_char,
928 new_firmware_password: *const ::std::os::raw::c_char,
929 ) -> ::std::os::raw::c_int;
930}
931#[repr(C)]
932#[derive(Debug, Default, Copy, Clone)]
933pub struct ReadSlot_t {
934 pub slot_name: [u8; 15usize],
935 pub _slot_config: u8,
936 pub slot_token_id: [u8; 13usize],
937 pub slot_counter: u64,
938}
939#[repr(C)]
940#[derive(Debug, Copy, Clone)]
941pub struct GetRandom_t {
942 pub op_success: u8,
943 pub size_effective: u8,
944 pub data: [u8; 51usize],
945}
946impl Default for GetRandom_t {
947 fn default() -> Self {
948 let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
949 unsafe {
950 ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
951 s.assume_init()
952 }
953 }
954}
955extern "C" {
956 pub fn NK_get_random(len: u8, out: *mut GetRandom_t) -> ::std::os::raw::c_int;
957}
958extern "C" {
959 pub fn NK_read_HOTP_slot(slot_num: u8, out: *mut ReadSlot_t) -> ::std::os::raw::c_int;
960}