1#![doc = include_str!("../README.md")]
4#![allow(renamed_and_removed_lints, unknown_lints)]
7#![deny(bad_style,
8 dead_code,
9 improper_ctypes,
10 non_shorthand_field_patterns,
11 no_mangle_generic_items,
12 overflowing_literals,
13 path_statements ,
14 patterns_in_fns_without_body,
15 private_bounds,
16 private_in_public,
17 private_interfaces,
18 renamed_and_removed_lints,
19 unconditional_recursion,
20 unnameable_types,
21 unused,
22 unused_allocation,
23 unused_comparisons,
24 unused_parens,
25 while_true,
26 missing_debug_implementations,
27 missing_copy_implementations,
28 missing_docs,
29 trivial_numeric_casts,
32 unused_extern_crates,
33 unused_import_braces,
34 unused_qualifications,
35 unused_results)]
36
37#[macro_use]
41pub mod context;
42
43pub mod error;
44pub mod mechanism;
45pub mod object;
46pub mod session;
47pub mod slot;
48pub mod types;
49
50use cryptoki_sys::CK_UTF8CHAR;
51
52fn string_from_blank_padded(field: &[CK_UTF8CHAR]) -> String {
53 let decoded_str = String::from_utf8_lossy(field);
54 decoded_str.trim_end_matches(' ').to_string()
55}
56
57fn label_from_str(label: &str) -> [CK_UTF8CHAR; 32] {
58 let mut lab: [CK_UTF8CHAR; 32] = [32; 32];
59 let mut i = 0;
60 for c in label.chars() {
61 if i + c.len_utf8() <= 32 {
62 let mut buf = [0; 4];
63 let bytes = c.encode_utf8(&mut buf).as_bytes();
64 for b in bytes {
65 lab[i] = *b;
66 i += 1;
67 }
68 } else {
69 break;
70 }
71 }
72 lab
73}