Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
termion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
akitsu-sanae
termion
Commits
e145bf65
Commit
e145bf65
authored
9 years ago
by
Ticki
Browse files
Options
Downloads
Plain Diff
Merge pull request #3 from skade/utf8-password-buffer
Use a byte buffer for the password
parents
f601c49e
c5fd3b11
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/error.rs
+3
-0
3 additions, 0 deletions
src/error.rs
src/extra.rs
+6
-4
6 additions, 4 deletions
src/extra.rs
with
9 additions
and
4 deletions
src/error.rs
+
3
−
0
View file @
e145bf65
...
...
@@ -16,6 +16,8 @@ pub enum TerminalError {
StdinError
,
/// Failed to parse number.
ParseError
,
/// Failed to read unicode encoded data.
UnicodeError
}
impl
TerminalError
{
...
...
@@ -27,6 +29,7 @@ impl TerminalError {
TerminalError
::
StdoutError
=>
"Failed to write to stdout."
,
TerminalError
::
StdinError
=>
"Failed to read from stdin."
,
TerminalError
::
ParseError
=>
"Failed to parse number."
,
TerminalError
::
UnicodeError
=>
"Failed to read unicode encoded data."
,
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/extra.rs
+
6
−
4
View file @
e145bf65
...
...
@@ -13,17 +13,19 @@ pub trait ReadExt {
impl
<
R
:
Read
>
ReadExt
for
R
{
fn
read_passwd
<
W
:
Write
>
(
&
mut
self
,
writer
:
&
mut
W
)
->
Result
<
Option
<
String
>
,
TerminalError
>
{
let
_raw
=
try
!
(
writer
.into_raw_mode
());
let
mut
string
=
String
::
with_capacity
(
30
);
let
mut
passbuf
=
Vec
::
with_capacity
(
30
);
for
c
in
self
.bytes
()
{
match
c
{
Err
(
_
)
=>
return
Err
(
TerminalError
::
StdinError
),
Ok
(
0
)
|
Ok
(
3
)
|
Ok
(
4
)
=>
return
Ok
(
None
),
Ok
(
b'\n'
)
|
Ok
(
b'\r'
)
=>
re
turn
Ok
(
Some
(
string
))
,
Ok
(
c
)
=>
string
.push
(
c
as
char
),
Ok
(
b'\n'
)
|
Ok
(
b'\r'
)
=>
b
re
ak
,
Ok
(
c
)
=>
passbuf
.push
(
c
),
}
}
Ok
(
Some
(
string
))
let
passwd
=
try
!
(
String
::
from_utf8
(
passbuf
)
.map_err
(|
_
|
TerminalError
::
UnicodeError
));
Ok
(
Some
(
passwd
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment