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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# reqsign-core
Core components for signing API requests.
---
This crate provides the foundational types and traits for the reqsign ecosystem. It defines the core abstractions that enable flexible and extensible request signing.
## Quick Start
```rust
use reqsign_core::{Context, Signer, ProvideCredential, SignRequest};
// Create a context with your implementations
let ctx = Context::default();
// Create a signer with credential loader and request builder
let signer = Signer::new(ctx, credential_loader, request_builder);
// Sign your requests
let mut parts = /* your request parts */;
signer.sign(&mut parts, None).await?;
```
## Features
- **Flexible Architecture**: Define your own credential types and signing logic
- **Async Support**: Built with async/await for modern Rust applications
- **Environment Integration**: Access environment variables through the Context
- **Type Safety**: Strong typing ensures compile-time correctness
## Core Concepts
### Context
The `Context` struct serves as a container for runtime dependencies:
- File system access via `FileRead` trait
- HTTP client via `HttpSend` trait
- Environment variables via `Env` trait
### Traits
- **`ProvideCredential`**: Load credentials from various sources
- **`SignRequest`**: Build service-specific signing requests
- **`SigningCredential`**: Validate credential validity
- **`FileRead`**: Async file reading operations
- **`HttpSend`**: HTTP request execution
- **`Env`**: Environment variable access
### Signer
The `Signer` orchestrates the signing process by:
1. Loading credentials using the provided loader
2. Building signing requests with the builder
3. Applying signatures to HTTP requests
## Examples
Check out the [custom_signer example](examples/custom_signer.rs) to see how to implement your own signing logic.
```bash
cargo run --example custom_signer
```
## Integration
This crate is typically used with service-specific implementations:
- `reqsign-aws-v4` for AWS services
- `reqsign-aliyun-oss` for Aliyun OSS
- `reqsign-azure-storage` for Azure Storage
- And more...
## License
Licensed under [Apache License, Version 2.0](./LICENSE).
|