Expand description
The Azure Cosmos DB master-key Authorization header.
Pure functions and known-answer tests. No HTTP client, no async runtime, no TLS stack — this crate computes a header value and stops.
§Why it is worth having separately
Three details of the signing algorithm each produce an indistinguishable
401, and none can be checked against a live account without a
subscription:
- The case of each line. The verb and the resource type are lowercased; the resource link is not. Lowercasing the link too is the classic mistake.
- The date appears identically in two places — in the string to
sign and in the
x-ms-dateheader — and must be lowercase RFC 1123 in GMT in both. - There is a trailing empty line. The string to sign ends
\n\n.
All three can be checked against the published algorithm, here, offline.
MasterKey does that; the transport is somebody else’s problem.
§Examples
use cosmos_signature::{MasterKey, ResourceType, date};
use time::macros::datetime;
// The account key, as the Azure portal prints it.
let key = MasterKey::new("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")?;
let when = date(datetime!(2026-08-22 09:15:00 UTC));
let header = key.authorization("GET", ResourceType::Docs, "dbs/MyDb/colls/MyColl/docs/Config", &when);
// Send `header` as `Authorization` and `when` as `x-ms-date` — the same
// string, in both places.
assert!(header.starts_with("type%3Dmaster"));
assert_eq!(when, "sat, 22 aug 2026 09:15:00 gmt");Structs§
- Master
Key - A validated Cosmos DB account key, ready to sign with.
Enums§
- KeyError
- Why an account key could not be used for signing.
- Resource
Type - Which kind of resource a request addresses.
Constants§
- DEFAULT_
API_ VERSION - The
x-ms-versionto send alongside a signature computed here.
Functions§
- container_
link - The resource link for a container:
dbs/{database}/colls/{container}. - database_
link - The resource link for a database:
dbs/{database}. - date
- The date format Cosmos wants: lowercase RFC 1123 in GMT.
- document_
link - The resource link for one document.
- document_
url - The URL for one document.
- documents_
url - The URL for a container’s document collection.
- now
datefor the current moment.- string_
to_ sign - The five-line string a Cosmos signature covers.