Skip to content

Commit f5ab03b

Browse files
authored
Add readmes to all crates (#200)
In an effort to improve documentation for our public crates this PR adds relevant boilerplate readmes to every crate and moves the disclaimer to the workspace. Uses `readme = "DISCLAIMER.md"` to configure which readme is shown on crates.io. This allows us to use `README.md` for internal documentation. The READMEs are also included in rustdoc in an effort to avoid duplicating documentation.
1 parent ae3c08d commit f5ab03b

File tree

45 files changed

+145
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+145
-104
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rust-version = "1.75"
1313
homepage = "https://bitwarden.com"
1414
repository = "https://github.com/bitwarden/sdk-internal"
1515
license-file = "LICENSE"
16+
readme = "DISCLAIMER.md"
1617
keywords = ["bitwarden"]
1718

1819
# Define dependencies that are expected to be consistent across all crates

DISCLAIMER.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is an internal crate for the Bitwarden SDK. Do not depend on this directly and use the
2+
[`bitwarden`](https://crates.io/crates/bitwarden) crate instead.
3+
4+
This crate does not follow semantic versioning and the public interface may change at any time.

crates/bitwarden-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version.workspace = true
88
authors.workspace = true
99
edition.workspace = true
1010
rust-version.workspace = true
11+
readme.workspace = true
1112
homepage.workspace = true
1213
repository.workspace = true
1314
license-file.workspace = true

crates/bitwarden-cli/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# Bitwarden Cli
22

3-
This is an internal crate for the Bitwarden SDK do not depend on this directly and use the
4-
[`bitwarden`](https://crates.io/crates/bitwarden) crate instead.
5-
6-
This crate does not follow semantic versioning and the public interface may change at any time.
3+
Common utilities for the Bitwarden Password Manager CLI and Secrets Manager CLI.

crates/bitwarden-cli/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![doc = include_str!("../README.md")]
2+
13
mod color;
24

35
pub use color::{install_color_eyre, Color};

crates/bitwarden-core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ name = "bitwarden-core"
33
description = """
44
Internal crate for the bitwarden crate. Do not use.
55
"""
6-
keywords = ["bitwarden"]
76

87
version.workspace = true
98
authors.workspace = true
109
edition.workspace = true
1110
rust-version.workspace = true
11+
readme.workspace = true
1212
homepage.workspace = true
1313
repository.workspace = true
1414
license-file.workspace = true
15+
keywords.workspace = true
1516

1617
[features]
1718
internal = ["dep:zxcvbn"]

crates/bitwarden-core/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Bitwarden Core
22

3-
This is an internal crate for the Bitwarden SDK do not depend on this directly and use the
4-
[`bitwarden`](https://crates.io/crates/bitwarden) crate instead.
3+
Contains core functionality used by the feature crates.
54

6-
This crate does not follow semantic versioning and the public interface may change at any time.
5+
<div class="warning">
6+
Generally you should <b>not</b> find yourself needing to edit this crate! When possible, please use the feature crates instead.
7+
</div>

crates/bitwarden-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![doc = include_str!("../README.md")]
2+
13
#[cfg(feature = "uniffi")]
24
uniffi::setup_scaffolding!();
35
#[cfg(feature = "uniffi")]

crates/bitwarden-crypto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version.workspace = true
88
authors.workspace = true
99
edition.workspace = true
1010
rust-version.workspace = true
11+
readme.workspace = true
1112
homepage.workspace = true
1213
repository.workspace = true
1314
license-file.workspace = true

crates/bitwarden-crypto/README.md

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
1-
# Bitwarden Crypto
1+
# Bitwarden Cryptographic primitives
22

3-
This is an internal crate for the Bitwarden SDK do not depend on this directly and use the
4-
[`bitwarden`](https://crates.io/crates/bitwarden) crate instead.
3+
This crate contains the cryptographic primitives used throughout the SDK. The general aspiration is
4+
for this crate to handle all the difficult cryptographic operations and expose higher level concepts
5+
to the rest of the SDK.
56

6-
This crate does not follow semantic versioning and the public interface may change at any time.
7+
<div class="warning">
8+
Generally you should <b>not</b> find yourself needing to edit this crate! Everything written
9+
here requires additional care and attention to ensure that the cryptographic primitives are
10+
secure.
11+
</div>
12+
13+
## Example:
14+
15+
```rust
16+
use bitwarden_crypto::{SymmetricCryptoKey, KeyEncryptable, KeyDecryptable, CryptoError};
17+
18+
async fn example() -> Result<(), CryptoError> {
19+
let key = SymmetricCryptoKey::generate(rand::thread_rng());
20+
21+
let data = "Hello, World!".to_owned();
22+
let encrypted = data.clone().encrypt_with_key(&key)?;
23+
let decrypted: String = encrypted.decrypt_with_key(&key)?;
24+
25+
assert_eq!(data, decrypted);
26+
Ok(())
27+
}
28+
```
29+
30+
## Development considerations
31+
32+
This crate is expected to provide long term support for cryptographic operations. To that end, the
33+
following considerations should be taken into account when making changes to this crate:
34+
35+
- Limit public interfaces to the bare minimum.
36+
- Breaking changes should be rare and well communicated.
37+
- Serializable representation of keys and encrypted data must be supported indefinitely as we have
38+
no way to update all data.
39+
40+
### Conventions:
41+
42+
- Pure Functions that deterministically "derive" keys from input are prefixed with `derive_`.
43+
- Functions that generate non deterministically keys are prefixed with `make_`.
44+
45+
### Differences from `clients`
46+
47+
There are some noteworthy differences compared to the other Bitwarden
48+
[clients](https://github.com/bitwarden/clients). These changes are made in an effort to introduce
49+
conventions in how we name things, improve best practices and abstracting away internal complexity.
50+
51+
- `CryptoService.makeSendKey` & `AccessService.createAccessToken` are replaced by the generic
52+
`derive_shareable_key`
53+
- MasterKey operations such as `makeMasterKey` and `hashMasterKey` are moved to the MasterKey
54+
struct.
55+
56+
## Crate features
57+
58+
- `no-memory-hardening` - Disables memory hardening which ensures that allocated memory is zeroed on
59+
drop. This feature primarily exists in case you do not want to use the standard allocator, and we
60+
advise to still define a `global_allocator` using the [`ZeroizingAllocator`].

0 commit comments

Comments
 (0)