Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/features/newsletter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ fn parse_newsletter_messages_response(
let message =
msg_node
.get_optional_child("plaintext")
.and_then(|pt| match pt.content.as_deref() {
.and_then(|pt| match pt.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => {
waproto::codec::message_decode(bytes.as_ref()).ok()
}
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/notification/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub(crate) fn handle_mex_notification(client: &Arc<Client>, node: &NodeRef<'_>)

// `from_str` skips the redundant UTF-8 validation `from_slice` would
// do on a `&str`.
let parsed = match update_node.content.as_deref() {
let parsed = match update_node.content.as_ref() {
Some(NodeContentRef::String(s)) => serde_json::from_str(s),
Some(NodeContentRef::Bytes(b)) => serde_json::from_slice(b.as_ref()),
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/notification/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub(crate) fn handle_status_notification(client: &Arc<Client>, node: &NodeRef<'_
let timestamp = notification_timestamp(node);

if let Some(set_node) = node.get_optional_child("set") {
let status_text = match set_node.content.as_deref() {
let status_text = match set_node.content.as_ref() {
Some(NodeContentRef::String(s)) => s.to_string(),
Some(NodeContentRef::Bytes(b)) => String::from_utf8_lossy(b.as_ref()).into_owned(),
_ => String::new(),
Expand Down
8 changes: 4 additions & 4 deletions src/pair_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ async fn handle_primary_hello(client: &Arc<Client>, reg_node: &NodeRef<'_>) -> b
// Extract primary's wrapped ephemeral public key (80 bytes: salt + iv + encrypted key)
let primary_wrapped_ephemeral = match reg_node
.get_optional_child_by_tag(&["link_code_pairing_wrapped_primary_ephemeral_pub"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) if b.len() == 80 => Some(b.to_vec()),
_ => None,
}) {
Expand All @@ -644,7 +644,7 @@ async fn handle_primary_hello(client: &Arc<Client>, reg_node: &NodeRef<'_>) -> b
// Extract primary's identity public key (32 bytes, unencrypted)
let primary_identity_pub: [u8; 32] = match reg_node
.get_optional_child_by_tag(&["primary_identity_pub"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) if b.len() == 32 => b.as_ref().try_into().ok(),
_ => None,
}) {
Expand All @@ -662,7 +662,7 @@ async fn handle_primary_hello(client: &Arc<Client>, reg_node: &NodeRef<'_>) -> b
// primary_hello whose ref doesn't match the one from our companion_hello.
let notif_ref = match reg_node
.get_optional_child_by_tag(&["link_code_pairing_ref"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.to_vec()),
_ => None,
}) {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ async fn replace_adv_secret_key(client: &Arc<Client>) {
async fn handle_refresh_code(client: &Arc<Client>, reg_node: &NodeRef<'_>) -> bool {
let notif_ref = match reg_node
.get_optional_child_by_tag(&["link_code_pairing_ref"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.to_vec()),
_ => None,
}) {
Expand Down
2 changes: 1 addition & 1 deletion src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn get_bytes_content(node: &Node) -> Option<&[u8]> {

/// Helper to extract bytes content from a NodeRef.
fn get_bytes_content_ref<'a>(node: &'a NodeRef<'_>) -> Option<&'a [u8]> {
match node.content.as_deref() {
match node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.as_ref()),
_ => None,
}
Expand Down
6 changes: 3 additions & 3 deletions wacore/binary/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ impl<'a> Decoder<'a> {

let attrs = self.read_attributes(attr_count)?;
let content = if has_content {
self.read_content(depth)?.map(Box::new)
self.read_content(depth)?
} else {
None
};
Expand Down Expand Up @@ -618,7 +618,7 @@ mod tests {
assert_eq!(decoded.tag, "message");
assert!(decoded.attrs.is_empty());
match &decoded.content {
Some(content) => match &**content {
Some(content) => match content {
NodeContentRef::String(s) => assert_eq!(s, "receipt"),
_ => panic!("Expected string content"),
},
Expand Down Expand Up @@ -648,7 +648,7 @@ mod tests {
assert_eq!(decoded.tag, "test");
assert!(decoded.attrs.is_empty());
match &decoded.content {
Some(content) => match &**content {
Some(content) => match content {
NodeContentRef::String(s) => assert_eq!(s, test_str),
_ => panic!("Expected string content"),
},
Expand Down
4 changes: 2 additions & 2 deletions wacore/binary/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl EncodeNode for NodeRef<'_> {
}

fn encode_content<'a, W: ByteWriter>(&self, encoder: &mut Encoder<'a, W>) -> Result<()> {
if let Some(content) = self.content.as_deref() {
if let Some(content) = self.content.as_ref() {
match content {
NodeContentRef::String(s) => encoder.write_string(s)?,
NodeContentRef::Bytes(b) => encoder.write_bytes_with_len(b)?,
Expand Down Expand Up @@ -505,7 +505,7 @@ fn node_ref_encoded_size_with_cache(node: &NodeRef<'_>, hints: &mut StringHintCa
};
}

size += match node.content.as_deref() {
size += match node.content.as_ref() {
Some(NodeContentRef::String(s)) => string_encoded_size_with_cache(s, hints),
Some(NodeContentRef::Bytes(b)) => bytes_with_len_encoded_size(b.len()),
Some(NodeContentRef::Nodes(nodes)) => {
Expand Down
8 changes: 4 additions & 4 deletions wacore/binary/src/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn should_auto_reserve_node_ref(node: &NodeRef<'_>) -> bool {
return true;
}

match node.content.as_deref() {
match node.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => bytes.len() >= AUTO_RESERVE_SCALAR_THRESHOLD,
Some(NodeContentRef::String(text)) => text.len() >= AUTO_RESERVE_SCALAR_THRESHOLD,
Some(NodeContentRef::Nodes(children)) => {
Expand All @@ -178,7 +178,7 @@ fn should_auto_reserve_node_ref(node: &NodeRef<'_>) -> bool {
}
// Check one level deeper for large nested lists (e.g., <iq> -> <list> -> 812 keys)
children.iter().any(|child| {
matches!(child.content.as_deref(), Some(NodeContentRef::Nodes(gc)) if gc.len() >= AUTO_RESERVE_CHILDREN_THRESHOLD)
matches!(child.content.as_ref(), Some(NodeContentRef::Nodes(gc)) if gc.len() >= AUTO_RESERVE_CHILDREN_THRESHOLD)
})
}
None => false,
Expand Down Expand Up @@ -227,7 +227,7 @@ fn estimate_capacity_node_ref(node: &NodeRef<'_>) -> usize {
estimate += node.tag.len();
estimate += node.attrs.len() * AUTO_ATTR_ESTIMATE;

match node.content.as_deref() {
match node.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => {
estimate += bytes.len() + 8;
}
Expand All @@ -238,7 +238,7 @@ fn estimate_capacity_node_ref(node: &NodeRef<'_>) -> usize {
estimate += children.len() * AUTO_CHILD_ESTIMATE;
for child in children.iter().take(AUTO_CHILD_SAMPLE_LIMIT) {
estimate += child.tag.len() + child.attrs.len() * AUTO_ATTR_ESTIMATE;
match child.content.as_deref() {
match child.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => estimate += bytes.len() + 8,
Some(NodeContentRef::String(text)) => estimate += text.len() + 8,
Some(NodeContentRef::Nodes(grand_children)) => {
Expand Down
16 changes: 8 additions & 8 deletions wacore/binary/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ pub struct Node {
pub struct NodeRef<'a> {
pub tag: NodeStr<'a>,
pub attrs: AttrsRef<'a>,
pub content: Option<Box<NodeContentRef<'a>>>,
pub content: Option<NodeContentRef<'a>>,
}

impl Node {
Expand Down Expand Up @@ -685,7 +685,7 @@ impl Node {
(NodeStr::Borrowed(k.as_ref()), value_ref)
})
.collect(),
content: self.content.as_ref().map(|c| Box::new(c.as_content_ref())),
content: self.content.as_ref().map(|c| c.as_content_ref()),
}
}

Expand Down Expand Up @@ -767,7 +767,7 @@ impl<'a> NodeRef<'a> {
Self {
tag,
attrs,
content: content.map(Box::new),
content,
}
}

Expand All @@ -776,7 +776,7 @@ impl<'a> NodeRef<'a> {
}

pub fn children(&self) -> Option<&[NodeRef<'a>]> {
match self.content.as_deref() {
match self.content.as_ref() {
Some(NodeContentRef::Nodes(nodes)) => Some(nodes),
_ => None,
}
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<'a> NodeRef<'a> {

/// Extract text content, handling both String and Bytes (lossy UTF-8).
pub fn content_as_string(&self) -> Option<CompactString> {
match self.content.as_deref() {
match self.content.as_ref() {
Some(NodeContentRef::String(s)) => Some(s.to_compact_string()),
Some(NodeContentRef::Bytes(b)) => Some(CompactString::from(
String::from_utf8_lossy(b.as_ref()).as_ref(),
Expand All @@ -827,15 +827,15 @@ impl<'a> NodeRef<'a> {

/// Zero-copy byte content, if this node has Bytes content.
pub fn content_bytes(&self) -> Option<&[u8]> {
match self.content.as_deref() {
match self.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.as_ref()),
_ => None,
}
}

/// Zero-copy string content, if this node has String content.
pub fn content_str(&self) -> Option<&str> {
match self.content.as_deref() {
match self.content.as_ref() {
Some(NodeContentRef::String(s)) => Some(s.as_ref()),
_ => None,
}
Expand All @@ -862,7 +862,7 @@ impl<'a> NodeRef<'a> {
(intern_cow(k), value)
})
.collect::<Attrs>(),
content: self.content.as_deref().map(|c| match c {
content: self.content.as_ref().map(|c| match c {
NodeContentRef::Bytes(b) => NodeContent::Bytes(b.to_vec()),
NodeContentRef::String(s) => NodeContent::String(s.to_compact_string()),
NodeContentRef::Nodes(nodes) => {
Expand Down
2 changes: 1 addition & 1 deletion wacore/src/iq/business.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum BusinessHourMode {
}

fn node_text(node: &NodeRef<'_>) -> Option<String> {
match node.content.as_deref() {
match node.content.as_ref() {
Some(NodeContentRef::String(s)) => Some(s.to_string()),
Some(NodeContentRef::Bytes(b)) => std::str::from_utf8(b).ok().map(|s| s.to_string()),
_ => None,
Expand Down
6 changes: 3 additions & 3 deletions wacore/src/iq/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,14 +1172,14 @@ impl ProtocolNode for GroupInfoResponse {

let member_add_mode = node
.get_optional_child_by_tag(&["member_add_mode"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::String(s)) => MemberAddMode::try_from(s.as_ref()).ok(),
_ => None,
});

let member_link_mode = node
.get_optional_child_by_tag(&["member_link_mode"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::String(s)) => MemberLinkMode::try_from(s.as_ref()).ok(),
_ => None,
});
Expand Down Expand Up @@ -1229,7 +1229,7 @@ impl ProtocolNode for GroupInfoResponse {

let member_share_history_mode = node
.get_optional_child_by_tag(&["member_share_group_history_mode"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::String(s)) => {
MemberShareHistoryMode::try_from(s.as_ref()).ok()
}
Expand Down
2 changes: 1 addition & 1 deletion wacore/src/iq/mex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl IqSpec for MexQuerySpec {
.ok_or_else(|| anyhow!("Missing <result> node in MEX response"))?;

// Handle both binary and string content from the server
let mex_response: MexResponse = match result_node.content.as_deref() {
let mex_response: MexResponse = match result_node.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => serde_json::from_slice(bytes)?,
Some(NodeContentRef::String(s)) => serde_json::from_str(s)?,
_ => return Err(anyhow!("MEX result node content is not binary or string")),
Expand Down
4 changes: 2 additions & 2 deletions wacore/src/iq/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn collect_children<T: ProtocolNode>(
/// Extract binary content from an optional `NodeRef` as `Vec<u8>`.
/// Returns an empty vector if the node is `None` or does not hold byte content.
pub(crate) fn extract_content_bytes(node: Option<&NodeRef<'_>>) -> Vec<u8> {
node.and_then(|n| match n.content.as_deref() {
node.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.to_vec()),
_ => None,
})
Expand All @@ -53,7 +53,7 @@ pub(crate) fn extract_content_bytes(node: Option<&NodeRef<'_>>) -> Vec<u8> {
/// Extract binary content from an optional `NodeRef` as a big-endian `u32`.
/// Returns 0 if the node is missing or does not hold byte content. Truncates to 4 bytes.
pub(crate) fn extract_content_uint(node: Option<&NodeRef<'_>>) -> u32 {
node.and_then(|n| match n.content.as_deref() {
node.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => {
let mut buf = [0u8; 4];
let len = b.len().min(4);
Expand Down
20 changes: 10 additions & 10 deletions wacore/src/iq/prekeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl IqSpec for DigestKeyBundleSpec {
let reg_id = extract_content_uint(Some(reg_node));

let identity_node = required_child(digest_node, "identity")?;
let identity = match identity_node.content.as_deref() {
let identity = match identity_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) if !b.is_empty() => b.to_vec(),
_ => return Err(anyhow!("missing or empty bytes in <identity>")),
};
Expand Down Expand Up @@ -280,7 +280,7 @@ impl IqSpec for DigestKeyBundleSpec {
.unwrap_or_default();

let hash_node = required_child(digest_node, "hash")?;
let hash = match hash_node.content.as_deref() {
let hash = match hash_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) if !b.is_empty() => b.to_vec(),
_ => return Err(anyhow!("missing or empty bytes in <hash>")),
};
Expand Down Expand Up @@ -623,14 +623,14 @@ impl ProtocolNode for SignedPreKeyNode {
}

let id_node = required_child(node, "id")?;
let id_bytes = match id_node.content.as_deref() {
let id_bytes = match id_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b,
_ => return Err(anyhow!("missing bytes in <id>")),
};
let id = expand_from_3bytes(id_bytes)?;

let value_node = required_child(node, "value")?;
let public_bytes = match value_node.content.as_deref() {
let public_bytes = match value_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b.to_vec(),
_ => return Err(anyhow!("missing bytes in <value>")),
};
Expand All @@ -639,7 +639,7 @@ impl ProtocolNode for SignedPreKeyNode {
}

let sig_node = required_child(node, "signature")?;
let signature = match sig_node.content.as_deref() {
let signature = match sig_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b.to_vec(),
_ => return Err(anyhow!("missing bytes in <signature>")),
};
Expand Down Expand Up @@ -698,14 +698,14 @@ impl ProtocolNode for OneTimePreKeyNode {
}

let id_node = required_child(node, "id")?;
let id_bytes = match id_node.content.as_deref() {
let id_bytes = match id_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b,
_ => return Err(anyhow!("missing bytes in <id>")),
};
let id = expand_from_3bytes(id_bytes)?;

let value_node = required_child(node, "value")?;
let public_bytes = match value_node.content.as_deref() {
let public_bytes = match value_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b.to_vec(),
_ => return Err(anyhow!("missing bytes in <value>")),
};
Expand Down Expand Up @@ -846,7 +846,7 @@ impl ProtocolNode for PreKeyBundleUserNode {

// Parse registration ID (4 bytes big-endian)
let reg_node = required_child(node, "registration")?;
let reg_bytes = match reg_node.content.as_deref() {
let reg_bytes = match reg_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b,
_ => return Err(anyhow!("missing bytes in <registration>")),
};
Expand All @@ -858,7 +858,7 @@ impl ProtocolNode for PreKeyBundleUserNode {

// Parse identity key (32 bytes)
let identity_node = required_child(node, "identity")?;
let identity_key = match identity_node.content.as_deref() {
let identity_key = match identity_node.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => b.to_vec(),
_ => return Err(anyhow!("missing bytes in <identity>")),
};
Expand All @@ -878,7 +878,7 @@ impl ProtocolNode for PreKeyBundleUserNode {

// Parse optional device identity
let device_identity = match node.get_optional_child("device-identity") {
Some(n) => match n.content.as_deref() {
Some(n) => match n.content.as_ref() {
Some(NodeContentRef::Bytes(b)) => Some(b.to_vec()),
_ => return Err(anyhow!("device-identity must be bytes")),
},
Expand Down
2 changes: 1 addition & 1 deletion wacore/src/iq/spam_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl IqSpec for SpamReportSpec {
// Extract report_id from response if present
let report_id = response
.get_optional_child_by_tag(&["report_id"])
.and_then(|n| match n.content.as_deref() {
.and_then(|n| match n.content.as_ref() {
Some(NodeContentRef::String(s)) => Some(s.to_string()),
_ => None,
});
Expand Down
2 changes: 1 addition & 1 deletion wacore/src/iq/usync/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ fn parse_key_index(node: &NodeRef<'_>) -> Result<UsyncKeyIndexResult, anyhow::Er
let expected_timestamp = attrs.optional_unix_time(ATTR_EXPECTED_TIMESTAMP);
attrs.finish()?;

let signed_key_index_bytes = match node.content.as_deref() {
let signed_key_index_bytes = match node.content.as_ref() {
Some(NodeContentRef::Bytes(bytes)) => Some(bytes.to_vec()),
None => None,
Some(_) => {
Expand Down
Loading