1use std::fmt;
2use time::OffsetDateTime;
34pub mod account_sas;
5pub mod service_sas;
67pub trait SasToken {
8fn token(&self) -> azure_core::Result<String>;
9}
1011/// Converts an `OffsetDateTime` to an RFC3339 formatted string after truncating
12/// any partial seconds.
13pub(crate) fn format_date(d: OffsetDateTime) -> String {
14// When validating signatures, Azure Storage server creates a canonicalized
15 // version of the request, then verifies the signature from the request with
16 // the canonicalized version.
17 //
18 // The canonicalization at the server truncates the timestamps without
19 // microseconds or nanoseconds. As such, this needs to be truncated here
20 // too.
21 //
22 // replacing nanosecond with 0 is known to not panic
23azure_core::date::to_rfc3339(&d.replace_nanosecond(0).unwrap())
24}
2526/// Specifies the protocol permitted for a request made with the SAS ([Azure documentation](https://docs.microsoft.com/rest/api/storageservices/create-service-sas#specifying-the-http-protocol)).
27#[derive(Copy, Clone, PartialEq, Eq, Debug)]
28pub enum SasProtocol {
29 Https,
30 HttpHttps,
31}
3233impl fmt::Display for SasProtocol {
34fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35match *self {
36 SasProtocol::Https => write!(f, "https"),
37 SasProtocol::HttpHttps => write!(f, "http,https"),
38 }
39 }
40}
4142#[cfg(test)]
43mod tests {
44use super::*;
45use time::macros::datetime;
4647#[test]
48// verify format_date truncates as expected.
49fn test_format_date_truncation() {
50let date = datetime!(2022-08-22 15:11:43.4185122 +00:00:00);
51assert_eq!(format_date(date), "2022-08-22T15:11:43Z");
52 }
53}