Skip to content

Commit 896d6be

Browse files
committed
Document (un)marshalling FFI type
Adding comments to the `marshall` and `unmarshall` methods to describe the type of the bytes produced/expected from the operation. Also fixing some typos. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent ffe6681 commit 896d6be

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

tss-esapi/src/structures/attestation/attest.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Attest {
2727
}
2828

2929
impl Attest {
30-
/// Returns ttestation type
30+
/// Returns attestation type
3131
pub const fn attestation_type(&self) -> AttestationType {
3232
self.attestation_type
3333
}
@@ -37,7 +37,7 @@ impl Attest {
3737
&self.qualified_signer
3838
}
3939

40-
/// Retirns the extra data specified by the caller.
40+
/// Returns the extra data specified by the caller.
4141
pub const fn extra_data(&self) -> &Data {
4242
&self.extra_data
4343
}
@@ -121,6 +121,7 @@ impl TryFrom<TPMS_ATTEST> for Attest {
121121
impl Marshall for Attest {
122122
const BUFFER_SIZE: usize = std::mem::size_of::<TPMS_ATTEST>();
123123

124+
/// Produce a marshalled [`TPMS_ATTEST`]
124125
fn marshall(&self) -> Result<Vec<u8>> {
125126
let mut buffer = vec![0; Self::BUFFER_SIZE];
126127
let mut offset = 0;
@@ -153,6 +154,7 @@ impl Marshall for Attest {
153154
}
154155

155156
impl UnMarshall for Attest {
157+
/// Unmarshall the structure from [`TPMS_ATTEST`]
156158
fn unmarshall(marshalled_data: &[u8]) -> Result<Self> {
157159
let mut dest = TPMS_ATTEST::default();
158160
let mut offset = 0;

tss-esapi/src/structures/buffers/public.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl TryFrom<Public> for PublicBuffer {
119119
impl Marshall for PublicBuffer {
120120
const BUFFER_SIZE: usize = std::mem::size_of::<TPM2B_PUBLIC>();
121121

122+
/// Produce a marshalled [`TPM2B_PUBLIC`]
122123
fn marshall(&self) -> Result<Vec<u8>> {
123124
let mut buffer = vec![0; Self::BUFFER_SIZE];
124125
let mut offset = 0;
@@ -151,6 +152,7 @@ impl Marshall for PublicBuffer {
151152
}
152153

153154
impl UnMarshall for PublicBuffer {
155+
/// Unmarshall the structure from [`TPM2B_PUBLIC`]
154156
fn unmarshall(marshalled_data: &[u8]) -> Result<Self> {
155157
let mut dest = TPM2B_PUBLIC::default();
156158
let mut offset = 0;

tss-esapi/src/structures/buffers/sensitive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl TryFrom<Sensitive> for SensitiveBuffer {
118118
impl Marshall for SensitiveBuffer {
119119
const BUFFER_SIZE: usize = std::mem::size_of::<TPM2B_SENSITIVE>();
120120

121+
/// Produce a marshalled [`TPM2B_SENSITIVE`]
121122
fn marshall(&self) -> Result<Vec<u8>> {
122123
let mut buffer = vec![0; Self::BUFFER_SIZE];
123124
let mut offset = 0;
@@ -150,6 +151,7 @@ impl Marshall for SensitiveBuffer {
150151
}
151152

152153
impl UnMarshall for SensitiveBuffer {
154+
/// Unmarshall the structure from [`TPM2B_SENSITIVE`]
153155
fn unmarshall(marshalled_data: &[u8]) -> Result<Self> {
154156
let mut dest = TPM2B_SENSITIVE::default();
155157
let mut offset = 0;

tss-esapi/src/structures/tagged/public.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl PublicBuilder {
7676
self
7777
}
7878

79-
/// Adds the name hash algorithm for the [Public] strucutre
79+
/// Adds the name hash algorithm for the [Public] structure
8080
/// to the builder.
8181
pub const fn with_name_hashing_algorithm(
8282
mut self,
@@ -86,7 +86,7 @@ impl PublicBuilder {
8686
self
8787
}
8888

89-
/// Adds the auth policy for the [Public] strucutre
89+
/// Adds the auth policy for the [Public] structure
9090
/// to the builder
9191
pub fn with_auth_policy(mut self, auth_policy: Digest) -> Self {
9292
self.auth_policy = Some(auth_policy);
@@ -494,6 +494,9 @@ impl TryFrom<TPMT_PUBLIC> for Public {
494494
impl Marshall for Public {
495495
const BUFFER_SIZE: usize = std::mem::size_of::<TPMT_PUBLIC>();
496496

497+
/// Produce a marshalled [TPMT_PUBLIC]
498+
///
499+
/// Note: for [TPM2B_PUBLIC] marshalling use [PublicBuffer][`crate::structures::PublicBuffer]
497500
fn marshall(&self) -> Result<Vec<u8>> {
498501
let mut buffer = vec![0; Self::BUFFER_SIZE];
499502
let mut offset = 0;
@@ -526,6 +529,9 @@ impl Marshall for Public {
526529
}
527530

528531
impl UnMarshall for Public {
532+
/// Unmarshall the structure from [`TPMT_PUBLIC`]
533+
///
534+
/// Note: for [TPM2B_PUBLIC] unmarshalling use [PublicBuffer][`crate::structures::PublicBuffer]
529535
fn unmarshall(marshalled_data: &[u8]) -> Result<Self> {
530536
let mut dest = TPMT_PUBLIC::default();
531537
let mut offset = 0;

tss-esapi/src/structures/tagged/sensitive.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ impl TryFrom<TPMT_SENSITIVE> for Sensitive {
166166
impl Marshall for Sensitive {
167167
const BUFFER_SIZE: usize = std::mem::size_of::<TPMT_SENSITIVE>();
168168

169+
/// Produce a marshalled [`TPMT_SENSITIVE`]
170+
///
171+
/// Note: for [TPM2B_SENSITIVE] marshalling use [SensitiveBuffer][`crate::structures::SensitiveBuffer]
169172
fn marshall(&self) -> Result<Vec<u8>> {
170173
let mut buffer = vec![0; Self::BUFFER_SIZE];
171174
let mut offset = 0;
@@ -198,6 +201,9 @@ impl Marshall for Sensitive {
198201
}
199202

200203
impl UnMarshall for Sensitive {
204+
/// Unmarshall the structure from [`TPMT_SENSITIVE`]
205+
///
206+
/// Note: for [TPM2B_SENSITIVE] marshalling use [SensitiveBuffer][`crate::structures::SensitiveBuffer]
201207
fn unmarshall(marshalled_data: &[u8]) -> Result<Self> {
202208
let mut dest = TPMT_SENSITIVE::default();
203209
let mut offset = 0;

tss-esapi/src/structures/tagged/signature.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl TryFrom<TPMT_SIGNATURE> for Signature {
132132
impl Marshall for Signature {
133133
const BUFFER_SIZE: usize = std::mem::size_of::<TPMT_SIGNATURE>();
134134

135+
/// Produce a marshalled [`TPMT_SIGNATURE`]
135136
fn marshall(&self) -> Result<Vec<u8>> {
136137
let tpmt_sig = TPMT_SIGNATURE::try_from(self.clone())?;
137138
let mut offset = 0;
@@ -164,6 +165,7 @@ impl Marshall for Signature {
164165
}
165166

166167
impl UnMarshall for Signature {
168+
/// Unmarshall the structure from [`TPMT_SIGNATURE`]
167169
fn unmarshall(public_buffer: &[u8]) -> Result<Self> {
168170
let mut tpmt_sig = TPMT_SIGNATURE::default();
169171
let mut offset = 0;

tss-esapi/src/structures/tagged/symmetric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
Error, Result, WrapperErrorKind,
1010
};
1111
use std::convert::{TryFrom, TryInto};
12-
/// Enum repsesnting the symmetric algorithm definition.
12+
/// Enum representing the symmetric algorithm definition.
1313
///
1414
/// # Details
1515
/// This corresponds to TPMT_SYM_DEF.

0 commit comments

Comments
 (0)