Skip to content

Commit 0872274

Browse files
authored
Format WASM generator code to be in line with other clients (#223)
## 🎟️ Tracking ## 📔 Objective Reformatting some of my [previous PR](#197) to be more in line with the rest of the code ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent c6835e5 commit 0872274

File tree

5 files changed

+17
-59
lines changed

5 files changed

+17
-59
lines changed

crates/bitwarden-generators/src/generator_client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use bitwarden_core::Client;
2+
#[cfg(feature = "wasm")]
3+
use wasm_bindgen::prelude::*;
24

35
use crate::{
46
passphrase::passphrase, password::password, username::username, PassphraseError,
57
PassphraseGeneratorRequest, PasswordError, PasswordGeneratorRequest, UsernameError,
68
UsernameGeneratorRequest,
79
};
810

11+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
912
pub struct GeneratorClient {
1013
client: Client,
1114
}
1215

16+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
1317
impl GeneratorClient {
1418
fn new(client: Client) -> Self {
1519
Self { client }
@@ -68,7 +72,9 @@ impl GeneratorClient {
6872
pub fn passphrase(&self, input: PassphraseGeneratorRequest) -> Result<String, PassphraseError> {
6973
passphrase(input)
7074
}
75+
}
7176

77+
impl GeneratorClient {
7278
/// Generates a random username.
7379
/// There are different username generation strategies, which can be customized using the
7480
/// `input` parameter.

crates/bitwarden-generators/src/username.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bitwarden_crypto::EFF_LONG_WORD_LIST;
2+
use bitwarden_error::bitwarden_error;
23
use rand::{distributions::Distribution, seq::SliceRandom, Rng, RngCore};
34
use reqwest::StatusCode;
45
use schemars::JsonSchema;
@@ -7,6 +8,7 @@ use thiserror::Error;
78

89
use crate::util::capitalize_first_letter;
910

11+
#[bitwarden_error(flat)]
1012
#[derive(Debug, Error)]
1113
pub enum UsernameError {
1214
#[error("Invalid API Key")]
@@ -66,6 +68,11 @@ pub enum ForwarderServiceType {
6668
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
6769
#[serde(rename_all = "camelCase", deny_unknown_fields)]
6870
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
71+
#[cfg_attr(
72+
feature = "wasm",
73+
derive(tsify_next::Tsify),
74+
tsify(into_wasm_abi, from_wasm_abi)
75+
)]
6976
pub enum UsernameGeneratorRequest {
7077
/// Generates a single word username
7178
Word {

crates/bitwarden-wasm-internal/src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use std::fmt::Display;
44
use bitwarden_core::{Client, ClientSettings};
55
use bitwarden_error::bitwarden_error;
66
use bitwarden_exporters::ExporterClientExt;
7+
use bitwarden_generators::GeneratorClientsExt;
78
use bitwarden_vault::VaultClientExt;
89
use wasm_bindgen::prelude::*;
910

10-
use crate::{CryptoClient, GeneratorClient, VaultClient};
11+
use crate::{CryptoClient, VaultClient};
1112

1213
#[wasm_bindgen]
1314
pub struct BitwardenClient(pub(crate) Client);
@@ -49,8 +50,8 @@ impl BitwardenClient {
4950
}
5051

5152
/// Constructs a specific client for generating passwords and passphrases
52-
pub fn generator(&self) -> GeneratorClient {
53-
GeneratorClient::new(self.0.clone())
53+
pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
54+
self.0.generator()
5455
}
5556

5657
pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {

crates/bitwarden-wasm-internal/src/generators.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.

crates/bitwarden-wasm-internal/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
mod client;
44
mod crypto;
55
mod custom_types;
6-
mod generators;
76
mod init;
87
mod pure_crypto;
98
mod ssh;
@@ -12,6 +11,5 @@ mod vault;
1211
pub use bitwarden_ipc::wasm::*;
1312
pub use client::BitwardenClient;
1413
pub use crypto::CryptoClient;
15-
pub use generators::GeneratorClient;
1614
pub use init::init_sdk;
1715
pub use vault::{folders::FoldersClient, VaultClient};

0 commit comments

Comments
 (0)