1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use crate::{
Context, Result, ReturnCode, handles::AuthHandle, interface_types::algorithm::HashingAlgorithm,
structures::CommandCodeList, tss2_esys::Esys_SetCommandCodeAuditStatus,
};
use log::error;
impl Context {
/// Set the command code audit status.
///
/// # Arguments
///
/// * `auth_handle` - An [AuthHandle] for the authorization (Owner or Platform).
/// * `audit_algorithm` - The [HashingAlgorithm] for the audit digest.
/// * `set_list` - A [CommandCodeList] of command codes to add to the audit list.
/// * `clear_list` - A [CommandCodeList] of command codes to remove from the audit list.
///
/// # Details
///
/// *From the specification*
/// > This command may be used by the Privacy Administrator or platform
/// > to change the audit status of a command or to set the hash
/// > algorithm used for the audit digest.
///
/// # Example
///
/// ```rust
/// # use tss_esapi::{Context, TctiNameConf};
/// # use tss_esapi::handles::AuthHandle;
/// # use tss_esapi::interface_types::{
/// # algorithm::HashingAlgorithm,
/// # session_handles::AuthSession,
/// # };
/// # use tss_esapi::structures::CommandCodeList;
/// # let mut context =
/// # Context::new(
/// # TctiNameConf::from_environment_variable().expect("Failed to get TCTI"),
/// # ).expect("Failed to create Context");
/// context
/// .execute_with_sessions((Some(AuthSession::Password), None, None), |ctx| {
/// ctx.set_command_code_audit_status(
/// AuthHandle::Owner,
/// HashingAlgorithm::Sha256,
/// CommandCodeList::new(),
/// CommandCodeList::new(),
/// )
/// })
/// .expect("Failed to set command code audit status");
/// ```
pub fn set_command_code_audit_status(
&mut self,
auth_handle: AuthHandle,
audit_algorithm: HashingAlgorithm,
set_list: CommandCodeList,
clear_list: CommandCodeList,
) -> Result<()> {
ReturnCode::ensure_success(
unsafe {
Esys_SetCommandCodeAuditStatus(
self.mut_context(),
auth_handle.into(),
self.required_session_1()?,
self.optional_session_2(),
self.optional_session_3(),
audit_algorithm.into(),
&set_list.into(),
&clear_list.into(),
)
},
|ret| {
error!("Error setting command code audit status: {:#010X}", ret);
},
)
}
}