-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add is_signal_key_encrypted, is_signal_service_envelope.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
include!(concat!(env!("OUT_DIR"), "/signalservice.rs")); | ||
|
||
use std::ops::Deref; | ||
|
||
impl WebSocketRequestMessage { | ||
/// Equivalent of | ||
/// `SignalServiceMessagePipe::isSignalServiceEnvelope(WebSocketMessage)`. | ||
fn is_signal_service_envelope(&self) -> bool { | ||
self.verb.as_ref().map(Deref::deref) == Some("PUT") | ||
&& self.path.as_ref().map(Deref::deref) == Some("/api/v1/message") | ||
} | ||
|
||
/// Equivalent of | ||
/// `SignalServiceMessagePipe::isSignalKeyEncrypted(WebSocketMessage)`. | ||
fn is_signal_key_encrypted(&self) -> bool { | ||
if self.headers.len() == 0 { | ||
return true; | ||
} | ||
|
||
for header in &self.headers { | ||
let parts: Vec<_> = header.split(':').collect(); | ||
if parts.len() != 2 { | ||
log::warn!( | ||
"Got a weird header: {:?}, split in {:?}", | ||
header, | ||
parts | ||
); | ||
continue; | ||
} | ||
|
||
if parts[0].trim().eq_ignore_ascii_case("X-Signal-Key") { | ||
if parts[1].trim().eq_ignore_ascii_case("false") { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
false | ||
} | ||
} |