@@ -15,6 +15,8 @@ use futures::{StreamExt, SinkExt};
1515use futures:: channel:: mpsc;
1616use futures:: lock:: Mutex ;
1717use rand:: { thread_rng, Rng } ;
18+ use sha2:: { Digest , Sha256 } ;
19+ use sha2:: digest:: generic_array:: typenum:: marker_traits:: Unsigned ;
1820
1921use tox_crypto:: * ;
2022use crate :: dht:: ip_port:: IsGlobal ;
@@ -169,7 +171,7 @@ struct OnionNode {
169171 /// Path used to send packets to this node.
170172 path_id : OnionPathId ,
171173 /// Ping id that should be used to announce to this node.
172- ping_id : Option < sha256 :: Digest > ,
174+ ping_id : Option < [ u8 ; < Sha256 as Digest > :: OutputSize :: USIZE ] > ,
173175 /// Data `PublicKey` that should be used to send data packets to our friend
174176 /// through this node.
175177 data_pk : Option < PublicKey > ,
@@ -268,7 +270,7 @@ struct AnnouncePacketData<'a> {
268270impl < ' a > AnnouncePacketData < ' a > {
269271 /// Create `InnerOnionAnnounceRequest`. The request is a search request if
270272 /// pind_id is 0 and an announce request otherwise.
271- fn request ( & self , node_pk : & PublicKey , ping_id : Option < sha256 :: Digest > , request_id : u64 ) -> InnerOnionAnnounceRequest {
273+ fn request ( & self , node_pk : & PublicKey , ping_id : Option < [ u8 ; < Sha256 as Digest > :: OutputSize :: USIZE ] > , request_id : u64 ) -> InnerOnionAnnounceRequest {
272274 let payload = OnionAnnounceRequestPayload {
273275 ping_id : ping_id. unwrap_or ( INITIAL_PING_ID ) ,
274276 search_pk : self . search_pk ,
@@ -286,7 +288,7 @@ impl<'a> AnnouncePacketData<'a> {
286288 self . request ( node_pk, None , request_id)
287289 }
288290 /// Create `InnerOnionAnnounceRequest` for an announce request.
289- pub fn announce_request ( & self , node_pk : & PublicKey , ping_id : sha256 :: Digest , request_id : u64 ) -> InnerOnionAnnounceRequest {
291+ pub fn announce_request ( & self , node_pk : & PublicKey , ping_id : [ u8 ; < Sha256 as Digest > :: OutputSize :: USIZE ] , request_id : u64 ) -> InnerOnionAnnounceRequest {
290292 self . request ( node_pk, Some ( ping_id) , request_id)
291293 }
292294}
@@ -469,7 +471,7 @@ impl OnionClient {
469471 let ( ping_id, data_pk) = if payload. announce_status == AnnounceStatus :: Found {
470472 ( None , Some ( PublicKey ( payload. ping_id_or_pk ) ) )
471473 } else {
472- ( Some ( sha256 :: Digest ( payload. ping_id_or_pk ) ) , None )
474+ ( Some ( payload. ping_id_or_pk ) , None )
473475 } ;
474476
475477 let now = clock_now ( ) ;
@@ -1021,7 +1023,7 @@ mod tests {
10211023 keys : [ gen_keypair ( ) . 0 , gen_keypair ( ) . 0 , gen_keypair ( ) . 0 ] ,
10221024 path_type : OnionPathType :: Udp ,
10231025 } ;
1024- let ping_id = sha256 :: hash ( & [ 1 , 2 , 3 ] ) ;
1026+ let ping_id = [ 42 ; 32 ] ;
10251027 let data_pk = gen_keypair ( ) . 0 ;
10261028 let new_now = now + Duration :: from_secs ( 1 ) ;
10271029 let other_onion_node = OnionNode {
@@ -1228,7 +1230,7 @@ mod tests {
12281230 // The sender should be added to close nodes
12291231 let onion_node = state. announce_list . get_node ( & real_pk, & sender_pk) . unwrap ( ) ;
12301232 assert_eq ! ( onion_node. path_id, path. id( ) ) ;
1231- assert_eq ! ( onion_node. ping_id, Some ( sha256 :: Digest ( ping_id) ) ) ;
1233+ assert_eq ! ( onion_node. ping_id, Some ( ping_id) ) ;
12321234 assert_eq ! ( onion_node. data_pk, None ) ;
12331235 assert_eq ! ( onion_node. announce_status, AnnounceStatus :: Announced ) ;
12341236
@@ -1920,7 +1922,7 @@ mod tests {
19201922 state. paths_pool . path_nodes . put ( node) ;
19211923 }
19221924
1923- let ping_id = sha256 :: hash ( & [ 1 , 2 , 3 ] ) ;
1925+ let ping_id = [ 42 ; 32 ] ;
19241926 let now = Instant :: now ( ) ;
19251927
19261928 let mut nodes_key_by_addr = HashMap :: new ( ) ;
@@ -2064,7 +2066,7 @@ mod tests {
20642066 saddr,
20652067 path_id : path. id ( ) ,
20662068 // regardless of this ping_id search requests should contain 0
2067- ping_id : Some ( sha256 :: hash ( & [ 1 , 2 , 3 ] ) ) ,
2069+ ping_id : Some ( [ 42 ; 32 ] ) ,
20682070 data_pk : None ,
20692071 unsuccessful_pings : 0 ,
20702072 added_time : now,
0 commit comments