init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
2430
Cargo.lock
generated
Normal file
2430
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "blackwriter-server"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
argon2 = "0.5.3"
|
||||||
|
axum = "0.8.7"
|
||||||
|
dashmap = "6.1.0"
|
||||||
|
jsonwebtoken = "10.2.0"
|
||||||
|
mediasoup = "0.20.0"
|
||||||
|
rand = "0.9.2"
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
tokio = { version = "1.48.0", features = ["full"] }
|
||||||
|
tokio-tungstenite = "0.28.0"
|
||||||
|
uuid = "1.19.0"
|
||||||
473
doc/argon2.md
Normal file
473
doc/argon2.md
Normal file
@ -0,0 +1,473 @@
|
|||||||
|
# Crate Documentation
|
||||||
|
|
||||||
|
**Version:** 0.5.3
|
||||||
|
|
||||||
|
**Format Version:** 56
|
||||||
|
|
||||||
|
# Module `argon2`
|
||||||
|
|
||||||
|
# RustCrypto: Argon2
|
||||||
|
|
||||||
|
[![crate][crate-image]][crate-link]
|
||||||
|
[![Docs][docs-image]][docs-link]
|
||||||
|
[![Build Status][build-image]][build-link]
|
||||||
|
![Apache2/MIT licensed][license-image]
|
||||||
|
![Rust Version][rustc-image]
|
||||||
|
[![Project Chat][chat-image]][chat-link]
|
||||||
|
|
||||||
|
Pure Rust implementation of the [Argon2] password hashing function.
|
||||||
|
|
||||||
|
[Documentation][docs-link]
|
||||||
|
|
||||||
|
# About
|
||||||
|
|
||||||
|
Argon2 is a memory-hard [key derivation function] chosen as the winner of
|
||||||
|
the [Password Hashing Competition] in July 2015.
|
||||||
|
|
||||||
|
It implements the following three algorithmic variants:
|
||||||
|
|
||||||
|
- **Argon2d**: maximizes resistance to GPU cracking attacks
|
||||||
|
- **Argon2i**: optimized to resist side-channel attacks
|
||||||
|
- **Argon2id**: (default) hybrid version combining both Argon2i and Argon2d
|
||||||
|
|
||||||
|
Support is provided for embedded (i.e. `no_std`) environments, including
|
||||||
|
ones without `alloc` support.
|
||||||
|
|
||||||
|
## Minimum Supported Rust Version
|
||||||
|
|
||||||
|
Rust **1.65** or higher.
|
||||||
|
|
||||||
|
Minimum supported Rust version can be changed in the future, but it will be
|
||||||
|
done with a minor version bump.
|
||||||
|
|
||||||
|
## SemVer Policy
|
||||||
|
|
||||||
|
- All on-by-default features of this library are covered by SemVer
|
||||||
|
- MSRV is considered exempt from SemVer as noted above
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Licensed under either of:
|
||||||
|
|
||||||
|
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
* [MIT license](http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
at your option.
|
||||||
|
|
||||||
|
### Contribution
|
||||||
|
|
||||||
|
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||||
|
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
|
||||||
|
dual licensed as above, without any additional terms or conditions.
|
||||||
|
|
||||||
|
[//]: # (badges)
|
||||||
|
|
||||||
|
[crate-image]: https://buildstats.info/crate/argon2
|
||||||
|
[crate-link]: https://crates.io/crates/argon2
|
||||||
|
[docs-image]: https://docs.rs/argon2/badge.svg
|
||||||
|
[docs-link]: https://docs.rs/argon2/
|
||||||
|
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
|
||||||
|
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
|
||||||
|
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
|
||||||
|
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260046-password-hashes
|
||||||
|
[build-image]: https://github.com/RustCrypto/password-hashes/workflows/argon2/badge.svg?branch=master&event=push
|
||||||
|
[build-link]: https://github.com/RustCrypto/password-hashes/actions?query=workflow%3Aargon2
|
||||||
|
|
||||||
|
[//]: # (general links)
|
||||||
|
|
||||||
|
[Argon2]: https://en.wikipedia.org/wiki/Argon2
|
||||||
|
[key derivation function]: https://en.wikipedia.org/wiki/Key_derivation_function
|
||||||
|
[Password Hashing Competition]: https://www.password-hashing.net/
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Password Hashing
|
||||||
|
|
||||||
|
This API hashes a password to a "PHC string" suitable for the purposes of
|
||||||
|
password-based authentication. Do not use this API to derive cryptographic
|
||||||
|
keys: see the "key derivation" usage example below.
|
||||||
|
|
||||||
|
```
|
||||||
|
# fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
use argon2::{
|
||||||
|
password_hash::{
|
||||||
|
rand_core::OsRng,
|
||||||
|
PasswordHash, PasswordHasher, PasswordVerifier, SaltString
|
||||||
|
},
|
||||||
|
Argon2
|
||||||
|
};
|
||||||
|
|
||||||
|
let password = b"hunter42"; // Bad password; don't actually use!
|
||||||
|
let salt = SaltString::generate(&mut OsRng);
|
||||||
|
|
||||||
|
// Argon2 with default params (Argon2id v19)
|
||||||
|
let argon2 = Argon2::default();
|
||||||
|
|
||||||
|
// Hash password to PHC string ($argon2id$v=19$...)
|
||||||
|
let password_hash = argon2.hash_password(password, &salt)?.to_string();
|
||||||
|
|
||||||
|
// Verify password against PHC string.
|
||||||
|
//
|
||||||
|
// NOTE: hash params from `parsed_hash` are used instead of what is configured in the
|
||||||
|
// `Argon2` instance.
|
||||||
|
let parsed_hash = PasswordHash::new(&password_hash)?;
|
||||||
|
assert!(Argon2::default().verify_password(password, &parsed_hash).is_ok());
|
||||||
|
# Ok(())
|
||||||
|
# }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key Derivation
|
||||||
|
|
||||||
|
This API is useful for transforming a password into cryptographic keys for
|
||||||
|
e.g. password-based encryption.
|
||||||
|
|
||||||
|
```
|
||||||
|
# fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
use argon2::Argon2;
|
||||||
|
|
||||||
|
let password = b"hunter42"; // Bad password; don't actually use!
|
||||||
|
let salt = b"example salt"; // Salt should be unique per password
|
||||||
|
|
||||||
|
let mut output_key_material = [0u8; 32]; // Can be any desired size
|
||||||
|
Argon2::default().hash_password_into(password, salt, &mut output_key_material)?;
|
||||||
|
# Ok(())
|
||||||
|
# }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
### Struct `Argon2`
|
||||||
|
|
||||||
|
Argon2 context.
|
||||||
|
|
||||||
|
This is the primary type of this crate's API, and contains the following:
|
||||||
|
|
||||||
|
- Argon2 [`Algorithm`] variant to be used
|
||||||
|
- Argon2 [`Version`] to be used
|
||||||
|
- Default set of [`Params`] to be used
|
||||||
|
- (Optional) Secret key a.k.a. "pepper" to be used
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub struct Argon2<''key> {
|
||||||
|
// Some fields omitted
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Fields
|
||||||
|
|
||||||
|
| Name | Type | Documentation |
|
||||||
|
|------|------|---------------|
|
||||||
|
| *private fields* | ... | *Some fields have been omitted* |
|
||||||
|
|
||||||
|
#### Implementations
|
||||||
|
|
||||||
|
##### Methods
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn new(algorithm: Algorithm, version: Version, params: Params) -> Self { /* ... */ }
|
||||||
|
```
|
||||||
|
Create a new Argon2 context.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn new_with_secret(secret: &''key [u8], algorithm: Algorithm, version: Version, params: Params) -> Result<Self> { /* ... */ }
|
||||||
|
```
|
||||||
|
Create a new Argon2 context.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn hash_password_into(self: &Self, pwd: &[u8], salt: &[u8], out: &mut [u8]) -> Result<()> { /* ... */ }
|
||||||
|
```
|
||||||
|
Hash a password and associated parameters into the provided output buffer.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn hash_password_into_with_memory</* synthetic */ impl AsMut<[Block]>: AsMut<[Block]>>(self: &Self, pwd: &[u8], salt: &[u8], out: &mut [u8], memory_blocks: impl AsMut<[Block]>) -> Result<()> { /* ... */ }
|
||||||
|
```
|
||||||
|
Hash a password and associated parameters into the provided output buffer.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn fill_memory</* synthetic */ impl AsMut<[Block]>: AsMut<[Block]>>(self: &Self, pwd: &[u8], salt: &[u8], memory_blocks: impl AsMut<[Block]>) -> Result<()> { /* ... */ }
|
||||||
|
```
|
||||||
|
Use a password and associated parameters only to fill the given memory blocks.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub const fn params(self: &Self) -> &Params { /* ... */ }
|
||||||
|
```
|
||||||
|
Get default configured [`Params`].
|
||||||
|
|
||||||
|
##### Trait Implementations
|
||||||
|
|
||||||
|
- **Any**
|
||||||
|
- ```rust
|
||||||
|
fn type_id(self: &Self) -> TypeId { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Borrow**
|
||||||
|
- ```rust
|
||||||
|
fn borrow(self: &Self) -> &T { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **BorrowMut**
|
||||||
|
- ```rust
|
||||||
|
fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Clone**
|
||||||
|
- ```rust
|
||||||
|
fn clone(self: &Self) -> Argon2<''key> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **CloneToUninit**
|
||||||
|
- ```rust
|
||||||
|
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8) { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Debug**
|
||||||
|
- ```rust
|
||||||
|
fn fmt(self: &Self, fmt: &mut fmt::Formatter<''_>) -> fmt::Result { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Default**
|
||||||
|
- ```rust
|
||||||
|
fn default() -> Self { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Freeze**
|
||||||
|
- **From**
|
||||||
|
- ```rust
|
||||||
|
fn from(t: T) -> T { /* ... */ }
|
||||||
|
```
|
||||||
|
Returns the argument unchanged.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn from(params: Params) -> Self { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn from(params: &Params) -> Self { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Into**
|
||||||
|
- ```rust
|
||||||
|
fn into(self: Self) -> U { /* ... */ }
|
||||||
|
```
|
||||||
|
Calls `U::from(self)`.
|
||||||
|
|
||||||
|
- **PasswordHasher**
|
||||||
|
- ```rust
|
||||||
|
fn hash_password<''a, /* synthetic */ impl Into<Salt<'a>>: Into<Salt<''a>>>(self: &Self, password: &[u8], salt: impl Into<Salt<''a>>) -> password_hash::Result<PasswordHash<''a>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn hash_password_customized<''a, /* synthetic */ impl Into<Salt<'a>>: Into<Salt<''a>>>(self: &Self, password: &[u8], alg_id: Option<Ident<''a>>, version: Option<Decimal>, params: Params, salt: impl Into<Salt<''a>>) -> password_hash::Result<PasswordHash<''a>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **PasswordVerifier**
|
||||||
|
- ```rust
|
||||||
|
fn verify_password(self: &Self, password: &[u8], hash: &PasswordHash<''_>) -> Result<(), Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **RefUnwindSafe**
|
||||||
|
- **Same**
|
||||||
|
- **Send**
|
||||||
|
- **Sync**
|
||||||
|
- **ToOwned**
|
||||||
|
- ```rust
|
||||||
|
fn to_owned(self: &Self) -> T { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn clone_into(self: &Self, target: &mut T) { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **TryFrom**
|
||||||
|
- ```rust
|
||||||
|
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **TryInto**
|
||||||
|
- ```rust
|
||||||
|
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Unpin**
|
||||||
|
- **UnwindSafe**
|
||||||
|
## Constants and Statics
|
||||||
|
|
||||||
|
### Constant `MAX_PWD_LEN`
|
||||||
|
|
||||||
|
Maximum password length in bytes.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const MAX_PWD_LEN: usize = 0xFFFFFFFF;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constant `MIN_SALT_LEN`
|
||||||
|
|
||||||
|
Minimum salt length in bytes.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const MIN_SALT_LEN: usize = 8;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constant `MAX_SALT_LEN`
|
||||||
|
|
||||||
|
Maximum salt length in bytes.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const MAX_SALT_LEN: usize = 0xFFFFFFFF;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constant `RECOMMENDED_SALT_LEN`
|
||||||
|
|
||||||
|
Recommended salt length for password hashing in bytes.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const RECOMMENDED_SALT_LEN: usize = 16;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constant `MAX_SECRET_LEN`
|
||||||
|
|
||||||
|
Maximum secret key length in bytes.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub const MAX_SECRET_LEN: usize = 0xFFFFFFFF;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Re-exports
|
||||||
|
|
||||||
|
### Re-export `Algorithm`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::algorithm::Algorithm;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Block`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::block::Block;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Error`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::error::Error;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Result`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::error::Result;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `AssociatedData`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::params::AssociatedData;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `KeyId`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::params::KeyId;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Params`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::params::Params;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `ParamsBuilder`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::params::ParamsBuilder;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Version`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::version::Version;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `ARGON2D_IDENT`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::algorithm::ARGON2D_IDENT;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `ARGON2ID_IDENT`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::algorithm::ARGON2ID_IDENT;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `ARGON2I_IDENT`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use crate::algorithm::ARGON2I_IDENT;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `password_hash`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use password_hash;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `PasswordHash`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use password_hash::PasswordHash;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `PasswordHasher`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use password_hash::PasswordHasher;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `PasswordVerifier`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg_trace>(feature = \"password-hash\")]")`
|
||||||
|
- `Other("#[<cfg_attr_trace>(docsrs, doc(cfg(feature = \"password-hash\")))]")`
|
||||||
|
- `Other("#[doc(cfg(feature = \"password-hash\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use password_hash::PasswordVerifier;
|
||||||
|
```
|
||||||
|
|
||||||
15350
doc/axum.md
Normal file
15350
doc/axum.md
Normal file
File diff suppressed because it is too large
Load Diff
3318
doc/dashmap.md
Normal file
3318
doc/dashmap.md
Normal file
File diff suppressed because it is too large
Load Diff
3074
doc/jsonwebtoken.md
Normal file
3074
doc/jsonwebtoken.md
Normal file
File diff suppressed because it is too large
Load Diff
4203
doc/mediasoup.md
Normal file
4203
doc/mediasoup.md
Normal file
File diff suppressed because it is too large
Load Diff
2683
doc/rand.md
Normal file
2683
doc/rand.md
Normal file
File diff suppressed because it is too large
Load Diff
11869
doc/serde.md
Normal file
11869
doc/serde.md
Normal file
File diff suppressed because it is too large
Load Diff
5643
doc/serde_json.md
Normal file
5643
doc/serde_json.md
Normal file
File diff suppressed because it is too large
Load Diff
381
doc/tokio-tungstenite.md
Normal file
381
doc/tokio-tungstenite.md
Normal file
@ -0,0 +1,381 @@
|
|||||||
|
# Crate Documentation
|
||||||
|
|
||||||
|
**Version:** 0.28.0
|
||||||
|
|
||||||
|
**Format Version:** 56
|
||||||
|
|
||||||
|
# Module `tokio_tungstenite`
|
||||||
|
|
||||||
|
Async WebSocket usage.
|
||||||
|
|
||||||
|
This library is an implementation of WebSocket handshakes and streams. It
|
||||||
|
is based on the crate which implements all required WebSocket protocol
|
||||||
|
logic. So this crate basically just brings tokio support / tokio integration
|
||||||
|
to it.
|
||||||
|
|
||||||
|
Each WebSocket stream implements the required `Stream` and `Sink` traits,
|
||||||
|
so the socket is just a stream of messages coming in and going out.
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
### Struct `WebSocketStream`
|
||||||
|
|
||||||
|
A wrapper around an underlying raw stream which implements the WebSocket
|
||||||
|
protocol.
|
||||||
|
|
||||||
|
A `WebSocketStream<S>` represents a handshake that has been completed
|
||||||
|
successfully and both the server and the client are ready for receiving
|
||||||
|
and sending data. Message from a `WebSocketStream<S>` are accessible
|
||||||
|
through the respective `Stream` and `Sink`. Check more information about
|
||||||
|
them in `futures-rs` crate documentation or have a look on the examples
|
||||||
|
and unit tests for this crate.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub struct WebSocketStream<S> {
|
||||||
|
// Some fields omitted
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Fields
|
||||||
|
|
||||||
|
| Name | Type | Documentation |
|
||||||
|
|------|------|---------------|
|
||||||
|
| *private fields* | ... | *Some fields have been omitted* |
|
||||||
|
|
||||||
|
#### Implementations
|
||||||
|
|
||||||
|
##### Methods
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub async fn from_raw_socket(stream: S, role: Role, config: Option<WebSocketConfig>) -> Self
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
Convert a raw socket into a WebSocketStream without performing a
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub async fn from_partially_read(stream: S, part: Vec<u8>, role: Role, config: Option<WebSocketConfig>) -> Self
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
Convert a raw socket into a WebSocketStream without performing a
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn into_inner(self: Self) -> S { /* ... */ }
|
||||||
|
```
|
||||||
|
Consumes the `WebSocketStream` and returns the underlying stream.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn get_ref(self: &Self) -> &S
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
Returns a shared reference to the inner stream.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn get_mut(self: &mut Self) -> &mut S
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
Returns a mutable reference to the inner stream.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub fn get_config(self: &Self) -> &WebSocketConfig { /* ... */ }
|
||||||
|
```
|
||||||
|
Returns a reference to the configuration of the tungstenite stream.
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
pub async fn close(self: &mut Self, msg: Option<CloseFrame>) -> Result<(), WsError>
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
Close the underlying web socket
|
||||||
|
|
||||||
|
##### Trait Implementations
|
||||||
|
|
||||||
|
- **Any**
|
||||||
|
- ```rust
|
||||||
|
fn type_id(self: &Self) -> TypeId { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Borrow**
|
||||||
|
- ```rust
|
||||||
|
fn borrow(self: &Self) -> &T { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **BorrowMut**
|
||||||
|
- ```rust
|
||||||
|
fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Debug**
|
||||||
|
- ```rust
|
||||||
|
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<''_>) -> $crate::fmt::Result { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **ErasedDestructor**
|
||||||
|
- **Freeze**
|
||||||
|
- **From**
|
||||||
|
- ```rust
|
||||||
|
fn from(t: T) -> T { /* ... */ }
|
||||||
|
```
|
||||||
|
Returns the argument unchanged.
|
||||||
|
|
||||||
|
- **FusedStream**
|
||||||
|
- ```rust
|
||||||
|
fn is_terminated(self: &Self) -> bool { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Into**
|
||||||
|
- ```rust
|
||||||
|
fn into(self: Self) -> U { /* ... */ }
|
||||||
|
```
|
||||||
|
Calls `U::from(self)`.
|
||||||
|
|
||||||
|
- **RefUnwindSafe**
|
||||||
|
- **Same**
|
||||||
|
- **Send**
|
||||||
|
- **Sink**
|
||||||
|
- ```rust
|
||||||
|
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<''_>) -> Poll<Result<(), <Self as >::Error>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), <Self as >::Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<''_>) -> Poll<Result<(), <Self as >::Error>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- ```rust
|
||||||
|
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<''_>) -> Poll<Result<(), <Self as >::Error>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **SinkExt**
|
||||||
|
- **Stream**
|
||||||
|
- ```rust
|
||||||
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<''_>) -> Poll<Option<<Self as >::Item>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **StreamExt**
|
||||||
|
- **Sync**
|
||||||
|
- **TryFrom**
|
||||||
|
- ```rust
|
||||||
|
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **TryInto**
|
||||||
|
- ```rust
|
||||||
|
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **TryStream**
|
||||||
|
- ```rust
|
||||||
|
fn try_poll_next(self: Pin<&mut S>, cx: &mut Context<''_>) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>> { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
- **TryStreamExt**
|
||||||
|
- **Unpin**
|
||||||
|
- **UnwindSafe**
|
||||||
|
- **VZip**
|
||||||
|
- ```rust
|
||||||
|
fn vzip(self: Self) -> V { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
### Function `client_async`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
Creates a WebSocket handshake from a request and a stream.
|
||||||
|
For convenience, the user may call this with a url string, a URL,
|
||||||
|
or a `Request`. Calling with `Request` allows the user to add
|
||||||
|
a WebSocket protocol or other custom headers.
|
||||||
|
|
||||||
|
Internally, this custom creates a handshake representation and returns
|
||||||
|
a future representing the resolution of the WebSocket handshake. The
|
||||||
|
returned future will resolve to either `WebSocketStream<S>` or `Error`
|
||||||
|
depending on whether the handshake is successful.
|
||||||
|
|
||||||
|
This is typically used for clients who have already established, for
|
||||||
|
example, a TCP connection to the remote server.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn client_async<''a, R, S>(request: R, stream: S) -> Result<(WebSocketStream<S>, tungstenite::handshake::client::Response), tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
R: IntoClientRequest + Unpin,
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function `client_async_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
The same as `client_async()` but the one can specify a websocket configuration.
|
||||||
|
Please refer to `client_async()` for more details.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn client_async_with_config<''a, R, S>(request: R, stream: S, config: Option<tungstenite::protocol::WebSocketConfig>) -> Result<(WebSocketStream<S>, tungstenite::handshake::client::Response), tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
R: IntoClientRequest + Unpin,
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function `accept_async`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
Accepts a new WebSocket connection with the provided stream.
|
||||||
|
|
||||||
|
This function will internally call `server::accept` to create a
|
||||||
|
handshake representation and returns a future representing the
|
||||||
|
resolution of the WebSocket handshake. The returned future will resolve
|
||||||
|
to either `WebSocketStream<S>` or `Error` depending if it's successful
|
||||||
|
or not.
|
||||||
|
|
||||||
|
This is typically used after a socket has been accepted from a
|
||||||
|
`TcpListener`. That socket is then passed to this function to perform
|
||||||
|
the server half of the accepting a client's websocket connection.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn accept_async<S>(stream: S) -> Result<WebSocketStream<S>, tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function `accept_async_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
The same as `accept_async()` but the one can specify a websocket configuration.
|
||||||
|
Please refer to `accept_async()` for more details.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn accept_async_with_config<S>(stream: S, config: Option<tungstenite::protocol::WebSocketConfig>) -> Result<WebSocketStream<S>, tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function `accept_hdr_async`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
Accepts a new WebSocket connection with the provided stream.
|
||||||
|
|
||||||
|
This function does the same as `accept_async()` but accepts an extra callback
|
||||||
|
for header processing. The callback receives headers of the incoming
|
||||||
|
requests and is able to add extra headers to the reply.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn accept_hdr_async<S, C>(stream: S, callback: C) -> Result<WebSocketStream<S>, tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin,
|
||||||
|
C: Callback + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function `accept_hdr_async_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"handshake\")]")`
|
||||||
|
|
||||||
|
The same as `accept_hdr_async()` but the one can specify a websocket configuration.
|
||||||
|
Please refer to `accept_hdr_async()` for more details.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub async fn accept_hdr_async_with_config<S, C>(stream: S, callback: C, config: Option<tungstenite::protocol::WebSocketConfig>) -> Result<WebSocketStream<S>, tungstenite::error::Error>
|
||||||
|
where
|
||||||
|
S: AsyncRead + AsyncWrite + Unpin,
|
||||||
|
C: Callback + Unpin { /* ... */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
## Re-exports
|
||||||
|
|
||||||
|
### Re-export `tungstenite`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use tungstenite;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `Connector`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(any(feature = \"native-tls\", feature = \"__rustls-tls\", feature =\n\"connect\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use tls::Connector;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `client_async_tls`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(any(feature = \"native-tls\", feature = \"__rustls-tls\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use tls::client_async_tls;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `client_async_tls_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(any(feature = \"native-tls\", feature = \"__rustls-tls\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use tls::client_async_tls_with_config;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `connect_async`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"connect\")]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use connect::connect_async;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `connect_async_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"connect\")]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use connect::connect_async_with_config;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `connect_async_tls_with_config`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(all(any(feature = \"native-tls\", feature = \"__rustls-tls\"), feature =\n\"connect\"))]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use connect::connect_async_tls_with_config;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Re-export `MaybeTlsStream`
|
||||||
|
|
||||||
|
**Attributes:**
|
||||||
|
|
||||||
|
- `Other("#[<cfg>(feature = \"stream\")]")`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
pub use stream::MaybeTlsStream;
|
||||||
|
```
|
||||||
|
|
||||||
14681
doc/tokio.md
Normal file
14681
doc/tokio.md
Normal file
File diff suppressed because it is too large
Load Diff
2558
doc/uuid.md
Normal file
2558
doc/uuid.md
Normal file
File diff suppressed because it is too large
Load Diff
3
src/main.rs
Normal file
3
src/main.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user