Skip to content

Commit dfe4d73

Browse files
committed
Fixed BaseError display trait impl.
- Changed to the displayed messages to proper sentences and also add information that is relevant for this crate. - Added tests for missing items. - Added documentation build check for CI. Co-authored-by: Wiktor Kwapisiewicz <[email protected]> Signed-off-by: Jesper Brynolf <[email protected]>
1 parent 9a9355e commit dfe4d73

File tree

6 files changed

+227
-109
lines changed

6 files changed

+227
-109
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ jobs:
4646
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/all-ubuntu.sh
4747
- name: Run the cross-compilation script
4848
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/cross-compile.sh
49-
- name: Check the documentation
50-
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi ubuntucontainer cargo doc
5149

5250
tests-ubuntu-v3:
5351
name: Ubuntu tests on v3.x.y of tpm2-tss
@@ -90,3 +88,14 @@ jobs:
9088
run: docker build -t ubuntucontainer tss-esapi/tests/ --file tss-esapi/tests/Dockerfile-ubuntu
9189
- name: Run the tests
9290
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi ubuntucontainer /tmp/rust-tss-esapi/tss-esapi/tests/valgrind.sh
91+
92+
# Check that the documentation builds as well.
93+
docs:
94+
name: Check documentation
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@v2
98+
- name: Build the container
99+
run: docker build -t ubuntucontainer tss-esapi/tests/ --file tss-esapi/tests/Dockerfile-ubuntu
100+
- name: Check documentation
101+
run: docker run -v $(pwd):/tmp/rust-tss-esapi -w /tmp/rust-tss-esapi/tss-esapi -e RUSTDOCFLAGS="-Dwarnings" ubuntucontainer cargo doc --document-private-items --no-deps

tss-esapi/src/constants/return_code/base_error.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,58 +55,118 @@ use std::convert::TryFrom;
5555
#[derive(FromPrimitive, ToPrimitive, Copy, Clone, Debug, PartialEq, Eq, Hash)]
5656
#[repr(u16)]
5757
pub enum BaseError {
58+
/// Catch all for all errors not otherwise specified.
5859
GeneralFailure = TSS2_BASE_RC_GENERAL_FAILURE as u16,
60+
/// If called functionality isn't implemented.
5961
NotImplemented = TSS2_BASE_RC_NOT_IMPLEMENTED as u16,
62+
/// A context structure is bad.
6063
BadContext = TSS2_BASE_RC_BAD_CONTEXT as u16,
64+
/// Passed in ABI version doesn't match called module's ABI version.
6165
AbiMismatch = TSS2_BASE_RC_ABI_MISMATCH as u16,
66+
/// A pointer is NULL that isn't allowed to be NULL.
6267
BadReference = TSS2_BASE_RC_BAD_REFERENCE as u16,
68+
/// A buffer isn't large enough.
6369
InsufficientBuffer = TSS2_BASE_RC_INSUFFICIENT_BUFFER as u16,
70+
/// Function called in the wrong order.
6471
BadSequence = TSS2_BASE_RC_BAD_SEQUENCE as u16,
72+
/// Fails to connect to next lower layer.
6573
NoConnection = TSS2_BASE_RC_NO_CONNECTION as u16,
74+
/// Operation timed out; function must be called again to be completed.
6675
TryAgain = TSS2_BASE_RC_TRY_AGAIN as u16,
76+
/// IO failure.
6777
IoError = TSS2_BASE_RC_IO_ERROR as u16,
78+
/// A parameter has a bad value.
6879
BadValue = TSS2_BASE_RC_BAD_VALUE as u16,
80+
/// Operation not permitted.
6981
NotPermitted = TSS2_BASE_RC_NOT_PERMITTED as u16,
82+
/// The TPM command doesn't use the number of sessions provided by the caller.
7083
InvalidSessions = TSS2_BASE_RC_INVALID_SESSIONS as u16,
84+
/// A session with `decrypt` set in its [SessionAttributes](crate::attributes::SessionAttributes)
85+
/// (TPMA_SESSION_DECRYPT bit set) was passed to a TPM command that doesn't support encryption
86+
/// of the first command parameter.
7187
NoDecryptParam = TSS2_BASE_RC_NO_DECRYPT_PARAM as u16,
88+
/// A session with `encrypt` set in its [SessionAttributes](crate::attributes::SessionAttributes)
89+
/// (TPMA_SESSION_ENCRYPT bit set) was passed to a TPM command that doesn't support encryption
90+
/// of the first response parameter.
7291
NoEncryptParam = TSS2_BASE_RC_NO_ENCRYPT_PARAM as u16,
92+
/// If size of a parameter is incorrect.
7393
BadSize = TSS2_BASE_RC_BAD_SIZE as u16,
94+
/// Response is malformed.
7495
MalformedResponse = TSS2_BASE_RC_MALFORMED_RESPONSE as u16,
96+
/// Context not large enough.
7597
InsufficientContext = TSS2_BASE_RC_INSUFFICIENT_CONTEXT as u16,
98+
/// Response is not long enough.
7699
InsufficientResponse = TSS2_BASE_RC_INSUFFICIENT_RESPONSE as u16,
100+
/// Unknown or unusable TCTI version.
77101
IncompatibleTcti = TSS2_BASE_RC_INCOMPATIBLE_TCTI as u16,
102+
/// Functionality not supported.
78103
NotSupported = TSS2_BASE_RC_NOT_SUPPORTED as u16,
104+
/// TCTI context is bad.
79105
BadTctiStructure = TSS2_BASE_RC_BAD_TCTI_STRUCTURE as u16,
106+
/// Memory allocation failed.
80107
Memory = TSS2_BASE_RC_MEMORY as u16,
108+
/// Invalid [ObjectHandle](crate::handles::ObjectHandle)
109+
/// (ESYS_TR handle).
81110
BadTr = TSS2_BASE_RC_BAD_TR as u16,
111+
/// More than one session with `decrypt` set in its [SessionAttributes](crate::attributes::SessionAttributes)
112+
/// (TPMA_SESSION_DECRYPT bit set).
82113
MultipleDecryptSessions = TSS2_BASE_RC_MULTIPLE_DECRYPT_SESSIONS as u16,
114+
/// More than one session with encrypt set its [SessionAttributes](crate::attributes::SessionAttributes)
115+
/// (TPMA_SESSION_ENCRYPT bit set).
83116
MultipleEncryptSessions = TSS2_BASE_RC_MULTIPLE_ENCRYPT_SESSIONS as u16,
117+
/// Authorizing the TPM response failed.
84118
RspAuthFailed = TSS2_BASE_RC_RSP_AUTH_FAILED as u16,
119+
/// No config is available.
85120
NoConfig = TSS2_BASE_RC_NO_CONFIG as u16,
121+
/// The provided path is bad.
86122
BadPath = TSS2_BASE_RC_BAD_PATH as u16,
123+
/// The object is not deletable.
87124
NotDeletable = TSS2_BASE_RC_NOT_DELETABLE as u16,
125+
/// The provided path already exists.
88126
PathAlreadyExists = TSS2_BASE_RC_PATH_ALREADY_EXISTS as u16,
127+
/// The key was not found.
89128
KeyNotFound = TSS2_BASE_RC_KEY_NOT_FOUND as u16,
129+
/// Signature verification failed.
90130
SignatureVerificationFailed = TSS2_BASE_RC_SIGNATURE_VERIFICATION_FAILED as u16,
131+
/// Hash mismatch.
91132
HashMismatch = TSS2_BASE_RC_HASH_MISMATCH as u16,
133+
/// Key is not duplicatable.
92134
KeyNotDuplicable = TSS2_BASE_RC_KEY_NOT_DUPLICABLE as u16,
135+
/// The path was not found.
93136
PathNotFound = TSS2_BASE_RC_PATH_NOT_FOUND as u16,
137+
/// No certificate.
94138
NoCert = TSS2_BASE_RC_NO_CERT as u16,
139+
/// No PCR.
95140
NoPcr = TSS2_BASE_RC_NO_PCR as u16,
141+
/// PCR not resettable.
96142
PcrNotResettable = TSS2_BASE_RC_PCR_NOT_RESETTABLE as u16,
143+
/// The template is bad.
97144
BadTemplate = TSS2_BASE_RC_BAD_TEMPLATE as u16,
145+
/// Authorization failed.
98146
AuthorizationFailed = TSS2_BASE_RC_AUTHORIZATION_FAILED as u16,
147+
/// Authorization is unknown.
99148
AuthorizationUnknown = TSS2_BASE_RC_AUTHORIZATION_UNKNOWN as u16,
149+
/// NV is not readable.
100150
NvNotReadable = TSS2_BASE_RC_NV_NOT_READABLE as u16,
151+
/// NV is too small.
101152
NvTooSmall = TSS2_BASE_RC_NV_TOO_SMALL as u16,
153+
/// NV is not writable.
102154
NvNotWriteable = TSS2_BASE_RC_NV_NOT_WRITEABLE as u16,
155+
/// The policy is unknown.
103156
PolicyUnknown = TSS2_BASE_RC_POLICY_UNKNOWN as u16,
157+
/// The NV type is wrong.
104158
NvWrongType = TSS2_BASE_RC_NV_WRONG_TYPE as u16,
159+
/// The name already exists.
105160
NameAlreadyExists = TSS2_BASE_RC_NAME_ALREADY_EXISTS as u16,
161+
/// No TPM available.
106162
NoTpm = TSS2_BASE_RC_NO_TPM as u16,
163+
/// The key is bad.
107164
BadKey = TSS2_BASE_RC_BAD_KEY as u16,
165+
/// No handle provided.
108166
NoHandle = TSS2_BASE_RC_NO_HANDLE as u16,
167+
/// Provisioning was not executed.
109168
NotProvisioned = TSS2_BASE_RC_NOT_PROVISIONED as u16,
169+
/// Already provisioned.
110170
AlreadyProvisioned = TSS2_BASE_RC_ALREADY_PROVISIONED as u16,
111171
}
112172

tss-esapi/src/error/return_code/base.rs

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,59 +47,70 @@ impl std::error::Error for BaseReturnCode {}
4747
impl std::fmt::Display for BaseReturnCode {
4848
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4949
match self.base_error {
50-
BaseError::GeneralFailure => write!(f, "General Error"),
51-
BaseError::NotImplemented => write!(f, "Not Implemented"),
52-
BaseError::BadContext => write!(f, "Bad Context"),
53-
BaseError::AbiMismatch => write!(f, "ABI Mismatch"),
54-
BaseError::BadReference => write!(f, "Bad Reference"),
55-
BaseError::InsufficientBuffer => write!(f, "Insufficient Buffer"),
56-
BaseError::BadSequence => write!(f, "Bad Sequence"),
57-
BaseError::NoConnection => write!(f, "No Connection"),
58-
BaseError::TryAgain => write!(f, "Try Again"),
59-
BaseError::IoError => write!(f, "IO Error"),
60-
BaseError::BadValue => write!(f, "Bad Value"),
61-
BaseError::NotPermitted => write!(f, "Not Permitted"),
62-
BaseError::InvalidSessions => write!(f, "Invalid Sessions"),
63-
BaseError::NoDecryptParam => write!(f, "No Decrypt Param"),
64-
BaseError::NoEncryptParam => write!(f, "No Encrypt Param"),
65-
BaseError::BadSize => write!(f, "Bad Size"),
66-
BaseError::MalformedResponse => write!(f, "Malformed Response"),
67-
BaseError::InsufficientContext => write!(f, "Insufficient Context"),
68-
BaseError::InsufficientResponse => write!(f, "Insufficient Response"),
69-
BaseError::IncompatibleTcti => write!(f, "Incompatible TCTI"),
70-
BaseError::NotSupported => write!(f, "Not Supported"),
71-
BaseError::BadTctiStructure => write!(f, "Bad TCTI Structure"),
72-
BaseError::Memory => write!(f, "Memory"),
73-
BaseError::BadTr => write!(f, "Bad TR"),
74-
BaseError::MultipleDecryptSessions => write!(f, "Multiple Decrypt Sessions"),
75-
BaseError::MultipleEncryptSessions => write!(f, "Multiple Encrypt Sessions"),
76-
BaseError::RspAuthFailed => write!(f, "RSP Auth Failed"),
77-
BaseError::NoConfig => write!(f, "No Config"),
78-
BaseError::BadPath => write!(f, "Bad Path"),
79-
BaseError::NotDeletable => write!(f, "Not Deletable"),
80-
BaseError::PathAlreadyExists => write!(f, "Path Already Exists"),
81-
BaseError::KeyNotFound => write!(f, "Key Not Found"),
82-
BaseError::SignatureVerificationFailed => write!(f, "Signature Verification Failed"),
83-
BaseError::HashMismatch => write!(f, "Hash Mismatch"),
84-
BaseError::KeyNotDuplicable => write!(f, "Key Not Duplicable"),
85-
BaseError::PathNotFound => write!(f, "Path Not Found"),
86-
BaseError::NoCert => write!(f, "No Cert"),
87-
BaseError::NoPcr => write!(f, "No PCR"),
88-
BaseError::PcrNotResettable => write!(f, "PCR Not Resettable"),
89-
BaseError::BadTemplate => write!(f, "Bad Template"),
90-
BaseError::AuthorizationFailed => write!(f, "Authorization Failed"),
91-
BaseError::AuthorizationUnknown => write!(f, "Authorization Unknown"),
92-
BaseError::NvNotReadable => write!(f, "NV Not Readable"),
93-
BaseError::NvTooSmall => write!(f, "NV Too Small"),
94-
BaseError::NvNotWriteable => write!(f, "NV Not Writeable"),
95-
BaseError::PolicyUnknown => write!(f, "Policy Unknown"),
96-
BaseError::NvWrongType => write!(f, "NV Wrong Type"),
97-
BaseError::NameAlreadyExists => write!(f, "Name Already Exists"),
98-
BaseError::NoTpm => write!(f, "No TPM"),
99-
BaseError::BadKey => write!(f, "Bad Key"),
100-
BaseError::NoHandle => write!(f, "No Handle"),
101-
BaseError::NotProvisioned => write!(f, "Not Provisioned"),
102-
BaseError::AlreadyProvisioned => write!(f, "Already Provisioned"),
50+
BaseError::GeneralFailure => write!(f, "An unspecified error occurred."),
51+
BaseError::NotImplemented => write!(f, "Called functionality isn't implemented."),
52+
BaseError::BadContext => write!(f, "A context structure is bad."),
53+
BaseError::AbiMismatch => write!(
54+
f,
55+
"Passed in ABI version doesn't match called module's ABI version."
56+
),
57+
BaseError::BadReference => {
58+
write!(f, "A pointer is NULL that isn't allowed to be NULL.")
59+
}
60+
BaseError::InsufficientBuffer => write!(f, "A buffer isn't large enough."),
61+
BaseError::BadSequence => write!(f, "Function called in the wrong order."),
62+
BaseError::NoConnection => write!(f, "Fails to connect to next lower layer."),
63+
BaseError::TryAgain => write!(
64+
f,
65+
"Operation timed out; function must be called again to be completed."
66+
),
67+
BaseError::IoError => write!(f, "IO failure."),
68+
BaseError::BadValue => write!(f, "A parameter has a bad value."),
69+
BaseError::NotPermitted => write!(f, "Operation not permitted."),
70+
BaseError::InvalidSessions => write!(
71+
f,
72+
"The TPM command doesn't use the number of sessions provided by the caller."
73+
),
74+
BaseError::NoDecryptParam => write!(f, "A session with decrypt set in its SessionAttributes (TPMA_SESSION_DECRYPT bit set) was passed to a TPM command that doesn't support encryption of the first command parameter."),
75+
BaseError::NoEncryptParam => write!(f, "A session with encrypt set in its SessionAttributes (TPMA_SESSION_ENCRYPT bit set) was passed to a TPM command that doesn't support encryption of the first response parameter."),
76+
BaseError::BadSize => write!(f, "Size of a parameter is incorrect."),
77+
BaseError::MalformedResponse => write!(f, "Response is malformed."),
78+
BaseError::InsufficientContext => write!(f, "Context not large enough."),
79+
BaseError::InsufficientResponse => write!(f, "Response is not long enough."),
80+
BaseError::IncompatibleTcti => write!(f, "Unknown or unusable TCTI version."),
81+
BaseError::NotSupported => write!(f, "Functionality not supported."),
82+
BaseError::BadTctiStructure => write!(f, "TCTI context is bad."),
83+
BaseError::Memory => write!(f, "Memory allocation failed."),
84+
BaseError::BadTr => write!(f, "Invalid ObjectHandle(ESYS_TR handle)."),
85+
BaseError::MultipleDecryptSessions => write!(f, "More than one session with decrypt set in SessionAttributes (TPMA_SESSION_DECRYPT bit set)."),
86+
BaseError::MultipleEncryptSessions => write!(f, "More than one session with encrypt set in SessionAttributes (TPMA_SESSION_ENCRYPT bit set)."),
87+
BaseError::RspAuthFailed => write!(f, "Authorizing the TPM response failed."),
88+
BaseError::NoConfig => write!(f, "No config is available."),
89+
BaseError::BadPath => write!(f, "The provided path is bad."),
90+
BaseError::NotDeletable => write!(f, "The object is not deletable."),
91+
BaseError::PathAlreadyExists => write!(f, "The provided path already exists."),
92+
BaseError::KeyNotFound => write!(f, "The key was not found."),
93+
BaseError::SignatureVerificationFailed => write!(f, "Signature verification failed."),
94+
BaseError::HashMismatch => write!(f, "Hash mismatch."),
95+
BaseError::KeyNotDuplicable => write!(f, "Key is not duplicatable."),
96+
BaseError::PathNotFound => write!(f, "The path was not found."),
97+
BaseError::NoCert => write!(f, "No certificate."),
98+
BaseError::NoPcr => write!(f, "No PCR."),
99+
BaseError::PcrNotResettable => write!(f, "PCR not resettable."),
100+
BaseError::BadTemplate => write!(f, "The template is bad."),
101+
BaseError::AuthorizationFailed => write!(f, "Authorization failed."),
102+
BaseError::AuthorizationUnknown => write!(f, "Authorization is unknown."),
103+
BaseError::NvNotReadable => write!(f, "NV is not readable."),
104+
BaseError::NvTooSmall => write!(f, "NV is too small."),
105+
BaseError::NvNotWriteable => write!(f, "NV is not writable."),
106+
BaseError::PolicyUnknown => write!(f, "The policy is unknown."),
107+
BaseError::NvWrongType => write!(f, "The NV type is wrong."),
108+
BaseError::NameAlreadyExists => write!(f, "The name already exists."),
109+
BaseError::NoTpm => write!(f, "No TPM available."),
110+
BaseError::BadKey => write!(f, "The key is bad."),
111+
BaseError::NoHandle => write!(f, "No handle provided."),
112+
BaseError::NotProvisioned => write!(f, "Provisioning was not executed."),
113+
BaseError::AlreadyProvisioned => write!(f, "Already provisioned."),
103114
}
104115
}
105116
}

tss-esapi/src/interface_types/session_handles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub enum AuthSession {
9292
}
9393

9494
impl AuthSession {
95-
/// Function that creates a Option<Session>.
95+
/// Function that creates a `Option<Session>`.
9696
///
9797
/// If a Session is created from the NoneHandle
9898
/// then the returned value from the function will be None.

tss-esapi/src/structures/lists/pcr_selection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl PcrSelectionList {
5252
Ok(())
5353
}
5454

55-
/// Function for retrieving the PcrSelectionList from Option<PcrSelectionList>
55+
/// Function for retrieving the PcrSelectionList from `Option<PcrSelectionList>`
5656
///
5757
/// This returns an empty list if None is passed
5858
pub fn list_from_option(pcr_list: Option<PcrSelectionList>) -> PcrSelectionList {

0 commit comments

Comments
 (0)