fn sign_and_send<T: Serialize>(
        &self,
        mut request: ureq::Request,
        body: Option<T>,
    ) -> ureq::Response {
        let body = body
            .map(|x| serde_json::to_string(&x).unwrap())
            .unwrap_or("".to_string());
        let digest = format!(
            "SHA256={}",
            base64::encode(Sha256::digest(&body.as_bytes()))
        );
        request.set("Digest", &digest);
        // Check the mandatory headers
        if !request.has("host") {
            request.set("Host", "authservices.satispay.com");
        }
        if !request.has("date") {
            request.set("Date", &chrono::Utc::now().to_rfc2822());
        }
        let headers = ["digest", "host", "date"]
            .iter()
            .map(|x| format!("{}: {}", *x, request.header(x).unwrap()))
            .collect::<Vec<String>>()
            .join("\n");
        let string = format!(
            "(request-target): {} {}{}\n{}",
            request.get_method().to_lowercase(),
            request.get_path().unwrap(),
            request.get_query().unwrap(),
            headers
        );
        let string_digest = Sha256::digest(string.as_bytes());
        let padding = rsa::PaddingScheme::new_pkcs1v15_sign(Some(rsa::Hash::SHA2_256));
        let signature = base64::encode(self.private_key.sign(padding, &string_digest).unwrap());
        let signature_header = format!("keyId=\"{}\", algorithm=\"rsa-sha256\", headers=\"(request-target) digest host date\", signature=\"{}\"", self.key_id, signature);
        request.auth_kind("Signature", &signature_header);
        if body != "" {
            request.set("Content-Type", "application/json");
        }
        request.send_string(&body)
    }
/// Internal function used to sign the request
Internal function used to sign the request
Internal function used to sign the request
fn sign_and_send<T: Serialize>(
        &self,
        mut request: ureq::Request,
        body: Option<T>,
    ) -> ureq::Response {
        let body = body
            .map(|x| serde_json::to_string(&x).unwrap())
            .unwrap_or("".to_string());
        let digest = format!(
            "SHA256={}",
            base64::encode(Sha256::digest(&body.as_bytes()))
        );
        request.set("Digest", &digest);
        // Check the mandatory headers
        if !request.has("host") {
            request.set("Host", "authservices.satispay.com");
        }
        if !request.has("date") {
            request.set("Date", &chrono::Utc::now().to_rfc2822());
        }
        let headers = ["digest", "host", "date"]
            .iter()
            .map(|x| format!("{}: {}", *x, request.header(x).unwrap()))
            .collect::<Vec<String>>()
            .join("\n");
        let string = format!(
            "(request-target): {} {}{}\n{}",
            request.get_method().to_lowercase(),
            request.get_path().unwrap(),
            request.get_query().unwrap(),
            headers
        );
        let string_digest = Sha256::digest(string.as_bytes());
        let padding = rsa::PaddingScheme::new_pkcs1v15_sign(Some(rsa::Hash::SHA2_256));
        let signature = base64::encode(self.private_key.sign(padding, &string_digest).unwrap());
        let signature_header = format!("keyId=\"{}\", algorithm=\"rsa-sha256\", headers=\"(request-target) digest host date\", signature=\"{}\"", self.key_id, signature);
        request.auth_kind("Signature", &signature_header);
        if body != "" {
            request.set("Content-Type", "application/json");
        }
        request.send_string(&body)
    }
fn sign_and_send < T : Serialize > ( & self , mut request : ureq :: Request , body : Option < T > , ) -> ureq :: Response { let body = body . map ( | x | serde_json :: to_string ( & x ) . unwrap ( ) ) . unwrap_or ( " " . to_string ( ) ) ; let digest = format ! ( " " base64 encode ( Sha256 digest ( body as_bytes ( ) ) ) ) ; request . set ( " " , & digest ) ; // Check the mandatory headers if ! request . has ( " " ) { request . set ( " " , " " ) ; } if ! request . has ( " " ) { request . set ( " " , & chrono :: Utc :: now ( ) . to_rfc2822 ( ) ) ; } let headers = [ " " , " " , " " ] . iter ( ) . map ( | x | format ! ( " " x request header ( x ) unwrap ( ) ) ) . collect :: < Vec < String > > ( ) . join ( " \n " ) ; let string = format ! ( " \n " request get_method ( ) to_lowercase ( ) request get_path ( ) unwrap ( ) request get_query ( ) unwrap ( ) headers ) ; let string_digest = Sha256 :: digest ( string . as_bytes ( ) ) ; let padding = rsa :: PaddingScheme :: new_pkcs1v15_sign ( Some ( rsa :: Hash :: SHA2_256 ) ) ; let signature = base64 :: encode ( self . private_key . sign ( padding , & string_digest ) . unwrap ( ) ) ; let signature_header = format ! ( " \" \" \" \" \" \" \" \" " self key_id signature ) ; request . auth_kind ( " " , & signature_header ) ; if body != " " { request . set ( " " , " " ) ; } request . send_string ( & body ) }
Internal function used to sign the request
Internal function used to sign the request
&self
request
ureq::Request
body
Option<T>
&self
request
ureq::Request
body
Option<T>