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 inboxbody– Serialized activity body (JSON bytes)key_id–keyIdURI, typicallyhttps://actor/url#main-keyprivate_key_pem– PKCS#8 or PKCS#1 PEM-encoded RSA private keyextra_headers– Additional headers to cover, in the order sentnow– The time, in seconds since the Unix epoch, which becomes theDateheader
§Errors
Returns an error if the URL cannot be parsed or the key cannot sign.