Skip to content

Commit

Permalink
cleaner rtsp_types->digest_auth method conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
scottlamb committed May 24, 2021
1 parent 93f7d62 commit e77360d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rtsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ async-stream = "0.3.1"
base64 = "0.13.0"
bitreader = "0.3.3"
bytes = "1.0.1"
digest_auth = "0.2.4"
#digest_auth = "0.2.4"
digest_auth = { git = "https://git.ondrovo.com/slamb/digest_auth_rs.git", branch = "pr-method-lifetime" }
failure = "0.1.8"
futures = "0.3.14"
hex = "0.4.3"
Expand Down
23 changes: 2 additions & 21 deletions rtsp/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,6 @@ pub struct Session<S: State> {
state: S,
}

/// Converts from an RTSP method to a digest method.
/// Unfortunately all [digest_auth::HttpMethod]s have to be `&'static`, where all the other parameters are `Cow`.
/// Therefore extension methods aren't supported for now.
fn http_method(method: &rtsp_types::Method) -> Result<digest_auth::HttpMethod, Error> {
use rtsp_types::Method;
Ok(digest_auth::HttpMethod::OTHER(match method {
Method::Describe => "DESCRIBE",
Method::GetParameter => "GET_PARAMETER",
Method::Options => "OPTIONS",
Method::Pause => "PAUSE",
Method::Play => "PLAY",
Method::PlayNotify => "PLAY_NOTIFY",
Method::Redirect => "REDIRECT",
Method::Setup => "SETUP",
Method::SetParameter => "SET_PARAMETER",
Method::Teardown => "TEARDOWN",
Method::Extension(m) => bail!("can't authenticate with method {:?}", &m),
}))
}

impl RtspConnection {
async fn connect(url: &Url, creds: Option<Credentials>) -> Result<Self, Error> {
if url.scheme() != "rtsp" {
Expand Down Expand Up @@ -426,8 +406,9 @@ impl RtspConnection {
(None, _) => {},
(Some(auth), Some(creds)) => {
let uri = req.request_uri().map(|u| u.as_str()).unwrap_or("*");
let method = digest_auth::HttpMethod::OTHER(req.method().into());
let ctx = digest_auth::AuthContext::new_with_method(
&creds.username, &creds.password, uri, Option::<&'static [u8]>::None, http_method(req.method())?);
&creds.username, &creds.password, uri, Option::<&'static [u8]>::None, method);
let authorization = auth.respond(&ctx)?.to_string();
req.insert_header(rtsp_types::headers::AUTHORIZATION, authorization);
},
Expand Down

0 comments on commit e77360d

Please sign in to comment.