-
Notifications
You must be signed in to change notification settings - Fork 80
fix: use correct hex capacity for word and digest hex encoding #1675
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
base: next
Are you sure you want to change the base?
Changes from 2 commits
a976a54
d38975d
aa76a92
34371db
bfc13ac
90ce09b
f43407d
59c9207
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| use alloc::{string::String, vec::Vec}; | ||
| use core::fmt::{self, Display, Formatter}; | ||
| use alloc::string::String; | ||
| use core::fmt::{self, Display, Formatter, Write}; | ||
|
|
||
| use hex::ToHex; | ||
| use miden_objects::{Felt, StarkField, Word, note::NoteId}; | ||
|
|
@@ -9,7 +9,7 @@ use crate::rpc::{errors::RpcConversionError, generated::word}; | |
| // CONSTANTS | ||
| // ================================================================================================ | ||
|
|
||
| pub const WORD_DATA_SIZE: usize = 32; | ||
| pub const WORD_DATA_SIZE: usize = Word::SERIALIZED_SIZE * 2; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any correlation between |
||
|
|
||
| // FORMATTING | ||
| // ================================================================================================ | ||
|
|
@@ -32,21 +32,31 @@ impl ToHex for &word::Word { | |
|
|
||
| impl ToHex for word::Word { | ||
| fn encode_hex<T: FromIterator<char>>(&self) -> T { | ||
| let mut data: Vec<char> = Vec::with_capacity(WORD_DATA_SIZE); | ||
| data.extend(format!("{:016x}", self.w0).chars()); | ||
| data.extend(format!("{:016x}", self.w1).chars()); | ||
| data.extend(format!("{:016x}", self.w2).chars()); | ||
| data.extend(format!("{:016x}", self.w3).chars()); | ||
| data.into_iter().collect() | ||
| let mut data = String::with_capacity(WORD_DATA_SIZE); | ||
| write!( | ||
| &mut data, | ||
| "{:016x}{:016x}{:016x}{:016x}", | ||
| self.w0, | ||
| self.w1, | ||
| self.w2, | ||
| self.w3 | ||
| ) | ||
| .unwrap(); | ||
|
||
| data.chars().collect() | ||
| } | ||
|
|
||
| fn encode_hex_upper<T: FromIterator<char>>(&self) -> T { | ||
| let mut data: Vec<char> = Vec::with_capacity(WORD_DATA_SIZE); | ||
| data.extend(format!("{:016X}", self.w0).chars()); | ||
| data.extend(format!("{:016X}", self.w1).chars()); | ||
| data.extend(format!("{:016X}", self.w2).chars()); | ||
| data.extend(format!("{:016X}", self.w3).chars()); | ||
| data.into_iter().collect() | ||
| let mut data = String::with_capacity(WORD_DATA_SIZE); | ||
| write!( | ||
| &mut data, | ||
| "{:016X}{:016X}{:016X}{:016X}", | ||
| self.w0, | ||
| self.w1, | ||
| self.w2, | ||
| self.w3 | ||
| ) | ||
| .unwrap(); | ||
| data.chars().collect() | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Can we try and avoid this unwrap here? I was not needed before
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.
Yes, did it!