From: Simon Glass <simon.glass@canonical.com> Some fields may have sensitive information. Allow it to be obscured during entry, in case someone is watching the display nearby. Signed-off-by: Simon Glass <simon.glass@canonical.com> --- boot/scene.c | 19 +++++++++++++++++-- include/expo.h | 2 ++ test/boot/cedit.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/boot/scene.c b/boot/scene.c index c2d106738f5..77926bda5fa 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -573,6 +573,19 @@ static void scene_render_background(struct scene_obj *obj, bool box_only, } } +static void draw_string(struct udevice *cons, const char *str, int len, + bool password) +{ + if (password) { + int i; + + for (i = 0; i < len; i++) + vidconsole_put_char(cons, '*'); + } else { + vidconsole_put_stringn(cons, str, len); + } +} + static int scene_txt_render(struct expo *exp, struct udevice *dev, struct udevice *cons, struct scene_obj *obj, struct scene_txt_generic *gen, int x, int y, @@ -630,7 +643,8 @@ static int scene_txt_render(struct expo *exp, struct udevice *dev, if (!mline) { vidconsole_set_cursor_pos(cons, x, y); - vidconsole_put_string(cons, str); + draw_string(cons, str, strlen(str), + obj->flags & SCENEOF_PASSWORD); } alist_for_each(mline, &gen->lines) { @@ -648,7 +662,8 @@ static int scene_txt_render(struct expo *exp, struct udevice *dev, if (y > bbox.y1) break; /* clip this line and any following */ vidconsole_set_cursor_pos(cons, x, y); - vidconsole_put_stringn(cons, str + mline->start, mline->len); + draw_string(cons, str + mline->start, mline->len, + obj->flags & SCENEOF_PASSWORD); } if (obj->flags & SCENEOF_POINT) vidconsole_pop_colour(cons, &old); diff --git a/include/expo.h b/include/expo.h index 2f32ff0aa72..e6093769421 100644 --- a/include/expo.h +++ b/include/expo.h @@ -320,6 +320,7 @@ enum scene_obj_align { * @SCENEOF_SYNC_BBOX: object's bounding box has changed * @SCENEOF_MANUAL: manually arrange the items associated with this object * @SCENEOF_DIRTY: object has been modified and needs to be redrawn + * @SCENEOF_PASSWORD: textline input should show stars instead of characters * @SCENEOF_LAST: used just as a check for the size of the flags mask */ enum scene_obj_flags_t { @@ -333,6 +334,7 @@ enum scene_obj_flags_t { SCENEOF_SYNC_BBOX = BIT(7), SCENEOF_MANUAL = BIT(8), SCENEOF_DIRTY = BIT(9), + SCENEOF_PASSWORD = BIT(10), SCENEOF_LAST, /* check for size of flags below */ }; diff --git a/test/boot/cedit.c b/test/boot/cedit.c index bccc93f8926..041da445459 100644 --- a/test/boot/cedit.c +++ b/test/boot/cedit.c @@ -376,6 +376,7 @@ static int cedit_render_lineedit(struct unit_test_state *uts) extern struct expo *cur_exp; struct expo_action evt; struct expo_action act; + struct scene_obj *edit; struct udevice *dev, *con; struct stdio_dev *sdev; struct scene *scn; @@ -405,6 +406,16 @@ static int cedit_render_lineedit(struct unit_test_state *uts) ut_asserteq(5344, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); + edit = scene_obj_find(scn, ID_MACHINE_NAME_EDIT, SCENEOBJT_TEXT); + ut_assert(edit); + + /* try the password flag */ + edit->flags |= SCENEOF_PASSWORD; + ut_assertok(expo_render(exp)); + ut_asserteq(5135, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + edit->flags &= ~SCENEOF_PASSWORD; + /* move to the line-edit field */ act.type = EXPOACT_POINT_OBJ; act.select.id = ID_MACHINE_NAME; -- 2.43.0