Create Emulator Instance # Arguments `path` - A path to the Unix Domain Socket swtpm is listening on
(path: impl AsRef<Path>)
| 87 | /// * `path` - A path to the Unix Domain Socket swtpm is listening on |
| 88 | /// |
| 89 | pub fn new(path: impl AsRef<Path>) -> Result<Self> { |
| 90 | let path = path.as_ref(); |
| 91 | if !path.exists() { |
| 92 | return Err(Error::InitializeEmulator(anyhow!( |
| 93 | "The input TPM Socket path: {:?} does not exist", |
| 94 | path.to_str().unwrap() |
| 95 | ))); |
| 96 | } |
| 97 | let mut socket = SocketDev::new(); |
| 98 | socket.init(path).map_err(|e| { |
| 99 | Error::InitializeEmulator(anyhow!("Failed while initializing tpm emulator: {e:?}")) |
| 100 | })?; |
| 101 | |
| 102 | let mut emulator = Self { |
| 103 | caps: 0, |
| 104 | control_socket: socket, |
| 105 | data_fd: -1, |
| 106 | established_flag_cached: false, |
| 107 | established_flag: false, |
| 108 | }; |
| 109 | |
| 110 | emulator.prepare_data_fd()?; |
| 111 | |
| 112 | emulator.probe_caps()?; |
| 113 | if !emulator.check_caps() { |
| 114 | return Err(Error::InitializeEmulator(anyhow!( |
| 115 | "Required capabilities not supported by tpm backend" |
| 116 | ))); |
| 117 | } |
| 118 | |
| 119 | if !emulator.get_established_flag() { |
| 120 | return Err(Error::InitializeEmulator(anyhow!( |
| 121 | "TPM not in established state" |
| 122 | ))); |
| 123 | } |
| 124 | |
| 125 | Ok(emulator) |
| 126 | } |
| 127 | |
| 128 | /// Create socketpair, assign one socket/FD as data_fd to Control Socket |
| 129 | /// The other socket/FD will be assigned to msg_fd, which will be sent to swtpm |
nothing calls this directly
no test coverage detected