-
Notifications
You must be signed in to change notification settings - Fork 56
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
Use cpu_endian to check local endianness #637
Conversation
Resolves: keylime#283 Signed-off-by: Sergio Arroutbi <[email protected]>
Codecov Report
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I have tried making endianness handling in a templatized way. Something like: +pub fn local_endianness<T, const SIZE: usize>(t: T) -> [u8; SIZE] {
+ match cpu_endian::working() {
+ cpu_endian::Endian::Little => t.to_le_bytes(),
+ cpu_endian::Endian::Big => t.to_be_bytes(),
+ _ => t.to_le_bytes(),
+ }
+}
+ However, this seems to be not allowed: 6 | pub fn local_endianness<T, const SIZE: usize>(t: T) -> [u8; SIZE] {
| - method `to_le_bytes` not found for this type parameter
7 | match cpu_endian::working() {
8 | cpu_endian::Endian::Little => t.to_le_bytes(),
| ^^^^^^^^^^^ method not found in `T`
error[E0599]: no method named `to_be_bytes` found for type parameter `T` in the current scope
--> keylime/src/endian.rs:9:38
|
6 | pub fn local_endianness<T, const SIZE: usize>(t: T) -> [u8; SIZE] {
| - method `to_be_bytes` not found for this type parameter
...
9 | cpu_endian::Endian::Big => t.to_be_bytes(),
| ^^^^^^^^^^^ method not found in `T`
error[E0599]: no method named `to_le_bytes` found for type parameter `T` in the current scope
--> keylime/src/endian.rs:10:16
|
6 | pub fn local_endianness<T, const SIZE: usize>(t: T) -> [u8; SIZE] {
| - method `to_le_bytes` not found for this type parameter
...
10 | _ => t.to_le_bytes(),
| ^^^^^^^^^^^ method not found in `T` If anybody can help with this, I am grateful. Otherwise, I will keep the PR as it is right now |
You need to add a bound to "T". IIUC "T" will always be "u32", "u16" or "u8". I that case maybe you can use something like this: https://users.rust-lang.org/t/generic-function-for-from-be-bytes/59629/5 |
Signed-off-by: Sergio Arroutbi <[email protected]>
4f46f43
to
225c3f9
Compare
@sarroutbi Have you tested the interoperability of this between a big endian and a little endian machine? I'm afraid this can break interoperability. The reason of making the endianess fixed is for all machines to encode data in the same way. Another downside is the addition of a new dependency. It is not available in Fedora for example, which will cause problems on packaging. |
You are right. I did not figure out that scenario. If codification is hard coded intentionally, I guess #283 should be closed with no resolution. I will close this PR. Sorry for confusion |
@sarroutbi Sorry, I didn't mean you should close this, but to test if this would actually work in an interoperability scenario. We can test it and reopen this if it works. But then we would have to work to introduce the new dependency in Fedora. If it doesn't work, then we should do what you proposed and close #283 with the reasoning. |
No problem. I will reopen it and once tested, will let you know. |
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 think @ansasaki is right and my review was wrong. Now the data sent from a x86-64 and aarch64 will have different de-serialization order
I will close this PR, as it has been confirmed that current development status is intentionally done. My suggestion is closing #283, as it can be confusing |
Resolves: #283