Skip to main content

Crate acs_signature

Crate acs_signature 

Source
Expand description

Signing Azure Communication Services requests with an access key.

Every ACS data-plane API — email, SMS, chat, identity — accepts the same HMAC-SHA256 access-key scheme, and this crate computes it. Connection string in, three headers out. No HTTP client, no async runtime, no TLS stack.

§The scheme, in one line

Sign "{METHOD}\n{path and query}\n{date};{host};{base64 sha256 of the body}" with the base64-decoded access key, then send the signature alongside the date and the body hash — because the two headers are part of what was signed, and the service recomputes both.

§Examples

use acs_signature::{ConnectionString, Signer};

let parsed = ConnectionString::parse(
    "endpoint=https://contoso.communication.azure.com/;accesskey=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
)?;
let signer = Signer::new(parsed.access_key())?;

let body = r#"{"senderAddress":"a@b.c"}"#;
let signed = signer.sign(
    "POST",
    "/emails:send?api-version=2023-03-31",
    "contoso.communication.azure.com",
    &acs_signature::now(),
    body.as_bytes(),
);

// Send all three, exactly as given.
for (name, value) in signed.headers() {
    let _ = (name, value);
}

Structs§

ConnectionString
The two parts of an ACS connection string.
Signed
The three headers a signed request carries.
Signer
A validated access key, ready to sign with.

Enums§

KeyError
Why an access key could not be used for signing.
ParseError
Why a connection string could not be used.

Constants§

AUTHORIZATION_HEADER
The header carrying the signature.
CONTENT_HASH_HEADER
The header carrying the base64 SHA-256 of the body.
DATE_HEADER
The header carrying the request date.
SIGNED_HEADERS
The headers named in the SignedHeaders list, in the order they are signed in.

Functions§

content_hash
The base64 SHA-256 of a request body.
date
The date format ACS wants: lowercase RFC 1123 in GMT.
now
date for the current moment.
string_to_sign
The three-line string an ACS signature covers.