History

remove rustyline in favor of `git-prompt` (#450)

The latter needs implementation, but the API seems nice.

Sebastian Thiel committed 4 years ago

Commit b3e5e591 parent 41281ad8 files · +25 −199Browse files

Showing the changes to git-credentials/src/program (3 of 8 files). Show all

Unified · Split

3 files
  1. git-credentials/src/program/cascade.rs +3 −2
  2. git-credentials/src/program/mod.rs +0 −3
  3. git-credentials/src/program/prompt.rs +0 −52
git-credentials/src/program/cascade.rs+3−2
@@ -8,6 +8,7 @@ impl Default for Cascade { · 7 unmodified lines
88 Cascade {
99 programs: Vec::new(),
1010 stderr: true,
11+ #[cfg(feature = "prompt")]
1112 prompt: true,
1213 }
1314 }
@@ -127,10 +128,10 @@ impl Cascade { · 113 unmodified lines
127128 if self.prompt {
128129 if let Some(ctx) = action.context_mut() {
129130 if let username @ None = &mut ctx.username {
130− *username = crate::program::prompt::openly("Username: ")?.into();
131+ *username = git_prompt::openly("Username: ")?.into();
131132 }
132133 if let password @ None = &mut ctx.password {
133− *password = crate::program::prompt::securely("Password: ")?.into();
134+ *password = git_prompt::securely("Password: ")?.into();
134135 }
135136 }
136137 }
git-credentials/src/program/mod.rs+0−3
@@ -16,9 +16,6 @@ pub struct Cascade { · 15 unmodified lines
1616 }
1717
1818 mod cascade;
19−#[cfg(feature = "prompt")]
20−///
21−pub mod prompt;
2219
2320 /// The kind of helper program to use.
2421 #[derive(Debug, Clone, Eq, PartialEq)]
git-credentials/src/program/prompt.rs+0−52
@@ -1,52 +0,0 @@
1−use std::borrow::Cow;
2−
3−use rustyline::config::Configurer;
4−use rustyline::highlight::Highlighter;
5−use rustyline::{ColorMode, Editor, Result};
6−use rustyline_derive::{Completer, Helper, Hinter, Validator};
7−
8−#[derive(Completer, Helper, Hinter, Validator)]
9−struct Mask {
10− apply: bool,
11−}
12−
13−impl Highlighter for Mask {
14− fn highlight<'l>(&self, line: &'l str, _pos: usize) -> Cow<'l, str> {
15− use unicode_width::UnicodeWidthStr;
16− if self.apply {
17− Cow::Owned("*".repeat(line.width()))
18− } else {
19− Cow::Borrowed(line)
20− }
21− }
22−
23− fn highlight_char(&self, _line: &str, _pos: usize) -> bool {
24− self.apply
25− }
26−}
27−
28−/// Ask for information typed by the user after showing the prompt`, like `"Username: `.
29−pub fn openly(prompt: &str) -> Result<String> {
30− editor(false)?.readline(prompt)
31−}
32−
33−/// Ask for information _securely_ after showing the `prompt` (like `"password: "`) by not showing what's typed.
34−///
35−/// # Security
36−///
37−/// The current implementation does only mask the typed characters, they could still be read by an attacker.
38−/// To do this correctly, echoing has to be disabled entirely. See [this issue](https://github.com/kkawakam/rustyline/issues/58)
39−/// for progress on this.
40−pub fn securely(prompt: &str) -> Result<String> {
41− let mut ed = editor(true)?;
42− ed.set_color_mode(ColorMode::Forced); // force masking, otherwise disabling color won't trigger the highlighter.
43− ed.set_auto_add_history(false);
44− ed.readline(prompt)
45−}
46−
47−fn editor(masked: bool) -> Result<Editor<Mask>> {
48− let h = Mask { apply: masked };
49− let mut ed = Editor::new()?;
50− ed.set_helper(Some(h));
51− Ok(ed)
52−}