@ -36,6 +36,16 @@ pub const RSA_BLOCK_SIZE: usize = 512;
/// Max size to pre-allocate when reading a message buffer.
/// Max size to pre-allocate when reading a message buffer.
pub const MAX_ALLOC_SIZE : usize = 4096 ; // 4kb
pub const MAX_ALLOC_SIZE : usize = 4096 ; // 4kb
/// Max size to allow reading for a message buffer component.
///
/// Not including the message body, see `MAX_BODY_SIZE` for body.
pub const MAX_READ_SIZE : usize = 2048 * 1024 ; // 2MB.
/// Max allowed size of a single message body.
///
/// Set to 0 for unlimited.
pub const MAX_BODY_SIZE : usize = ( 1024 * 1024 ) * 1024 ; // 1GB
/// A message that can send a value into bytes.
/// A message that can send a value into bytes.
#[ derive(Debug, Clone, PartialEq, Eq, Hash) ]
#[ derive(Debug, Clone, PartialEq, Eq, Hash) ]
pub struct Message < V : ? Sized + MessageValue >
pub struct Message < V : ? Sized + MessageValue >
@ -158,7 +168,11 @@ impl<V: ?Sized + MessageValue> Message<V>
{
{
let send_with : & S = send_with . borrow ( ) ;
let send_with : & S = send_with . borrow ( ) ;
let data = serde_cbor ::to_vec ( & self . value ) ? ;
let data = serde_cbor ::to_vec ( & self . value ) ? ;
if MAX_BODY_SIZE > 0 & & data . len ( ) > MAX_BODY_SIZE {
return Err ( eyre ! ( "Encoded body is too large" ) )
. with_section ( | | data . len ( ) . header ( "Body size was" ) )
. with_section ( | | MAX_BODY_SIZE . header ( "Max size is" ) ) ;
}
let sig = if self . sign {
let sig = if self . sign {
Some ( send_with . sign_data ( & data [ .. ] ) . expect ( "Message expected signing, sender did not support it" ) )
Some ( send_with . sign_data ( & data [ .. ] ) . expect ( "Message expected signing, sender did not support it" ) )
} else {
} else {