File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,15 +42,28 @@ pub fn sha256(message: String) -> String {
4242 message_vec. push ( 0x80 as u8 ) ;
4343 while ( message_vec. len ( ) * 8 + 64 ) % 512 != 0 { message_vec. push ( 0x00 as u8 ) ; }
4444 for b in message_length. to_ne_bytes ( ) { message_vec. push ( b) ; }
45- assert_eq ! ( ( message_vec. len( ) * 8 ) % 512 , 0 , "Message was not properly padded" ) ;
45+ assert_eq ! ( ( message_vec. len( ) * 8 ) % 512 , 0 , "Message was not properly padded." ) ;
46+
4647
4748 /*
4849 Parsing
4950 =======
5051 -- Parse the padded message into 512-Bit Chunks.
51- |> TODO: The code for this section.
5252 */
53- let mut chunks: Vec < [ u8 ; 64 ] > = Vec :: new ( ) ;
53+ let mut chunks: Vec < Vec < u8 > > = Vec :: new ( ) ;
54+ while message_vec. len ( ) != 0 {
55+ let mut new_chunk = Vec :: with_capacity ( 64 ) ;
56+
57+ for _ in 0 .. 64 {
58+ new_chunk. push ( message_vec. pop ( ) . unwrap ( ) ) ;
59+ }
60+
61+ chunks. push ( new_chunk) ;
62+ }
63+
64+ assert_ne ! ( chunks. len( ) , 0 , "Could not split message into any chunks." ) ;
65+ for c in chunks { assert_eq ! ( c. len( ) , 64 , "Could not parse message into chunks properly." ) ; }
66+
5467
5568 return String :: new ( ) ;
5669}
You can’t perform that action at this time.
0 commit comments