Skip to main content

tss_esapi/
lib.rs

1// Copyright 2019 Contributors to the Parsec project.
2// SPDX-License-Identifier: Apache-2.0
3#![deny(
4    nonstandard_style,
5    dead_code,
6    improper_ctypes,
7    non_shorthand_field_patterns,
8    no_mangle_generic_items,
9    overflowing_literals,
10    path_statements,
11    patterns_in_fns_without_body,
12    private_bounds,
13    private_interfaces,
14    unconditional_recursion,
15    unused,
16    unused_allocation,
17    unused_comparisons,
18    unused_parens,
19    while_true,
20    missing_debug_implementations,
21    //TODO: activate this!
22    //missing_docs,
23    trivial_casts,
24    trivial_numeric_casts,
25    unused_extern_crates,
26    unused_import_braces,
27    unused_qualifications,
28    unused_results,
29    missing_copy_implementations,
30    rustdoc::broken_intra_doc_links,
31)]
32
33//! # TSS 2.0 Rust Wrapper over Enhanced System API
34//! This crate exposes the functionality of the TCG Software Stack Enhanced System API to
35//! Rust developers, both directly through FFI bindings and through more Rust-tailored interfaces
36//! at varying levels of abstraction.
37//! Only platforms based on processors with a word size of at least 16 bits are supported.
38//!
39//! # Relevant specifications
40//! This library is built with insight from Trusted Computing Group specifications. The specs most relevant
41//! here are:
42//! * the [Trusted Platform Module Library Specification, Family “2.0”, Level 00, Revision 01.59](https://trustedcomputinggroup.org/work-groups/trusted-platform-module/)
43//! * the [TCG TSS 2.0 Enhanced System API (ESAPI) Specification, version 1.00, revision 14](https://trustedcomputinggroup.org/resource/tcg-tss-2-0-enhanced-system-api-esapi-specification/)
44//!
45//! The different parts of the first spec mentioned above (henceforth called the TPM2 spec) can be
46//! referenced individually throughout the documentation of this crate, using their part number or name.
47//! For example,
48//! [Part 1, Architecture](https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p59_Part1_Architecture_pub.pdf)
49//! could be referenced as "the Architecture spec" or "part 1 of the TPM2 spec".
50//!
51//! The second spec mentioned above will henceforth be called the ESAPI or ESys spec.
52//!
53//! Some parts of the code relate to features or functionality defined in other specifications (such as the
54//! [Marshaling/Unmarshaling API v1, rev7 spec](https://trustedcomputinggroup.org/resource/tcg-tss-2-0-marshalingunmarshaling-api-specification/)),
55//! and in such cases the specification should be linked and referenced in full.
56//!
57//! # Code structure
58//! Our code structure is mostly derived from part 2 of the TPM2 spec.
59//! For simplicity, however, we have reduced the depth of the import tree, so most (if not all) types
60//! are at most one level away from root.
61//!
62//! Minimum supported Rust version (MSRV):
63//! We currently check with version 1.76.0 of the Rust compiler during CI builds.
64//!
65//! # Notes on code safety:
66//! * thread safety is ensured by the required mutability of the `Context` structure within the
67//!   methods implemented on it; thus, in an otherwise safe app commands cannot be dispatched in
68//!   parallel for the same context; whether multithreading with multiple context objects is possible
69//!   depends on the TCTI used and this is the responsibility of the crate client to establish.
70//! * the `unsafe` keyword is used to denote methods that could panic, crash or cause undefined
71//!   behaviour. Whenever this is the case, the properties that need to be checked against
72//!   parameters before passing them in will be stated in the documentation of the method.
73//! * `unsafe` blocks within this crate need to be documented through code comments if they
74//!   are not covered by the points of trust described here.
75//! * the TSS2.0 library that this crate links to is trusted to return consistent values and to
76//!   not crash or lead to undefined behaviour when presented with valid arguments.
77//! * the `Mbox` crate is trusted to perform operations safely on the pointers provided to it, if
78//!   the pointers are trusted to be valid.
79//! * methods not marked `unsafe` are trusted to behave safely, potentially returning appropriate
80//!   error messages when encountering any problems.
81//! * whenever `unwrap`, `expect`, `panic` or derivatives of these are used, they need to be
82//!   thoroughly documented and justified - preferably `unwrap` and `expect` should *never* fail
83//!   during normal operation.
84//! * these rules can be broken in test-only code and in tests.
85//!
86//! # Logging
87//! This crate uses the typical `log` crate for printing errors generated in method calls. If
88//! you would like to filter out these log messages, please check with your logger documentation
89//! on how to do that.
90//!
91//! Additionally, the TSS library will also generate its own log messages and these can be
92//! controlled through environment variables as explained
93//! [here](https://github.com/tpm2-software/tpm2-tss/blob/main/doc/logging.md#runtime-log-level).
94//!
95//! # Code examples
96//! The code examples in this documentation usually only showing a small part of all
97//! the steps that are necessary in order to make things work. For the most part it
98//! only shows the point of interest e.g. the code related to a context method call. It
99//! is therefore recommended to view the code for the whole example by looking at the
100//! source code or view the examples in our repository.
101
102mod context;
103
104pub mod error;
105pub use tss_esapi_sys as tss2_esys;
106#[cfg(feature = "abstraction")]
107pub mod abstraction;
108pub mod attributes;
109pub mod constants;
110pub mod handles;
111pub mod interface_types;
112pub mod structures;
113pub mod tcti_ldr;
114pub mod traits;
115pub mod utils;
116#[cfg(feature = "abstraction")]
117pub use abstraction::transient::TransientKeyContext;
118pub use context::Context;
119pub use error::{Error, Result, ReturnCode, WrapperErrorKind};
120pub use tcti_ldr::TctiNameConf;
121// To replace painlessly the old Tcti structure, should maybe be deprecated at some point.
122pub use tcti_ldr::TctiNameConf as Tcti;
123
124// Internal modules
125pub(crate) mod ffi;