-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-14229] Add more docs to bitwarden_core
#39
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,10 +30,20 @@ pub enum EncryptionSettingsError { | |||||||||||||||||||||||
MissingPrivateKey, | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/// A struct containing the core keys of a Bitwarden user. | ||||||||||||||||||||||||
#[derive(Clone)] | ||||||||||||||||||||||||
pub struct EncryptionSettings { | ||||||||||||||||||||||||
/// The users symmetric key, stored on the server after being | ||||||||||||||||||||||||
/// encrypted with another key. | ||||||||||||||||||||||||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is these details relevant to the EncryptionSettings context? We could expand this to give the bigger picture in which case this information could be relevant. If not I think we should focus on the EncryptionSettings perspective which is not to share this anywhere.
Suggested change
|
||||||||||||||||||||||||
user_key: SymmetricCryptoKey, | ||||||||||||||||||||||||
/// The users private key, stored on the server | ||||||||||||||||||||||||
/// encrypted with the users symmetric key. | ||||||||||||||||||||||||
pub(crate) private_key: Option<AsymmetricCryptoKey>, | ||||||||||||||||||||||||
/// A map of the users organization keys with the key being | ||||||||||||||||||||||||
/// the ID of the organization and the value being the symmetric | ||||||||||||||||||||||||
/// key. This map may be empty if the user is not a part of | ||||||||||||||||||||||||
/// any organizations. These keys are stored on the server | ||||||||||||||||||||||||
/// encrypted with the users private key. | ||||||||||||||||||||||||
Comment on lines
+45
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: I'm always confused on how to write this, technically they are encrypted with the public key and decrypted with the private key ๐คท |
||||||||||||||||||||||||
org_keys: HashMap<Uuid, SymmetricCryptoKey>, | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ pub(crate) struct Tokens { | |
pub(crate) refresh_token: Option<String>, | ||
} | ||
|
||
/// A struct contains various internal actions. Everything on this type | ||
/// should be considered unstable and subject to change at any time. Use | ||
/// with caution. | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question/suggestion: Who are targeting with this documentation? For external consumers this makes sense, but for our internal products we're expected to use this and not have to "be afraid". Should we maybe clarify that? |
||
#[derive(Debug)] | ||
pub struct InternalClient { | ||
pub(crate) tokens: RwLock<Tokens>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,58 @@ use super::{ | |
}; | ||
use crate::{error::Result, Client}; | ||
|
||
/// A struct containing platform utilities. | ||
pub struct ClientPlatform<'a> { | ||
pub(crate) client: &'a Client, | ||
} | ||
|
||
impl<'a> ClientPlatform<'a> { | ||
/// Will generate a fingerprint based on the `input`. Given the same `input` This | ||
/// method will always result in the exact same output. | ||
/// | ||
/// # Examples | ||
/// ```rust | ||
/// # use bitwarden_core::client::test_accounts::PUBLIC_KEY; | ||
/// use base64::{engine::general_purpose::STANDARD, Engine}; | ||
/// use bitwarden_core::{Client, platform::FingerprintRequest}; | ||
/// | ||
/// fn test(client: Client) { | ||
/// let fingerprint_response = client.platform() | ||
/// .fingerprint(&FingerprintRequest { | ||
/// fingerprint_material: "my_material".to_owned(), | ||
/// public_key: STANDARD.encode(PUBLIC_KEY), | ||
/// }) | ||
/// .unwrap(); | ||
/// | ||
/// assert_eq!(fingerprint_response.fingerprint, "unsure-unethical-bruising-semester-subscript"); | ||
/// } | ||
/// | ||
/// # tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on( | ||
/// # async { test(Client::test_account().await) }); | ||
/// ``` | ||
pub fn fingerprint(&self, input: &FingerprintRequest) -> Result<FingerprintResponse> { | ||
generate_fingerprint(input) | ||
} | ||
|
||
/// Will generate a fingerprint based on the given `fingerprint_material` | ||
/// and the users public key. Given the same `fingerprint_material` and | ||
/// the same user this method will always result in the exact same output. | ||
/// | ||
/// The returned fingerprint is a string of 5 words seperated by hyphens. | ||
/// | ||
/// # Examples | ||
/// ```rust | ||
/// use bitwarden_core::Client; | ||
/// | ||
/// async fn test() { | ||
/// let client = Client::test_account().await; | ||
/// let fingerprint = client.platform() | ||
/// .user_fingerprint("my_material".to_owned()) | ||
/// .unwrap(); | ||
/// | ||
/// assert_eq!(fingerprint, "dreamland-desecrate-corrosive-ecard-retry"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: huh, interesting, here we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we'd just assert! as much as possible, that way we can have an explanatory code comment and test all in one. That might not be always acceptable, if the output of the function is too long we don't want the code sample to be dwarfed by a massive multi-line assert for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I also prefer assert but the one above didn't use it in the above doc because I couldn't come up with a way to concisely show off a public key that wouldn't be pretty ugly for a test. I could probably generate a new one in a simple one-liner but I still couldn't |
||
/// } | ||
/// ``` | ||
pub fn user_fingerprint(self, fingerprint_material: String) -> Result<String> { | ||
generate_user_fingerprint(self.client, fingerprint_material) | ||
} | ||
|
@@ -27,6 +70,7 @@ impl<'a> ClientPlatform<'a> { | |
} | ||
|
||
impl<'a> Client { | ||
/// Retrieves a [`ClientPlatform`] for accessing Platform APIs. | ||
pub fn platform(&'a self) -> ClientPlatform<'a> { | ||
ClientPlatform { client: self } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: It's fairly self explanatory that this is a struct both from the code, but also in rust docs.