@@ -174,9 +174,9 @@ impl CanonicalRequest {
174
174
mut body : Bytes ,
175
175
options : SignatureOptions ,
176
176
) -> Result < ( Self , Parts , Bytes ) , SignatureError > {
177
- let canonical_path = canonicalize_uri_path ( & parts. uri . path ( ) , options. s3 ) ?;
177
+ let canonical_path = canonicalize_uri_path ( parts. uri . path ( ) , options. s3 ) ?;
178
178
let content_type = get_content_type_and_charset ( & parts. headers ) ;
179
- let mut query_parameters = query_string_to_normalized_map ( & parts. uri . query ( ) . unwrap_or ( "" ) ) ?;
179
+ let mut query_parameters = query_string_to_normalized_map ( parts. uri . query ( ) . unwrap_or ( "" ) ) ?;
180
180
181
181
if options. url_encode_form {
182
182
// Treat requests with application/x-www-form-urlencoded bodies as if they were passed into the query string.
@@ -210,7 +210,7 @@ impl CanonicalRequest {
210
210
}
211
211
} ;
212
212
213
- query_parameters. extend ( query_string_to_normalized_map ( body_query. as_str ( ) ) ?. into_iter ( ) ) ;
213
+ query_parameters. extend ( query_string_to_normalized_map ( body_query. as_str ( ) ) ?) ;
214
214
// Rebuild the parts URI with the new query string.
215
215
let qs = canonicalize_query_to_string ( & query_parameters) ;
216
216
trace ! ( "Rebuilding URI with new query string: {}" , qs) ;
@@ -320,12 +320,12 @@ impl CanonicalRequest {
320
320
321
321
/// Get the SHA-256 hash of the [canonical request](https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html).
322
322
pub fn canonical_request_sha256 ( & self , signed_headers : & Vec < String > ) -> [ u8 ; SHA256_OUTPUT_LEN ] {
323
- let canonical_request = self . canonical_request ( & signed_headers) ;
323
+ let canonical_request = self . canonical_request ( signed_headers) ;
324
324
let result_digest = digest ( & SHA256 , canonical_request. as_ref ( ) ) ;
325
325
let result_slice = result_digest. as_ref ( ) ;
326
326
assert ! ( result_slice. len( ) == SHA256_OUTPUT_LEN ) ;
327
327
let mut result: [ u8 ; SHA256_OUTPUT_LEN ] = [ 0 ; SHA256_OUTPUT_LEN ] ;
328
- result. as_mut_slice ( ) . clone_from_slice ( & result_slice) ;
328
+ result. as_mut_slice ( ) . clone_from_slice ( result_slice) ;
329
329
result
330
330
}
331
331
@@ -497,7 +497,7 @@ impl CanonicalRequest {
497
497
}
498
498
499
499
let mut signed_headers = if let Some ( signed_headers) = parameter_map. get ( SIGNED_HEADERS ) {
500
- signed_headers. split ( |c| * c == b';' ) . map ( |s| latin1_to_string ( s ) ) . collect ( )
500
+ signed_headers. split ( |c| * c == b';' ) . map ( latin1_to_string) . collect ( )
501
501
} else {
502
502
missing_messages. push ( MSG_AUTH_HEADER_REQ_SIGNED_HEADERS ) ;
503
503
Vec :: new ( )
@@ -824,7 +824,7 @@ pub fn get_content_type_and_charset(headers: &HeaderMap<HeaderValue>) -> Option<
824
824
None => return None ,
825
825
} ;
826
826
827
- let mut parts = content_type_opts. split ( |c| * c == b';' ) . map ( |s| trim_ascii ( s ) ) ;
827
+ let mut parts = content_type_opts. split ( |c| * c == b';' ) . map ( trim_ascii) ;
828
828
let content_type = latin1_to_string ( parts. next ( ) . expect ( "split always returns at least one element" ) ) ;
829
829
830
830
for option in parts {
@@ -870,7 +870,7 @@ pub fn normalize_headers(headers: &HeaderMap<HeaderValue>) -> HashMap<String, Ve
870
870
for ( key, value) in headers. iter ( ) {
871
871
let key = key. as_str ( ) . to_lowercase ( ) ;
872
872
let value = normalize_header_value ( value. as_bytes ( ) ) ;
873
- result. entry ( key) . or_insert_with ( Vec :: new ) . push ( value) ;
873
+ result. entry ( key) . or_default ( ) . push ( value) ;
874
874
}
875
875
876
876
result
@@ -886,7 +886,7 @@ fn normalize_header_value(value: &[u8]) -> Vec<u8> {
886
886
for c in value {
887
887
if * c == b' ' {
888
888
if !last_was_space {
889
- result. push ( ' ' as u8 ) ;
889
+ result. push ( b ' ') ;
890
890
last_was_space = true ;
891
891
}
892
892
} else {
@@ -897,7 +897,7 @@ fn normalize_header_value(value: &[u8]) -> Vec<u8> {
897
897
898
898
if last_was_space {
899
899
// Remove trailing spaces.
900
- while result. last ( ) == Some ( & ( ' ' as u8 ) ) {
900
+ while result. last ( ) == Some ( & b ' ') {
901
901
result. pop ( ) ;
902
902
}
903
903
}
@@ -1100,8 +1100,8 @@ fn unescape_uri_encoding(s: &str) -> String {
1100
1100
while let Some ( c) = chars. next ( ) {
1101
1101
if c == b'%' {
1102
1102
let mut hex_digits = [ 0u8 ; 2 ] ;
1103
- hex_digits[ 0 ] = chars. next ( ) . expect ( MSG_INCOMPLETE_TRAILING_ESCAPE ) as u8 ;
1104
- hex_digits[ 1 ] = chars. next ( ) . expect ( MSG_INCOMPLETE_TRAILING_ESCAPE ) as u8 ;
1103
+ hex_digits[ 0 ] = chars. next ( ) . expect ( MSG_INCOMPLETE_TRAILING_ESCAPE ) ;
1104
+ hex_digits[ 1 ] = chars. next ( ) . expect ( MSG_INCOMPLETE_TRAILING_ESCAPE ) ;
1105
1105
match u8:: from_str_radix ( from_utf8 ( & hex_digits) . unwrap ( ) , 16 ) {
1106
1106
Ok ( c) => result. push ( c as char ) ,
1107
1107
Err ( _) => panic ! ( "{}{}{}" , MSG_ILLEGAL_HEX_CHAR , hex_digits[ 0 ] as char , hex_digits[ 1 ] as char ) ,
@@ -1132,7 +1132,7 @@ mod tests {
1132
1132
uri:: { PathAndQuery , Uri } ,
1133
1133
} ,
1134
1134
scratchstack_errors:: ServiceError ,
1135
- std:: { collections:: HashMap , mem :: transmute } ,
1135
+ std:: collections:: HashMap ,
1136
1136
} ;
1137
1137
1138
1138
macro_rules! expect_err {
@@ -1252,7 +1252,7 @@ mod tests {
1252
1252
assert_eq ! ( foo. len( ) , 1 ) ;
1253
1253
assert_eq ! ( foo[ 0 ] , "bar" ) ;
1254
1254
1255
- assert ! ( v . get ( "" ) . is_none ( ) ) ;
1255
+ assert ! ( !v . contains_key ( "" ) ) ;
1256
1256
}
1257
1257
1258
1258
#[ test_log:: test]
@@ -1273,22 +1273,23 @@ mod tests {
1273
1273
#[ test_log:: test]
1274
1274
fn normalize_invalid_hex_path_cr ( ) {
1275
1275
// The HTTP crate does its own validation; we need to hack into it to force invalid URI elements in there.
1276
- for ( path, error_message) in vec ! [
1276
+ for ( path, error_message) in [
1277
1277
( "/abcd%yy" , "Illegal hex character in escape % pattern: %yy" ) ,
1278
1278
( "/abcd%0" , "Incomplete trailing escape % sequence" ) ,
1279
1279
( "/abcd%" , "Incomplete trailing escape % sequence" ) ,
1280
1280
] {
1281
1281
let mut fake_path = "/" . to_string ( ) ;
1282
1282
while fake_path. len ( ) < path. len ( ) {
1283
- fake_path. push_str ( "a" ) ;
1283
+ fake_path. push ( 'a' ) ;
1284
1284
}
1285
1285
1286
1286
let mut pq = PathAndQuery :: from_maybe_shared ( fake_path. clone ( ) ) . unwrap ( ) ;
1287
1287
let pq_path = Bytes :: from_static ( path. as_bytes ( ) ) ;
1288
1288
1289
1289
unsafe {
1290
- // Rewrite the path to be invalid.
1291
- let pq_ptr: * mut PathAndQuerySimulate = transmute ( & mut pq) ;
1290
+ // Rewrite the path to be invalid. This can't be done with the normal PathAndQuery
1291
+ // API.
1292
+ let pq_ptr: * mut PathAndQuerySimulate = & mut pq as * mut PathAndQuery as * mut PathAndQuerySimulate ;
1292
1293
( * pq_ptr) . data = pq_path;
1293
1294
}
1294
1295
@@ -1313,22 +1314,22 @@ mod tests {
1313
1314
#[ test_log:: test]
1314
1315
fn normalize_invalid_hex_query_cr ( ) {
1315
1316
// The HTTP crate does its own validation; we need to hack into it to force invalid URI elements in there.
1316
- for ( path, error_message) in vec ! [
1317
+ for ( path, error_message) in [
1317
1318
( "/?x=abcd%yy" , "Illegal hex character in escape % pattern: %yy" ) ,
1318
1319
( "/?x=abcd%0" , "Incomplete trailing escape % sequence" ) ,
1319
1320
( "/?x=abcd%" , "Incomplete trailing escape % sequence" ) ,
1320
1321
] {
1321
1322
let mut fake_path = "/?x=" . to_string ( ) ;
1322
1323
while fake_path. len ( ) < path. len ( ) {
1323
- fake_path. push_str ( "a" ) ;
1324
+ fake_path. push ( 'a' ) ;
1324
1325
}
1325
1326
1326
1327
let mut pq = PathAndQuery :: from_maybe_shared ( fake_path. clone ( ) ) . unwrap ( ) ;
1327
1328
let pq_path = Bytes :: from_static ( path. as_bytes ( ) ) ;
1328
1329
1329
1330
unsafe {
1330
1331
// Rewrite the path to be invalid.
1331
- let pq_ptr: * mut PathAndQuerySimulate = transmute ( & mut pq) ;
1332
+ let pq_ptr: * mut PathAndQuerySimulate = & mut pq as * mut PathAndQuery as * mut PathAndQuerySimulate ;
1332
1333
( * pq_ptr) . data = pq_path;
1333
1334
}
1334
1335
@@ -1487,7 +1488,7 @@ mod tests {
1487
1488
let ( parts, body) = request. into_parts ( ) ;
1488
1489
1489
1490
let ( cr, _, _) = CanonicalRequest :: from_request_parts ( parts, body, SignatureOptions :: default ( ) ) . unwrap ( ) ;
1490
- assert ! ( cr. query_parameters. get ( "foo" ) . is_none ( ) ) ;
1491
+ assert ! ( ! cr. query_parameters. contains_key ( "foo" ) ) ;
1491
1492
}
1492
1493
1493
1494
#[ test_log:: test]
0 commit comments