| 65 | } |
| 66 | |
| 67 | pub fn connect(&mut self, socket_path: impl AsRef<Path>) -> Result<()> { |
| 68 | let socket_path = socket_path.as_ref(); |
| 69 | self.state = SocketDevState::Connecting; |
| 70 | |
| 71 | let socket_path_s = socket_path.to_str().unwrap(); |
| 72 | let s = UnixStream::connect(socket_path).map_err(|e| { |
| 73 | Error::ConnectToSocket(anyhow!("Failed to connect to tpm Socket. Error: {e:?}")) |
| 74 | })?; |
| 75 | self.control_fd = s.as_raw_fd(); |
| 76 | self.stream = Some(s); |
| 77 | self.state = SocketDevState::Connected; |
| 78 | debug!("Connected to tpm socket path : {socket_path_s:?}"); |
| 79 | Ok(()) |
| 80 | } |
| 81 | |
| 82 | pub fn set_datafd(&mut self, fd: RawFd) { |
| 83 | self.data_fd = fd; |