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