Skip to content

Commit

Permalink
Undo some moves
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Jun 17, 2024
1 parent a6faee8 commit 54d97cd
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 162 deletions.
4 changes: 2 additions & 2 deletions crates/bitwarden-exporters/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::Serializer;
use thiserror::Error;
use uuid::Uuid;

use crate::models::{Cipher, CipherType, Field, Folder};
use crate::{Cipher, CipherType, Field, Folder};

#[derive(Debug, Error)]
pub enum CsvError {
Expand Down Expand Up @@ -111,7 +111,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::models::{Card, Identity, Login, LoginUri};
use crate::{Card, Identity, Login, LoginUri};

#[test]
fn test_export_csv() {
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-exporters/src/encrypted_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use uuid::Uuid;

use crate::{
json::{self, export_json},
models::{Cipher, Folder},
Cipher, Folder,
};

#[derive(Error, Debug)]
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
use std::num::NonZeroU32;

use super::*;
use crate::models::{
use crate::{
Card, Cipher, CipherType, Field, Identity, Login, LoginUri, SecureNote, SecureNoteType,
};

Expand Down
6 changes: 2 additions & 4 deletions crates/bitwarden-exporters/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub(crate) fn export_vault(
let key = enc.get_key(&None).ok_or(VaultLocked)?;

let folders: Vec<FolderView> = folders.decrypt_with_key(key)?;
let folders: Vec<crate::models::Folder> =
folders.into_iter().flat_map(|f| f.try_into()).collect();
let folders: Vec<crate::Folder> = folders.into_iter().flat_map(|f| f.try_into()).collect();

let ciphers: Vec<CipherView> = ciphers.decrypt_with_key(key)?;
let ciphers: Vec<crate::models::Cipher> =
ciphers.into_iter().flat_map(|c| c.try_into()).collect();
let ciphers: Vec<crate::Cipher> = ciphers.into_iter().flat_map(|c| c.try_into()).collect();

match format {
ExportFormat::Csv => Ok(export_csv(folders, ciphers)?),
Expand Down
6 changes: 2 additions & 4 deletions crates/bitwarden-exporters/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use chrono::{DateTime, Utc};
use thiserror::Error;
use uuid::Uuid;

use crate::models::{
Card, Cipher, CipherType, Field, Folder, Identity, Login, LoginUri, SecureNote,
};
use crate::{Card, Cipher, CipherType, Field, Folder, Identity, Login, LoginUri, SecureNote};

#[derive(Error, Debug)]
pub enum JsonError {
Expand Down Expand Up @@ -272,7 +270,7 @@ mod tests {
use std::{fs, io::Read, path::PathBuf};

use super::*;
use crate::models::{Cipher, Field, LoginUri, SecureNoteType};
use crate::{Cipher, Field, LoginUri, SecureNoteType};

#[test]
fn test_convert_login() {
Expand Down
124 changes: 118 additions & 6 deletions crates/bitwarden-exporters/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use std::fmt;

use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use uuid::Uuid;

#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();

mod client_exporter;
mod csv;
mod encrypted_json;
mod json;
mod models;
pub use client_exporter::{ClientExporters, ClientExportersExt};
mod encrypted_json;
mod error;
pub(crate) mod export;
mod export;
pub use error::ExportError;
mod models;

#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();

#[derive(JsonSchema)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
Expand All @@ -20,3 +24,111 @@ pub enum ExportFormat {
Json,
EncryptedJson { password: String },
}

/// Export representation of a Bitwarden folder.
///
/// These are mostly duplicated from the `bitwarden` vault models to facilitate a stable export API
/// that is not tied to the internal vault models. We may revisit this in the future.
pub struct Folder {
pub id: Uuid,
pub name: String,
}

/// Export representation of a Bitwarden cipher.
///
/// These are mostly duplicated from the `bitwarden` vault models to facilitate a stable export API
/// that is not tied to the internal vault models. We may revisit this in the future.
pub struct Cipher {
pub id: Uuid,
pub folder_id: Option<Uuid>,

pub name: String,
pub notes: Option<String>,

pub r#type: CipherType,

pub favorite: bool,
pub reprompt: u8,

pub fields: Vec<Field>,

pub revision_date: DateTime<Utc>,
pub creation_date: DateTime<Utc>,
pub deleted_date: Option<DateTime<Utc>>,
}

#[derive(Clone)]
pub struct Field {
pub name: Option<String>,
pub value: Option<String>,
pub r#type: u8,
pub linked_id: Option<u32>,
}

pub enum CipherType {
Login(Box<Login>),
SecureNote(Box<SecureNote>),
Card(Box<Card>),
Identity(Box<Identity>),
}

impl fmt::Display for CipherType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CipherType::Login(_) => write!(f, "login"),
CipherType::SecureNote(_) => write!(f, "note"),
CipherType::Card(_) => write!(f, "card"),
CipherType::Identity(_) => write!(f, "identity"),
}
}
}

pub struct Login {
pub username: Option<String>,
pub password: Option<String>,
pub login_uris: Vec<LoginUri>,
pub totp: Option<String>,
}

pub struct LoginUri {
pub uri: Option<String>,
pub r#match: Option<u8>,
}

pub struct Card {
pub cardholder_name: Option<String>,
pub exp_month: Option<String>,
pub exp_year: Option<String>,
pub code: Option<String>,
pub brand: Option<String>,
pub number: Option<String>,
}

pub struct SecureNote {
pub r#type: SecureNoteType,
}

pub enum SecureNoteType {
Generic = 0,
}

pub struct Identity {
pub title: Option<String>,
pub first_name: Option<String>,
pub middle_name: Option<String>,
pub last_name: Option<String>,
pub address1: Option<String>,
pub address2: Option<String>,
pub address3: Option<String>,
pub city: Option<String>,
pub state: Option<String>,
pub postal_code: Option<String>,
pub country: Option<String>,
pub company: Option<String>,
pub email: Option<String>,
pub phone: Option<String>,
pub ssn: Option<String>,
pub username: Option<String>,
pub passport_number: Option<String>,
pub license_number: Option<String>,
}
Loading

0 comments on commit 54d97cd

Please sign in to comment.