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§
- Connection
String - 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.
- Parse
Error - 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
SignedHeaderslist, 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
datefor the current moment.- string_
to_ sign - The three-line string an ACS signature covers.