MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / read_password

Function read_password

framework_lib/src/smart_battery.rs:671–699  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

669/// Reads a line from stdin without echoing (for sensitive input like keys)
670#[cfg(unix)]
671fn read_password() -> io::Result<String> {
672 use nix::sys::termios::{self, LocalFlags, SetArg};
673 use std::io::BufRead;
674 use std::os::fd::AsFd;
675
676 let stdin = io::stdin();
677 let fd = stdin.as_fd();
678
679 // Save original terminal settings
680 let original = termios::tcgetattr(fd)?;
681
682 // Disable echo
683 let mut noecho = original.clone();
684 noecho.local_flags.remove(LocalFlags::ECHO);
685 termios::tcsetattr(fd, SetArg::TCSANOW, &noecho)?;
686
687 // Read the line
688 let mut input = String::new();
689 let result = stdin.lock().read_line(&mut input);
690
691 // Restore original settings
692 termios::tcsetattr(fd, SetArg::TCSANOW, &original)?;
693
694 // Print newline since echo was disabled
695 println!();
696
697 result?;
698 Ok(input)
699}
700
701/// Reads a line from stdin without echoing (for sensitive input like keys)
702#[cfg(windows)]

Callers 3

dump_dataMethod · 0.85
dump_to_fileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected