Skip to main content

sign_request

Function sign_request 

Source
pub fn sign_request(
    method: &str,
    url: &str,
    body: &[u8],
    key_id: &str,
    private_key_pem: &str,
    extra_headers: &[(&str, &str)],
    now: i64,
) -> Result<SignedHeaders, Error>
Expand description

Sign an outgoing HTTP POST request body using RSA-SHA256.

Returns SignedHeaders that the caller must attach to the request.

Covers host, date, any extra_headers given, digest, and (request-target) — in that order, as Mastodon does. extra_headers are headers the caller will send and wants covered, such as Content-Type; Mastodon covers every header on the request except User-Agent, Accept and Accept-Encoding.

§Arguments

  • method – HTTP method in any case (will be lowercased)
  • url – Full URL of the target inbox
  • body – Serialized activity body (JSON bytes)
  • key_id – keyId URI, typically https://actor/url#main-key
  • private_key_pem – PKCS#8 or PKCS#1 PEM-encoded RSA private key
  • extra_headers – Additional headers to cover, in the order sent
  • now – The time, in seconds since the Unix epoch, which becomes the Date header

§Errors

Returns an error if the URL cannot be parsed or the key cannot sign.