@@ -10,8 +10,6 @@ use serde::{Deserialize, Serialize};
1010pub struct ClientHelloData {
1111 /// Client's LP x25519 public key (32 bytes)
1212 pub client_lp_public_key : [ u8 ; 32 ] ,
13- /// Protocol version for future compatibility
14- pub protocol_version : u8 ,
1513 /// Salt for PSK derivation (32 bytes: 8-byte timestamp + 24-byte nonce)
1614 pub salt : [ u8 ; 32 ] ,
1715}
@@ -24,7 +22,7 @@ impl ClientHelloData {
2422 /// # Arguments
2523 /// * `client_lp_public_key` - Client's x25519 public key
2624 /// * `protocol_version` - Protocol version number
27- pub fn new_with_fresh_salt ( client_lp_public_key : [ u8 ; 32 ] , protocol_version : u8 ) -> Self {
25+ pub fn new_with_fresh_salt ( client_lp_public_key : [ u8 ; 32 ] ) -> Self {
2826 use std:: time:: { SystemTime , UNIX_EPOCH } ;
2927
3028 // Generate salt: timestamp + nonce
@@ -43,7 +41,6 @@ impl ClientHelloData {
4341
4442 Self {
4543 client_lp_public_key,
46- protocol_version,
4744 salt,
4845 }
4946 }
@@ -89,11 +86,17 @@ impl MessageType {
8986 }
9087}
9188
89+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
90+ pub struct HandshakeData ( pub Vec < u8 > ) ;
91+
92+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
93+ pub struct EncryptedDataPayload ( pub Vec < u8 > ) ;
94+
9295#[ derive( Debug , Clone ) ]
9396pub enum LpMessage {
9497 Busy ,
95- Handshake ( Vec < u8 > ) ,
96- EncryptedData ( Vec < u8 > ) ,
98+ Handshake ( HandshakeData ) ,
99+ EncryptedData ( EncryptedDataPayload ) ,
97100 ClientHello ( ClientHelloData ) ,
98101}
99102
@@ -112,26 +115,26 @@ impl LpMessage {
112115 pub fn payload ( & self ) -> & [ u8 ] {
113116 match self {
114117 LpMessage :: Busy => & [ ] ,
115- LpMessage :: Handshake ( payload) => payload,
116- LpMessage :: EncryptedData ( payload) => payload,
117- LpMessage :: ClientHello ( _) => & [ ] , // Structured data, serialized in encode_content
118+ LpMessage :: Handshake ( payload) => payload. 0 . as_slice ( ) ,
119+ LpMessage :: EncryptedData ( payload) => payload. 0 . as_slice ( ) ,
120+ LpMessage :: ClientHello ( _) => unimplemented ! ( ) , // Structured data, serialized in encode_content
118121 }
119122 }
120123
121124 pub fn is_empty ( & self ) -> bool {
122125 match self {
123126 LpMessage :: Busy => true ,
124- LpMessage :: Handshake ( payload) => payload. is_empty ( ) ,
125- LpMessage :: EncryptedData ( payload) => payload. is_empty ( ) ,
127+ LpMessage :: Handshake ( payload) => payload. 0 . is_empty ( ) ,
128+ LpMessage :: EncryptedData ( payload) => payload. 0 . is_empty ( ) ,
126129 LpMessage :: ClientHello ( _) => false , // Always has data
127130 }
128131 }
129132
130133 pub fn len ( & self ) -> usize {
131134 match self {
132135 LpMessage :: Busy => 0 ,
133- LpMessage :: Handshake ( payload) => payload. len ( ) ,
134- LpMessage :: EncryptedData ( payload) => payload. len ( ) ,
136+ LpMessage :: Handshake ( payload) => payload. 0 . len ( ) ,
137+ LpMessage :: EncryptedData ( payload) => payload. 0 . len ( ) ,
135138 LpMessage :: ClientHello ( _) => 65 , // 32 bytes key + 1 byte version + 32 bytes salt
136139 }
137140 }
@@ -149,10 +152,10 @@ impl LpMessage {
149152 match self {
150153 LpMessage :: Busy => { /* No content */ }
151154 LpMessage :: Handshake ( payload) => {
152- dst. put_slice ( payload) ;
155+ dst. put_slice ( & payload. 0 ) ;
153156 }
154157 LpMessage :: EncryptedData ( payload) => {
155- dst. put_slice ( payload) ;
158+ dst. put_slice ( & payload. 0 ) ;
156159 }
157160 LpMessage :: ClientHello ( data) => {
158161 // Serialize ClientHelloData using bincode
@@ -172,10 +175,11 @@ mod tests {
172175
173176 #[ test]
174177 fn encoding ( ) {
175- let message = LpMessage :: EncryptedData ( vec ! [ 11u8 ; 124 ] ) ;
178+ let message = LpMessage :: EncryptedData ( EncryptedDataPayload ( vec ! [ 11u8 ; 124 ] ) ) ;
176179
177180 let resp_header = LpHeader {
178181 protocol_version : 1 ,
182+ reserved : 0 ,
179183 session_id : 0 ,
180184 counter : 0 ,
181185 } ;
@@ -195,7 +199,7 @@ mod tests {
195199 // Verify correct data in message
196200 match & packet. message {
197201 LpMessage :: EncryptedData ( data) => {
198- assert_eq ! ( * data, vec![ 11u8 ; 124 ] ) ;
202+ assert_eq ! ( * data, EncryptedDataPayload ( vec![ 11u8 ; 124 ] ) ) ;
199203 }
200204 _ => panic ! ( "Wrong message type" ) ,
201205 }
@@ -204,8 +208,8 @@ mod tests {
204208 #[ test]
205209 fn test_client_hello_salt_generation ( ) {
206210 let client_key = [ 1u8 ; 32 ] ;
207- let hello1 = ClientHelloData :: new_with_fresh_salt ( client_key, 1 ) ;
208- let hello2 = ClientHelloData :: new_with_fresh_salt ( client_key, 1 ) ;
211+ let hello1 = ClientHelloData :: new_with_fresh_salt ( client_key) ;
212+ let hello2 = ClientHelloData :: new_with_fresh_salt ( client_key) ;
209213
210214 // Different salts should be generated
211215 assert_ne ! ( hello1. salt, hello2. salt) ;
@@ -219,7 +223,7 @@ mod tests {
219223 #[ test]
220224 fn test_client_hello_timestamp_extraction ( ) {
221225 let client_key = [ 2u8 ; 32 ] ;
222- let hello = ClientHelloData :: new_with_fresh_salt ( client_key, 1 ) ;
226+ let hello = ClientHelloData :: new_with_fresh_salt ( client_key) ;
223227
224228 let timestamp = hello. extract_timestamp ( ) ;
225229 let now = std:: time:: SystemTime :: now ( )
@@ -234,7 +238,7 @@ mod tests {
234238 #[ test]
235239 fn test_client_hello_salt_format ( ) {
236240 let client_key = [ 3u8 ; 32 ] ;
237- let hello = ClientHelloData :: new_with_fresh_salt ( client_key, 1 ) ;
241+ let hello = ClientHelloData :: new_with_fresh_salt ( client_key) ;
238242
239243 // First 8 bytes should be non-zero timestamp
240244 let timestamp_bytes = & hello. salt [ ..8 ] ;
0 commit comments