tencentcloud-sign-sdk

Crates.iotencentcloud-sign-sdk
lib.rstencentcloud-sign-sdk
version0.1.0
created_at2025-09-14 06:38:29.607343+00
updated_at2025-09-14 06:38:29.607343+00
descriptionTencentCloud Sign SDK for Rust - Common signing utilities for TencentCloud APIs
homepagehttps://github.com/y-zion/tencentcloud-sign-sdk-rust
repositoryhttps://github.com/y-zion/tencentcloud-sign-sdk-rust
max_upload_size
id1838388
size36,476
(yzion-opensource)

documentation

https://docs.rs/tencentcloud-sign-sdk

README

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:

[dependencies]
tencentcloud-sign-sdk = "0.1.0"

Usage

Basic Signing

use tencentcloud_sign_sdk::{Tc3Signer, sha256_hex};
use time::OffsetDateTime;

// Create a signer
let signer = Tc3Signer::new(
    "your_secret_id".to_string(),
    "your_secret_key".to_string(),
    "hunyuan".to_string(), // service name
    false, // debug mode
);

// 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(payload);
let timestamp = OffsetDateTime::now_utc().unix_timestamp();

// Sign the request
let result = signer.sign(
    method,
    canonical_uri,
    canonical_querystring,
    canonical_headers,
    signed_headers,
    &hashed_payload,
    timestamp,
);

// Create Authorization header
let auth_header = signer.create_authorization_header(&result, signed_headers);

Cryptographic Utilities

use tencentcloud_sign_sdk::{sha256_hex, hmac_sha256_hex};

// SHA256 hashing
let hash = sha256_hex("hello world");

// HMAC-SHA256 signing
let key = b"secret_key";
let data = "message to sign";
let signature = hmac_sha256_hex(key, data);

API Reference

Tc3Signer

The main signer class for TC3-HMAC-SHA256 algorithm.

Methods

  • new(secret_id, secret_key, service, debug) - Create a new signer
  • sign(...) - Sign a request and return signature details
  • create_authorization_header(result, signed_headers) - Create Authorization header
  • secret_id() - Get the secret ID
  • service() - Get the service name
  • debug() - Check if debug mode is enabled

Cryptographic Functions

  • sha256_hex(data) - Compute SHA256 hash as hex string
  • hmac_sha256(key, data) - Compute HMAC-SHA256 as raw bytes
  • hmac_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.

Commit count: 6

cargo fmt