mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-20 17:21:03 +01:00
chore(syntax): Use dyn everywhere and remove unused imports.
This commit is contained in:
@@ -153,7 +153,7 @@ impl<'c, C: 'c + hyper::client::connect::Connect> InstalledFlow<C> {
|
||||
Err(e) => {
|
||||
return Err(Box::new(e) as Box<dyn Error + Send>);
|
||||
}
|
||||
Ok(tok) => Ok(tok) as Result<JSONTokenResponse, Box<Error + Send>>,
|
||||
Ok(tok) => Ok(tok) as Result<JSONTokenResponse, Box<dyn Error + Send>>,
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -341,14 +341,15 @@ impl std::ops::Drop for InstalledFlowServer {
|
||||
|
||||
pub struct InstalledFlowHandlerResponseFuture {
|
||||
inner: Box<
|
||||
futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
dyn futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
>,
|
||||
}
|
||||
|
||||
impl InstalledFlowHandlerResponseFuture {
|
||||
fn new(
|
||||
fut: Box<
|
||||
futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
dyn futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error>
|
||||
+ Send,
|
||||
>,
|
||||
) -> Self {
|
||||
Self { inner: fut }
|
||||
|
||||
@@ -46,7 +46,7 @@ fn encode_base64<T: AsRef<[u8]>>(s: T) -> String {
|
||||
base64::encode_config(s.as_ref(), base64::URL_SAFE)
|
||||
}
|
||||
|
||||
fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, Box<error::Error>> {
|
||||
fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, Box<dyn error::Error>> {
|
||||
let private = pem_pkcs8.to_string().replace("\\n", "\n").into_bytes();
|
||||
let mut private_reader: &[u8] = private.as_ref();
|
||||
let private_keys = pemfile::pkcs8_private_keys(&mut private_reader);
|
||||
@@ -121,7 +121,7 @@ impl JWT {
|
||||
head
|
||||
}
|
||||
|
||||
fn sign(&self, private_key: &str) -> Result<String, Box<error::Error>> {
|
||||
fn sign(&self, private_key: &str) -> Result<String, Box<dyn error::Error>> {
|
||||
let mut jwt_head = self.encode_claims();
|
||||
let key = decode_rsa_key(private_key)?;
|
||||
let signing_key = sign::RSASigningKey::new(&key)
|
||||
@@ -236,7 +236,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn request_token(&mut self, scopes: &Vec<&str>) -> result::Result<Token, Box<error::Error>> {
|
||||
fn request_token(
|
||||
&mut self,
|
||||
scopes: &Vec<&str>,
|
||||
) -> result::Result<Token, Box<dyn error::Error>> {
|
||||
let mut claims = init_claims_from_key(&self.key, scopes);
|
||||
claims.sub = self.sub.clone();
|
||||
let signed = JWT::new(claims).sign(self.key.private_key.as_ref().unwrap())?;
|
||||
|
||||
11
src/types.rs
11
src/types.rs
@@ -4,7 +4,7 @@ use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use futures::{future, prelude::*};
|
||||
use futures::prelude::*;
|
||||
|
||||
/// A marker trait for all Flows
|
||||
pub trait Flow {
|
||||
@@ -101,8 +101,8 @@ impl StringError {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Error> for StringError {
|
||||
fn from(err: &'a Error) -> StringError {
|
||||
impl<'a> From<&'a dyn Error> for StringError {
|
||||
fn from(err: &'a dyn Error) -> StringError {
|
||||
StringError::new(err.description().to_string(), None)
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,10 @@ impl FromStr for Scheme {
|
||||
/// The `api_key()` method is an alternative in case there are no scopes or
|
||||
/// if no user is involved.
|
||||
pub trait GetToken {
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> Box<dyn Future<Item = Token, Error = Box<Error>>>
|
||||
fn token<'b, I, T>(
|
||||
&mut self,
|
||||
scopes: I,
|
||||
) -> Box<dyn Future<Item = Token, Error = Box<dyn Error>>>
|
||||
where
|
||||
T: AsRef<str> + Ord + 'b,
|
||||
I: IntoIterator<Item = &'b T>;
|
||||
|
||||
Reference in New Issue
Block a user