@@ -169,7 +169,7 @@ pub fn generate_negotiate_algorithms_request<'a>(
169169 req_buf : & mut MessageBuf < ' a > ,
170170 ext_asym : Option < & ' a [ ExtendedAlgo ] > ,
171171 ext_hash : Option < & ' a [ ExtendedAlgo ] > ,
172- req_alg_struct : AlgStructure ,
172+ req_alg_struct : Option < AlgStructure > ,
173173 alg_external : Option < & ' a [ ExtendedAlgo ] > , // req_alg_struct.AlgCount.ExtAlgCount many
174174) -> CommandResult < ( ) > {
175175 let local_algorithms = & ctx. local_algorithms . device_algorithms ;
@@ -184,9 +184,12 @@ pub fn generate_negotiate_algorithms_request<'a>(
184184 None => 0 ,
185185 } ;
186186
187+ let num_alg_struct_tables = req_alg_struct. is_some ( ) as u8 ;
188+ let alg_ext_count = req_alg_struct. map_or ( 0 , |s| s. ext_alg_count ( ) ) ;
189+
187190 // Generate base structure **without** the variable length structures
188191 let negotiate_algorithms_req = NegotiateAlgorithmsReq :: new (
189- req_alg_struct . ext_alg_count ( ) ,
192+ num_alg_struct_tables ,
190193 0 , // param2
191194 local_algorithms. measurement_spec ,
192195 local_algorithms. other_param_support ,
@@ -195,6 +198,7 @@ pub fn generate_negotiate_algorithms_request<'a>(
195198 ext_asym_count,
196199 ext_hash_count,
197200 local_algorithms. mel_specification ,
201+ alg_ext_count,
198202 )
199203 . map_err ( |_| ( false , CommandError :: UnsupportedRequest ) ) ?;
200204
@@ -253,27 +257,23 @@ pub fn generate_negotiate_algorithms_request<'a>(
253257 }
254258 }
255259
256- // 3.2
257- if req_alg_struct. fixed_alg_count ( ) != 0 && !req_alg_struct. is_multiple ( ) {
258- return Err ( ( false , CommandError :: UnsupportedRequest ) ) ;
259- }
260+ // 3.3 + 3.4: encode AlgStructure and its extended algorithms if present
261+ if let Some ( alg_struct) = req_alg_struct {
262+ if alg_struct. fixed_alg_count ( ) != 0 && !alg_struct. is_multiple ( ) {
263+ return Err ( ( false , CommandError :: UnsupportedRequest ) ) ;
264+ }
260265
261- // If this is 1, we have an additional extended algorithm structure to add.
262- if negotiate_algorithms_req. num_alg_struct_tables > 0 {
263- // 3.3
264- req_alg_struct
266+ alg_struct
265267 . encode ( req_buf)
266268 . map_err ( |e| ( false , CommandError :: Codec ( e) ) ) ?;
267269
268- // 3.4
269- if let Some ( extended_algos) = alg_external {
270+ // If ext_alg_count > 0, we must have the extended algorithm structures.
271+ if alg_struct. ext_alg_count ( ) > 0 {
272+ let extended_algos = alg_external. ok_or ( ( false , CommandError :: UnsupportedRequest ) ) ?;
270273 for ext in extended_algos {
271274 ext. encode ( req_buf)
272275 . map_err ( |e| ( false , CommandError :: Codec ( e) ) ) ?;
273276 }
274- } else {
275- // If ext_alg_count > 0, we must have the extended algorithm structure.
276- return Err ( ( false , CommandError :: UnsupportedRequest ) ) ;
277277 }
278278 }
279279
0 commit comments