Skip to content

Commit 175b14c

Browse files
committed
feat!: rename TPM2TOOLS_TCTI to RUST_TPM2_CLI_TCTI
To prevent unintended conflicts between rust-tpm2-cli and tpm2-tools, rename the TCTI environment variable across the project. Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
1 parent e397b65 commit 175b14c

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ newgrp tss
6060
ls -l /dev/tpm*
6161

6262
# Set TPM device path used by rust-tpm2-cli
63-
export TPM2TOOLS_TCTI="device:/dev/tpm0"
63+
export RUST_TPM2_CLI_TCTI="device:/dev/tpm0"
6464
```
6565

6666
### Set up swtpm (software TPM simulator)
@@ -85,7 +85,7 @@ swtpm socket \
8585
--flags startup-clear
8686

8787
# In another terminal:
88-
export TPM2TOOLS_TCTI="swtpm:host=localhost,port=2321"
88+
export RUST_TPM2_CLI_TCTI="swtpm:host=localhost,port=2321"
8989
```
9090

9191
### Run integration tests

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub struct Cli {
1818

1919
#[derive(Parser)]
2020
pub struct GlobalOpts {
21-
/// TCTI configuration (e.g. device:/dev/tpm0, mssim:host=localhost,port=2321)
22-
#[arg(short = 'T', long = "tcti", env = "TPM2TOOLS_TCTI")]
21+
/// TCTI configuration (e.g. device:/dev/tpm0, swtpm:host=localhost,port=2321)
22+
#[arg(short = 'T', long = "tcti", env = "RUST_TPM2_CLI_TCTI")]
2323
pub tcti: Option<String>,
2424

2525
/// Enable errata fixups

src/raw_esys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::ptr::{null, null_mut};
1313
use anyhow::{Context, bail};
1414
use tss_esapi::tss2_esys::*;
1515

16+
use crate::tcti::DEFAULT_TCTI;
17+
1618
// -----------------------------------------------------------------------
1719
// Raw context helpers
1820
// -----------------------------------------------------------------------
@@ -27,9 +29,7 @@ impl RawEsysContext {
2729
pub(crate) fn new(tcti: Option<&str>) -> anyhow::Result<Self> {
2830
let tcti_str = match tcti {
2931
Some(s) => s.to_owned(),
30-
None => {
31-
std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| "device:/dev/tpm0".to_owned())
32-
}
32+
None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()),
3333
};
3434
let c_str = CString::new(tcti_str.as_str()).context("TCTI string contains NUL")?;
3535

src/tcti.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ pub(crate) const DEFAULT_DEVICE_PATH: &str = "/dev/tpm0";
1414

1515
/// Parse a TCTI configuration string into a [`TctiNameConf`].
1616
///
17-
/// If `tcti` is `None`, falls back to the `TPM2TOOLS_TCTI` environment
17+
/// If `tcti` is `None`, falls back to the `RUST_TPM2_CLI_TCTI` environment
1818
/// variable, then to `device:/dev/tpm0`.
1919
pub fn parse_tcti(tcti: Option<&str>) -> Result<TctiNameConf, Tpm2Error> {
2020
let tcti_str = match tcti {
2121
Some(s) => s.to_owned(),
22-
None => std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()),
22+
None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()),
2323
};
2424
TctiNameConf::from_str(&tcti_str).map_err(|e| Tpm2Error::InvalidTcti(e.to_string()))
2525
}
@@ -30,7 +30,7 @@ pub fn parse_tcti(tcti: Option<&str>) -> Result<TctiNameConf, Tpm2Error> {
3030
pub(crate) fn extract_device_path(tcti: Option<&str>) -> String {
3131
let tcti_str = match tcti {
3232
Some(s) => s.to_owned(),
33-
None => std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()),
33+
None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()),
3434
};
3535
if let Some(rest) = tcti_str.strip_prefix("device:") {
3636
rest.to_owned()

tests/helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ summary() {
5959
return 0
6060
}
6161

62-
# Start an swtpm simulator and set TPM2TOOLS_TCTI.
62+
# Start an swtpm simulator and set RUST_TPM2_CLI_TCTI.
6363
start_swtpm() {
6464
TEST_TMPDIR="$(mktemp -d)"
6565
export TEST_TMPDIR
@@ -84,7 +84,7 @@ start_swtpm() {
8484
sleep 0.1
8585
done
8686

87-
export TPM2TOOLS_TCTI="swtpm:host=localhost,port=${SWTPM_PORT}"
87+
export RUST_TPM2_CLI_TCTI="swtpm:host=localhost,port=${SWTPM_PORT}"
8888
}
8989

9090
# Stop swtpm and clean up.

0 commit comments

Comments
 (0)