LINE Bot SDK Utils
Utility functions for the LINE Bot SDK for Rust, including webhook signature validation.
Features
- Webhook Signature Validation: Validate LINE webhook request signatures using HMAC-SHA256
- Constant-time Comparison: Prevents timing attacks during signature verification
Installation
Add this package to your Cargo.toml:
[]
= { = "../packages/line-bot-sdk-utils" }
Usage
Signature Validation
Validate webhook signatures to ensure requests are from LINE servers:
use validate_signature;
// Get the raw request body and signature header
let body = /* raw request body as bytes */;
let channel_secret = var?;
let signature = /* X-Line-Signature header value */;
match validate_signature
Example with Axum
use ;
use validate_signature;
async
API Reference
validate_signature
Validates a LINE webhook signature.
Signature:
Parameters:
body: The raw request body as byteschannel_secret: Your channel secret from LINE Developers consolesignature: The signature from theX-Line-Signatureheader (base64 encoded)
Returns:
Ok(true)if the signature is validOk(false)if the signature is invalidErr(SignatureValidationError)if signature decoding fails
How It Works
The signature validation follows LINE's specification:
- Compute HMAC-SHA256 hash of the request body using the channel secret as the key
- Base64 encode the hash
- Compare the computed signature with the provided signature using constant-time comparison
This ensures that only requests from LINE servers are processed, preventing unauthorized access to your webhook endpoint.
License
Unlicense