Skip to content

Commit

Permalink
Fix compilation for Rust 1.75 and remove unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Oct 17, 2024
1 parent 660dc91 commit 59078db
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
let ciphertext = if let Some(msg) = envelope.content.as_ref() {
msg
} else {
return Err(ServiceError::InvalidFrameError {
return Err(ServiceError::InvalidFrame {
reason:
"Envelope should have either a legacy message or content."
.into(),
Expand Down Expand Up @@ -311,7 +311,7 @@ where
},
_ => {
// else
return Err(ServiceError::InvalidFrameError {
return Err(ServiceError::InvalidFrame {
reason: format!(
"Envelope has unknown type {:?}.",
envelope.r#type()
Expand Down Expand Up @@ -408,7 +408,7 @@ struct Plaintext {
#[allow(clippy::comparison_chain)]
fn add_padding(version: u32, contents: &[u8]) -> Result<Vec<u8>, ServiceError> {
if version < 2 {
Err(ServiceError::InvalidFrameError {
Err(ServiceError::InvalidFrame {
reason: format!("Unknown version {}", version),
})
} else if version == 2 {
Expand Down Expand Up @@ -436,7 +436,7 @@ fn strip_padding_version(
contents: &mut Vec<u8>,
) -> Result<(), ServiceError> {
if version < 2 {
Err(ServiceError::InvalidFrameError {
Err(ServiceError::InvalidFrame {
reason: format!("Unknown version {}", version),
})
} else if version == 2 {
Expand All @@ -450,7 +450,7 @@ fn strip_padding_version(
#[allow(clippy::comparison_chain)]
fn strip_padding(contents: &mut Vec<u8>) -> Result<(), ServiceError> {
let new_length = Iso7816::raw_unpad(contents)
.map_err(|e| ServiceError::InvalidFrameError {
.map_err(|e| ServiceError::InvalidFrame {
reason: format!("Invalid message padding: {:?}", e),
})?
.len();
Expand Down
2 changes: 1 addition & 1 deletion src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Envelope {
if input.len() < VERSION_LENGTH
|| input[VERSION_OFFSET] != SUPPORTED_VERSION
{
return Err(ServiceError::InvalidFrameError {
return Err(ServiceError::InvalidFrame {
reason: "Unsupported signaling cryptogram version".into(),
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/messagepipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl MessagePipe {
let body = if let Some(body) = request.body.as_ref() {
body
} else {
return Err(ServiceError::InvalidFrameError {
return Err(ServiceError::InvalidFrame {
reason: "Request without body.".into(),
});
};
Expand Down
18 changes: 13 additions & 5 deletions src/push_service/cdn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ impl PushService {
&mut self,
ptr: &AttachmentPointer,
) -> Result<impl futures::io::AsyncRead + Send + Unpin, ServiceError> {
let id = match ptr.attachment_identifier.as_ref().unwrap() {
AttachmentIdentifier::CdnId(id) => &id.to_string(),
AttachmentIdentifier::CdnKey(key) => key,
let path = match ptr.attachment_identifier.as_ref() {
Some(AttachmentIdentifier::CdnId(id)) => {
format!("attachments/{}", id)
},
Some(AttachmentIdentifier::CdnKey(key)) => {
format!("attachments/{}", key)
},
None => {
return Err(ServiceError::InvalidFrame {
reason: "no attachment identifier in pointer".into(),
});
},
};
self.get_from_cdn(ptr.cdn_number(), &format!("attachments/{}", id))
.await
self.get_from_cdn(ptr.cdn_number(), &path).await
}

#[tracing::instrument(skip(self))]
Expand Down
2 changes: 1 addition & 1 deletion src/push_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum ServiceError {
WsClosing { reason: &'static str },

#[error("Invalid frame: {reason}")]
InvalidFrameError { reason: String },
InvalidFrame { reason: String },

#[error("MAC error")]
MacError,
Expand Down
6 changes: 3 additions & 3 deletions src/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl SignalWebSocketProcess {

use web_socket_message::Type;
match (msg.r#type(), msg.request, msg.response) {
(Type::Unknown, _, _) => Err(ServiceError::InvalidFrameError {
(Type::Unknown, _, _) => Err(ServiceError::InvalidFrame {
reason: "Unknown frame type".into(),
}),
(Type::Request, Some(request), _) => {
Expand All @@ -137,7 +137,7 @@ impl SignalWebSocketProcess {

Ok(())
},
(Type::Request, None, _) => Err(ServiceError::InvalidFrameError {
(Type::Request, None, _) => Err(ServiceError::InvalidFrame {
reason: "Type was request, but does not contain request."
.into(),
}),
Expand Down Expand Up @@ -175,7 +175,7 @@ impl SignalWebSocketProcess {

Ok(())
},
(Type::Response, _, None) => Err(ServiceError::InvalidFrameError {
(Type::Response, _, None) => Err(ServiceError::InvalidFrame {
reason: "Type was response, but does not contain response."
.into(),
}),
Expand Down

0 comments on commit 59078db

Please sign in to comment.