-
-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust UI: improve messages returned to python #2138
Conversation
args: *const Obj, | ||
kwargs: *const Map, | ||
) -> Obj { | ||
extern "C" fn new_confirm_text(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I changed *const Map
to *mut Map
to pass type check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't check it now, but it should match the type the C-side expects.
@@ -18,7 +18,7 @@ use crate::{ | |||
}; | |||
|
|||
pub enum PinKeyboardMsg { | |||
Confirmed, | |||
Confirmed(Vec<u8, MAX_LENGTH>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the pin()
method exists I guess it was supposed to be used to obtain the pin, but haven't figured out how to get a reference to the layout object at the time the result is constructed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly the usecase the ObjComponentMsg
trait (hope I remember the name right) is supposed to address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you omit the TryInto
impl for the msg type, you should be able to impl the above trait and get a ref to the component for the conversion. Then you can pull the PIN out of it and convert into Obj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you omit the TryInto
impl for the msg type, you should be able to impl the above trait and get a ref to the component for the conversion. Then you can pull the PIN out of it and convert into Obj.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I implement the trait like
trezor-firmware/core/embed/rust/src/ui/model_tt/layout.rs
Lines 57 to 65 in 31fc2a4
impl ComponentMsgObj for PinKeyboard { | |
fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> { | |
let result: (Obj, Obj) = match msg { | |
PinKeyboardMsg::Cancelled => (CANCELLED.as_obj(), Obj::const_none()), | |
PinKeyboardMsg::Confirmed => (CONFIRMED.as_obj(), self.pin().try_into()?), | |
}; | |
result.try_into() | |
} | |
} |
then I get error regarding conflicting implementations:
error[E0119]: conflicting implementations of trait `ui::layout::obj::ComponentMsgObj` for type `ui::model_tt::component::keyboard::pin::PinKeyboard`
--> src/ui/model_tt/layout.rs:57:1
|
57 | impl ComponentMsgObj for PinKeyboard
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `ui::model_tt::component::keyboard::pin::PinKeyboard`
|
::: src/ui/layout/obj.rs:37:1
|
37 | / impl<T> ComponentMsgObj for T
38 | | where
39 | | T: Component,
40 | | T::Msg: TryInto<Obj, Error = Error>,
... |
44 | | }
45 | | }
| |_- first implementation here
What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TryInto
implementation is not there anymore, perhaps the compiler is not smart enough to figure out that T::Msg: TryInto<Obj, Error = Error>
is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, we may be hitting rust-lang/rust#20400. I rewrote all the TryInto
conversions to explicit ComponentMsgObj
impls, it's a bit ugly but uses less magic.
@@ -145,7 +145,7 @@ impl Component for PinKeyboard { | |||
|
|||
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> { | |||
if let Some(Clicked) = self.confirm_btn.event(ctx, event) { | |||
return Some(PinKeyboardMsg::Confirmed); | |||
return Some(PinKeyboardMsg::Confirmed(self.digits.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep this, is there a way to zero out the pin being cloned in a way that doesn't get optimized out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, we can get rid of PIN being stored in the message altogether. Re. reliable data zeroing, there are some crates, let's investigate how they work in a nostd env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/zeroize/latest/zeroize/ is such a crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not storing the pin in the message anymore so zeroing isn't needed (yet). But good to know such crate exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you should zero out the source buffer for the PIN though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, though that would require to modify the type of ComponentMsgObj::msg_try_into_obj
to fn msg_try_into_obj(&mut self, msg: Self::Msg) -> Result<Obj, Error>
. I propose to solve this in another PR, wanted to add this as a TODO item to #1922 but github is probably broken and won't let me edit:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
added the TODO
honestly, couldn't we just consume the layout object instead? self
instead of &mut self
(probably not because something something reference in the Python-held object, but still something that seems semantically more correct)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can extend |
6c51190
to
834e584
Compare
I've addressed the comments and extended |
Also rebased to master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM structure wise, leaving the details to @jpochyla
big 👍 on build_mocks
handling
Noticed that
I've added |
2c3647d
to
df9cdc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nitpicks, otherwise very nice
[no changelog] Co-authored-by: Martin Milata <martin@martinmilata.cz>
[no changelog]
e75c848
to
03866bd
Compare
Built on top of #2092. Pyright fails since we no longer generate the
.pyi
files, can we do better than just ignoring these issues? Some other questions inline.Fixes #2118.