https://github.com/littledivy/webcrypto
[WIP] WebCrypto API implementation in pure Rust
https://github.com/littledivy/webcrypto
crypto hacktoberfest rust webcrypto
Last synced: about 1 year ago
JSON representation
[WIP] WebCrypto API implementation in pure Rust
- Host: GitHub
- URL: https://github.com/littledivy/webcrypto
- Owner: littledivy
- Created: 2021-09-28T16:46:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-30T11:44:44.000Z (over 4 years ago)
- Last Synced: 2025-05-12T19:14:23.356Z (about 1 year ago)
- Topics: crypto, hacktoberfest, rust, webcrypto
- Language: Rust
- Homepage:
- Size: 13.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## [wip] webcrypto
Implementation of the [Web Cryptography specification](https://w3c.github.io/webcrypto) in Rust.
This crate hopes to ease interoperability between WASM and native targets.
If you are a browser or just a random person whose in a looking-to-port-JS-code-but-don't-know-how-to-do-that-with-existing-crates-in-the-Rust-ecosystem situation? This crate is for you.
### Usage
Unlike WebCrypto, the crate gives you the resposibility of
storing raw keying material. This is wrapped in the opaque
`KeyMaterial` wrapper type to avoid leakages through bad API usage or backtrace.
You should carefully choose how you store the `KeyMaterial` depending
on your use case.
```rust
/// A simple KeyMaterial storage impl
pub struct InMemoryVault(Vec);
impl KeyStorage for InMemoryVault {
/// This will be the _hidden_ handle to a `CryptoKey`
/// In future, this will be required to be serde
/// serializable.
type Handle = usize;
/// Put opaque key material into your backend and return
/// a handle.
fn store(&mut self, key: KeyMaterial) -> usize {
self.0.push(key);
self.0.len() - 1
}
/// Get opaque key material
fn get(&self, handle: usize) -> Option<&KeyMaterial> {
self.0.get(handle)
}
}
```