@@ -29,7 +29,9 @@ use url::Url;
2929
3030use super :: error:: BuildSenderError ;
3131use super :: * ;
32- use crate :: hpke:: { decrypt_message_b, encrypt_message_a, HpkeSecretKey } ;
32+ use crate :: hpke:: {
33+ decrypt_message_b, encrypt_message_a, HpkeError , HpkeSecretKey , PADDED_PLAINTEXT_A_LENGTH ,
34+ } ;
3335use crate :: ohttp:: { ohttp_decapsulate, ohttp_encapsulate} ;
3436use crate :: send:: v1;
3537use crate :: uri:: { ShortId , UrlExt } ;
@@ -149,15 +151,22 @@ impl Sender {
149151 }
150152 let rs = self . extract_rs_pubkey ( ) ?;
151153 let url = self . v1 . endpoint . clone ( ) ;
152- let body = serialize_v2_body (
154+ let mut plaintext = serialize_v2_body (
153155 & self . v1 . psbt ,
154156 self . v1 . disable_output_substitution ,
155157 self . v1 . fee_contribution ,
156158 self . v1 . min_fee_rate ,
157159 ) ?;
160+ plaintext. resize ( PADDED_PLAINTEXT_A_LENGTH , 0 ) ;
161+
158162 let hpke_ctx = HpkeContext :: new ( rs, & self . reply_key ) ;
159163 let body = encrypt_message_a (
160- body,
164+ & plaintext. clone ( ) . try_into ( ) . map_err ( |_| {
165+ InternalCreateRequestError :: Hpke ( HpkeError :: PayloadTooLarge {
166+ actual : plaintext. len ( ) ,
167+ max : PADDED_PLAINTEXT_A_LENGTH ,
168+ } )
169+ } ) ?,
161170 & hpke_ctx. reply_pair . public_key ( ) . clone ( ) ,
162171 & hpke_ctx. receiver . clone ( ) ,
163172 )
@@ -265,7 +274,7 @@ impl V2GetContext {
265274 . join ( & subdir. to_string ( ) )
266275 . map_err ( |e| InternalCreateRequestError :: Url ( e. into ( ) ) ) ?;
267276 let body = encrypt_message_a (
268- Vec :: new ( ) ,
277+ & [ 0 ; PADDED_PLAINTEXT_A_LENGTH ] ,
269278 & self . hpke_ctx . reply_pair . public_key ( ) . clone ( ) ,
270279 & self . hpke_ctx . receiver . clone ( ) ,
271280 )
0 commit comments