1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! This module provides a function to create a Last.fm API method signature.
use BTreeMap;
/// Generates a Last.fm API method signature.
///
/// According to the [Last.fm API authentication spec](https://www.last.fm/api/authspec#_8-signing-calls),
/// a method signature is an MD5 hash of a string constructed as follows:
///
/// 1. Take all API call parameters (except `format` and `callback`).
/// 2. Order them alphabetically by parameter name.
/// 3. Concatenate each parameter's name and value into a single string (e.g., `keyvalue`).
/// 4. Concatenate all these `keyvalue` strings into one long string.
/// 5. Append your API secret to the end of this long string.
/// 6. The final signature is the MD5 hash of this string.
///
/// This function expects `params` to be a `BTreeMap`, which automatically handles
/// the alphabetical ordering of parameters (step 2). The caller is responsible for
/// ensuring `params` contains all required parameters for the signature (e.g., `api_key`)
/// and excludes any that should not be signed (like `format` or `callback`).
///
/// # Arguments
///
/// * `params` - A map of API method parameters, sorted alphabetically by key.
/// * `api_secret` - Your Last.fm API secret.
///
/// # Returns
///
/// A string containing the 32-character lowercase hex-encoded MD5 signature.