@@ -275,18 +275,12 @@ impl V1Context {
275275 /// Call this method with response from receiver to continue BIP78 flow. If the response is
276276 /// valid you will get appropriate PSBT that you should sign and broadcast.
277277 #[ inline]
278- pub fn process_response (
279- self ,
280- response : & mut impl std:: io:: Read ,
281- ) -> Result < Psbt , ResponseError > {
282- let mut buf_reader = BufReader :: with_capacity ( MAX_CONTENT_LENGTH + 1 , response) ;
283- let buffer = buf_reader. fill_buf ( ) . map_err ( InternalValidationError :: Io ) ?;
284-
285- if buffer. len ( ) > MAX_CONTENT_LENGTH {
278+ pub fn process_response ( self , response : & [ u8 ] ) -> Result < Psbt , ResponseError > {
279+ if response. len ( ) > MAX_CONTENT_LENGTH {
286280 return Err ( ResponseError :: from ( InternalValidationError :: ContentTooLarge ) ) ;
287281 }
288282
289- let res_str = std:: str:: from_utf8 ( buffer ) . map_err ( |_| InternalValidationError :: Parse ) ?;
283+ let res_str = std:: str:: from_utf8 ( response ) . map_err ( |_| InternalValidationError :: Parse ) ?;
290284 let proposal = Psbt :: from_str ( res_str) . map_err ( |_| ResponseError :: parse ( res_str) ) ?;
291285 self . psbt_context . process_proposal ( proposal) . map_err ( Into :: into)
292286 }
@@ -334,7 +328,7 @@ mod test {
334328 "message" : "This version of payjoin is not supported."
335329 } )
336330 . to_string ( ) ;
337- match ctx. process_response ( & mut known_json_error. as_bytes ( ) ) {
331+ match ctx. process_response ( known_json_error. as_bytes ( ) ) {
338332 Err ( ResponseError :: WellKnown ( WellKnownError {
339333 code : ErrorCode :: VersionUnsupported ,
340334 ..
@@ -348,27 +342,23 @@ mod test {
348342 "message" : "This version of payjoin is not supported."
349343 } )
350344 . to_string ( ) ;
351- match ctx. process_response ( & mut invalid_json_error. as_bytes ( ) ) {
345+ match ctx. process_response ( invalid_json_error. as_bytes ( ) ) {
352346 Err ( ResponseError :: Validation ( _) ) => ( ) ,
353347 _ => panic ! ( "Expected unrecognized JSON error" ) ,
354348 }
355349 }
356350
357351 #[ test]
358352 fn process_response_valid ( ) {
359- let mut cursor = std:: io:: Cursor :: new ( PAYJOIN_PROPOSAL . as_bytes ( ) ) ;
360-
361353 let ctx = create_v1_context ( ) ;
362- let response = ctx. process_response ( & mut cursor ) ;
354+ let response = ctx. process_response ( PAYJOIN_PROPOSAL . as_bytes ( ) ) ;
363355 assert ! ( response. is_ok( ) )
364356 }
365357
366358 #[ test]
367359 fn process_response_invalid_psbt ( ) {
368- let mut cursor = std:: io:: Cursor :: new ( INVALID_PSBT . as_bytes ( ) ) ;
369-
370360 let ctx = create_v1_context ( ) ;
371- let response = ctx. process_response ( & mut cursor ) ;
361+ let response = ctx. process_response ( INVALID_PSBT . as_bytes ( ) ) ;
372362 match response {
373363 Ok ( _) => panic ! ( "Invalid PSBT should have caused an error" ) ,
374364 Err ( error) => match error {
@@ -386,11 +376,10 @@ mod test {
386376 #[ test]
387377 fn process_response_invalid_utf8 ( ) {
388378 // In UTF-8, 0xF0 represents the start of a 4-byte sequence, so 0xF0 by itself is invalid
389- let invalid_utf8 = [ 0xF0 ] ;
390- let mut cursor = std:: io:: Cursor :: new ( invalid_utf8) ;
379+ let invalid_utf8 = & [ 0xF0 ] ;
391380
392381 let ctx = create_v1_context ( ) ;
393- let response = ctx. process_response ( & mut cursor ) ;
382+ let response = ctx. process_response ( invalid_utf8 ) ;
394383 match response {
395384 Ok ( _) => panic ! ( "Invalid UTF-8 should have caused an error" ) ,
396385 Err ( error) => match error {
0 commit comments