TencentCloud Sign SDK for Rust
A common signing library for TencentCloud APIs, providing the TC3-HMAC-SHA256 algorithm used across all TencentCloud services.
Features
- TC3-HMAC-SHA256 Algorithm: Complete implementation of TencentCloud's signing algorithm
- Cryptographic Utilities: SHA256 and HMAC-SHA256 functions
- Clean API: Easy-to-use interface for signing requests
- Debug Support: Optional debug logging for troubleshooting
- No Dependencies: Minimal dependencies for maximum compatibility
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Signing
use ;
use OffsetDateTime;
// Create a signer
let signer = new;
// Prepare request data
let method = "POST";
let canonical_uri = "/";
let canonical_querystring = "";
let canonical_headers = "content-type:application/json; charset=utf-8\nhost:example.com\n";
let signed_headers = "content-type;host";
let payload = r#"{"message":"hello"}"#;
let hashed_payload = sha256_hex;
let timestamp = now_utc.unix_timestamp;
// Sign the request
let result = signer.sign;
// Create Authorization header
let auth_header = signer.create_authorization_header;
Cryptographic Utilities
use ;
// SHA256 hashing
let hash = sha256_hex;
// HMAC-SHA256 signing
let key = b"secret_key";
let data = "message to sign";
let signature = hmac_sha256_hex;
API Reference
Tc3Signer
The main signer class for TC3-HMAC-SHA256 algorithm.
Methods
new(secret_id, secret_key, service, debug)- Create a new signersign(...)- Sign a request and return signature detailscreate_authorization_header(result, signed_headers)- Create Authorization headersecret_id()- Get the secret IDservice()- Get the service namedebug()- Check if debug mode is enabled
Cryptographic Functions
sha256_hex(data)- Compute SHA256 hash as hex stringhmac_sha256(key, data)- Compute HMAC-SHA256 as raw byteshmac_sha256_hex(key, data)- Compute HMAC-SHA256 as hex string
License
This project uses the license provided in LICENSE.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.