break everything
This commit is contained in:
@@ -76,7 +76,7 @@ impl Envelope {
|
||||
// Ensure we are at least the length of the envelope
|
||||
// Silent drop here, as we use zero length packets as part of the protocol for hole punching
|
||||
if data.len() < MIN_ENVELOPE_SIZE {
|
||||
return Err(VeilidAPIError::generic("envelope data too small"));
|
||||
apibail_generic!("envelope data too small");
|
||||
}
|
||||
|
||||
// Verify magic number
|
||||
@@ -84,31 +84,28 @@ impl Envelope {
|
||||
.try_into()
|
||||
.map_err(VeilidAPIError::internal)?;
|
||||
if magic != *ENVELOPE_MAGIC {
|
||||
return Err(VeilidAPIError::generic("bad magic number"));
|
||||
apibail_generic!("bad magic number");
|
||||
}
|
||||
|
||||
// Check version
|
||||
let version = data[0x04];
|
||||
if version > MAX_CRYPTO_VERSION || version < MIN_CRYPTO_VERSION {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"unsupported cryptography version",
|
||||
version,
|
||||
));
|
||||
apibail_parse_error!("unsupported cryptography version", version);
|
||||
}
|
||||
|
||||
// Get min version
|
||||
let min_version = data[0x05];
|
||||
if min_version > version {
|
||||
return Err(VeilidAPIError::parse_error("version too low", version));
|
||||
apibail_parse_error!("version too low", version);
|
||||
}
|
||||
|
||||
// Get max version
|
||||
let max_version = data[0x06];
|
||||
if version > max_version {
|
||||
return Err(VeilidAPIError::parse_error("version too high", version));
|
||||
apibail_parse_error!("version too high", version);
|
||||
}
|
||||
if min_version > max_version {
|
||||
return Err(VeilidAPIError::generic("version information invalid"));
|
||||
apibail_generic!("version information invalid");
|
||||
}
|
||||
|
||||
// Get size and ensure it matches the size of the envelope and is less than the maximum message size
|
||||
@@ -118,17 +115,17 @@ impl Envelope {
|
||||
.map_err(VeilidAPIError::internal)?,
|
||||
);
|
||||
if (size as usize) > MAX_ENVELOPE_SIZE {
|
||||
return Err(VeilidAPIError::parse_error("envelope too large", size));
|
||||
apibail_parse_error!("envelope too large", size);
|
||||
}
|
||||
if (size as usize) != data.len() {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
"size doesn't match envelope size",
|
||||
format!(
|
||||
"size doesn't match envelope size: size={} data.len()={}",
|
||||
size,
|
||||
data.len()
|
||||
),
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Get the timestamp
|
||||
@@ -153,10 +150,10 @@ impl Envelope {
|
||||
|
||||
// Ensure sender_id and recipient_id are not the same
|
||||
if sender_id == recipient_id {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
"sender_id should not be same as recipient_id",
|
||||
recipient_id.encode(),
|
||||
));
|
||||
recipient_id.encode()
|
||||
);
|
||||
}
|
||||
|
||||
// Get signature
|
||||
@@ -206,10 +203,7 @@ impl Envelope {
|
||||
// Ensure body isn't too long
|
||||
let envelope_size: usize = body.len() + MIN_ENVELOPE_SIZE;
|
||||
if envelope_size > MAX_ENVELOPE_SIZE {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"envelope size is too large",
|
||||
envelope_size,
|
||||
));
|
||||
apibail_parse_error!("envelope size is too large", envelope_size);
|
||||
}
|
||||
let mut data = vec![0u8; envelope_size];
|
||||
|
||||
|
@@ -59,10 +59,10 @@ impl Receipt {
|
||||
extra_data: D,
|
||||
) -> Result<Self, VeilidAPIError> {
|
||||
if extra_data.as_ref().len() > MAX_EXTRA_DATA_SIZE {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
"extra data too large for receipt",
|
||||
extra_data.as_ref().len(),
|
||||
));
|
||||
extra_data.as_ref().len()
|
||||
);
|
||||
}
|
||||
Ok(Self {
|
||||
version,
|
||||
@@ -75,7 +75,7 @@ impl Receipt {
|
||||
pub fn from_signed_data(data: &[u8]) -> Result<Receipt, VeilidAPIError> {
|
||||
// Ensure we are at least the length of the envelope
|
||||
if data.len() < MIN_RECEIPT_SIZE {
|
||||
return Err(VeilidAPIError::parse_error("receipt too small", data.len()));
|
||||
apibail_parse_error!("receipt too small", data.len());
|
||||
}
|
||||
|
||||
// Verify magic number
|
||||
@@ -83,16 +83,13 @@ impl Receipt {
|
||||
.try_into()
|
||||
.map_err(VeilidAPIError::internal)?;
|
||||
if magic != *RECEIPT_MAGIC {
|
||||
return Err(VeilidAPIError::generic("bad magic number"));
|
||||
apibail_generic!("bad magic number");
|
||||
}
|
||||
|
||||
// Check version
|
||||
let version = data[0x04];
|
||||
if version > MAX_CRYPTO_VERSION || version < MIN_CRYPTO_VERSION {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"unsupported cryptography version",
|
||||
version,
|
||||
));
|
||||
apibail_parse_error!("unsupported cryptography version", version);
|
||||
}
|
||||
|
||||
// Get size and ensure it matches the size of the envelope and is less than the maximum message size
|
||||
@@ -102,16 +99,13 @@ impl Receipt {
|
||||
.map_err(VeilidAPIError::internal)?,
|
||||
);
|
||||
if (size as usize) > MAX_RECEIPT_SIZE {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"receipt size is too large",
|
||||
size,
|
||||
));
|
||||
apibail_parse_error!("receipt size is too large", size);
|
||||
}
|
||||
if (size as usize) != data.len() {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
apibail_parse_error!(
|
||||
"size doesn't match receipt size",
|
||||
format!("size={} data.len()={}", size, data.len()),
|
||||
));
|
||||
format!("size={} data.len()={}", size, data.len())
|
||||
);
|
||||
}
|
||||
|
||||
// Get sender id
|
||||
@@ -153,10 +147,7 @@ impl Receipt {
|
||||
// Ensure extra data isn't too long
|
||||
let receipt_size: usize = self.extra_data.len() + MIN_RECEIPT_SIZE;
|
||||
if receipt_size > MAX_RECEIPT_SIZE {
|
||||
return Err(VeilidAPIError::parse_error(
|
||||
"receipt too large",
|
||||
receipt_size,
|
||||
));
|
||||
apibail_parse_error!("receipt too large", receipt_size);
|
||||
}
|
||||
let mut data: Vec<u8> = vec![0u8; receipt_size];
|
||||
|
||||
|
Reference in New Issue
Block a user