aws_sigv4/
http_request.rs1mod canonical_request;
59mod error;
60mod settings;
61mod sign;
62mod uri_path_normalization;
63mod url_escape;
64
65#[cfg(test)]
66pub(crate) mod test;
67
68use crate::sign::v4;
69#[cfg(feature = "sigv4a")]
70use crate::sign::v4a;
71use crate::SignatureVersion;
72use aws_credential_types::Credentials;
73pub use error::SigningError;
74pub use settings::{
75 PayloadChecksumKind, PercentEncodingMode, SessionTokenMode, SignatureLocation, SigningSettings,
76 UriPathNormalizationMode,
77};
78pub use sign::{sign, SignableBody, SignableRequest, SigningInstructions};
79use std::time::SystemTime;
80
81#[derive(Debug)]
83#[non_exhaustive]
84pub enum SigningParams<'a> {
86 V4(v4::SigningParams<'a, SigningSettings>),
88 #[cfg(feature = "sigv4a")]
89 V4a(v4a::SigningParams<'a, SigningSettings>),
91}
92
93impl<'a> From<v4::SigningParams<'a, SigningSettings>> for SigningParams<'a> {
94 fn from(value: v4::SigningParams<'a, SigningSettings>) -> Self {
95 Self::V4(value)
96 }
97}
98
99#[cfg(feature = "sigv4a")]
100impl<'a> From<v4a::SigningParams<'a, SigningSettings>> for SigningParams<'a> {
101 fn from(value: v4a::SigningParams<'a, SigningSettings>) -> Self {
102 Self::V4a(value)
103 }
104}
105
106impl<'a> SigningParams<'a> {
107 pub(crate) fn credentials(&self) -> Result<&Credentials, SigningError> {
109 let identity = match self {
110 Self::V4(v4::SigningParams { identity, .. }) => identity,
111 #[cfg(feature = "sigv4a")]
112 Self::V4a(v4a::SigningParams { identity, .. }) => identity,
113 };
114
115 identity
116 .data::<Credentials>()
117 .ok_or_else(SigningError::unsupported_identity_type)
118 }
119
120 pub fn region(&self) -> Option<&str> {
122 match self {
123 SigningParams::V4(v4::SigningParams { region, .. }) => Some(region),
124 #[allow(unreachable_patterns)]
125 _ => None,
126 }
127 }
128
129 #[cfg(feature = "sigv4a")]
130 pub fn region_set(&self) -> Option<&str> {
132 match self {
133 SigningParams::V4a(v4a::SigningParams { region_set, .. }) => Some(region_set),
134 _ => None,
135 }
136 }
137
138 pub fn settings(&self) -> &SigningSettings {
140 match self {
141 Self::V4(v4::SigningParams { settings, .. }) => settings,
142 #[cfg(feature = "sigv4a")]
143 Self::V4a(v4a::SigningParams { settings, .. }) => settings,
144 }
145 }
146
147 pub fn settings_mut(&mut self) -> &mut SigningSettings {
149 match self {
150 Self::V4(v4::SigningParams { settings, .. }) => settings,
151 #[cfg(feature = "sigv4a")]
152 Self::V4a(v4a::SigningParams { settings, .. }) => settings,
153 }
154 }
155
156 #[cfg(test)]
157 pub fn set_payload_checksum_kind(&mut self, kind: PayloadChecksumKind) {
159 let settings = self.settings_mut();
160
161 settings.payload_checksum_kind = kind;
162 }
163
164 #[cfg(test)]
165 pub fn set_session_token_mode(&mut self, mode: SessionTokenMode) {
167 let settings = self.settings_mut();
168
169 settings.session_token_mode = mode;
170 }
171
172 pub fn time(&self) -> &SystemTime {
174 match self {
175 Self::V4(v4::SigningParams { time, .. }) => time,
176 #[cfg(feature = "sigv4a")]
177 Self::V4a(v4a::SigningParams { time, .. }) => time,
178 }
179 }
180
181 pub fn name(&self) -> &str {
183 match self {
184 Self::V4(v4::SigningParams { name, .. }) => name,
185 #[cfg(feature = "sigv4a")]
186 Self::V4a(v4a::SigningParams { name, .. }) => name,
187 }
188 }
189
190 pub fn algorithm(&self) -> &'static str {
192 match self {
193 Self::V4(params) => params.algorithm(),
194 #[cfg(feature = "sigv4a")]
195 Self::V4a(params) => params.algorithm(),
196 }
197 }
198
199 pub fn signature_version(&self) -> SignatureVersion {
201 match self {
202 Self::V4(..) => SignatureVersion::V4,
203 #[cfg(feature = "sigv4a")]
204 Self::V4a(..) => SignatureVersion::V4a,
205 }
206 }
207}