Skip to main content

sign_request

Function sign_request 

Source
pub fn sign_request(
    method: &str,
    url: &str,
    body: Option<&[u8]>,
    key_id: &str,
    key: &SigningKey<'_>,
    now: i64,
) -> Result<SignedHeaders, Error>
Expand description

Sign an outgoing request.

Covers @method and @target-uri, plus content-digest when there is a body — the components Mastodon covers, so that a Mastodon peer verifies what it expects to. The algorithm follows from the key.

§Arguments

  • method – HTTP method; canonicalised to uppercase for @method
  • url – full request URL, which becomes @target-uri
  • body – request body, or None for a bodyless request
  • key_id – keyid parameter, the URI identifying the key
  • key – the private key to sign with
  • now – the time, in seconds since the Unix epoch, which becomes created

§Errors

Returns an error if the key cannot be parsed or the signature cannot be made.