Skip to content

Commit 2a6c111

Browse files
Merge pull request #385 from cortex/v6-support
V6 support
2 parents b1cf9eb + 005d56d commit 2a6c111

11 files changed

Lines changed: 395 additions & 220 deletions

File tree

cursive/src/main.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use cursive::{
3333
RadioGroup, ResizedView, ScrollView, SelectView, TextArea, TextView,
3434
},
3535
};
36-
use hex::FromHex;
3736
use pass::Result;
3837
use ripasso::{
3938
crypto::CryptoImpl,
@@ -48,12 +47,12 @@ use unic_langid::LanguageIdentifier;
4847
mod helpers;
4948
mod wizard;
5049

51-
use lazy_static::lazy_static;
52-
use zeroize::Zeroize;
53-
5450
use crate::helpers::{
5551
get_value_from_input, is_checkbox_checked, is_radio_button_selected, recipients_widths,
5652
};
53+
use lazy_static::lazy_static;
54+
use ripasso::crypto::Fingerprint;
55+
use zeroize::Zeroize;
5756

5857
/// The 'pointer' to the current PasswordStore is of this convoluted type.
5958
type PasswordStoreType = Arc<Mutex<Arc<Mutex<PasswordStore>>>>;
@@ -1383,13 +1382,9 @@ fn get_stores(config: &config::Config, home: &Option<PathBuf>) -> Result<Vec<Pas
13831382
}?;
13841383

13851384
let own_fingerprint = store.get("own_fingerprint");
1386-
let own_fingerprint = match own_fingerprint {
1387-
None => None,
1388-
Some(k) => match k.clone().into_string() {
1389-
Err(_) => None,
1390-
Ok(key) => <[u8; 20]>::from_hex(key).ok(),
1391-
},
1392-
};
1385+
let own_fingerprint = own_fingerprint
1386+
.map(|k| k.clone().into_string().map(|key| key.as_str().try_into())?)
1387+
.transpose()?;
13931388

13941389
final_stores.push(PasswordStore::new(
13951390
store_name,
@@ -1507,7 +1502,7 @@ fn save_edit_config(
15071502
false => CryptoImpl::GpgMe,
15081503
};
15091504

1510-
let own_fingerprint = <[u8; 20]>::from_hex(own_fingerprint).ok();
1505+
let own_fingerprint: Fingerprint = own_fingerprint.as_str().try_into()?;
15111506

15121507
let new_store = PasswordStore::new(
15131508
e_n,
@@ -1516,7 +1511,7 @@ fn save_edit_config(
15161511
home,
15171512
&None,
15181513
&pgp_impl,
1519-
&own_fingerprint,
1514+
&Some(own_fingerprint),
15201515
);
15211516
if let Err(err) = new_store {
15221517
helpers::errorbox(ui, &err);
@@ -1689,7 +1684,10 @@ fn edit_store_in_config(
16891684
fingerprint_fields.add_child(
16901685
EditView::new()
16911686
.content(hex::encode_upper(
1692-
store.get_crypto().own_fingerprint().unwrap_or([0; 20]),
1687+
store
1688+
.get_crypto()
1689+
.own_fingerprint()
1690+
.unwrap_or(Fingerprint::V4([0; 20])),
16931691
))
16941692
.with_name("edit_own_fingerprint_input")
16951693
.fixed_size((50_usize, 1_usize)),

cursive/src/tests/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use cursive::{
88
views::{Checkbox, EditView, LinearLayout, RadioButton, RadioGroup},
99
};
1010
use hex::FromHex;
11-
use ripasso::crypto::CryptoImpl;
11+
use ripasso::crypto::{CryptoImpl, Fingerprint};
1212
use ripasso::pass::{Comment, KeyRingStatus, OwnerTrustLevel, Recipient};
1313

1414
#[test]
@@ -100,9 +100,9 @@ pub fn recipient_alex() -> Recipient {
100100
post_comment: None,
101101
},
102102
key_id: "1D108E6C07CBC406".to_owned(),
103-
fingerprint: Some(
103+
fingerprint: Some(Fingerprint::V4(
104104
<[u8; 20]>::from_hex("7E068070D5EF794B00C8A9D91D108E6C07CBC406").unwrap(),
105-
),
105+
)),
106106
key_ring_status: KeyRingStatus::InKeyRing,
107107
trust_level: OwnerTrustLevel::Ultimate,
108108
not_usable: false,

cursive/src/tests/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{fs::File, io::Write};
22

33
use chrono::Local;
4+
use hex::FromHex;
45
use ripasso::pass::{PasswordEntry, RepositoryStatus};
56
use tempfile::tempdir;
67

@@ -168,9 +169,9 @@ fn render_recipient_label_ultimate() {
168169
post_comment: None,
169170
},
170171
key_id: "1D108E6C07CBC406".to_owned(),
171-
fingerprint: Some(
172+
fingerprint: Some(Fingerprint::V4(
172173
<[u8; 20]>::from_hex("7E068070D5EF794B00C8A9D91D108E6C07CBC406").unwrap(),
173-
),
174+
)),
174175
key_ring_status: pass::KeyRingStatus::InKeyRing,
175176
trust_level: OwnerTrustLevel::Ultimate,
176177
not_usable: false,

gtk/src/window/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ use std::{
66
sync::{Arc, Mutex},
77
};
88

9+
use crate::{collection_object::CollectionObject, password_object::PasswordObject};
910
use adw::{ActionRow, NavigationDirection, prelude::*, subclass::prelude::*};
1011
use glib::{Object, clone};
1112
use gtk::{
1213
AboutDialog, CustomFilter, Dialog, DialogFlags, Entry, FilterListModel, Label, ListBox,
1314
ListBoxRow, NoSelection, ResponseType, SelectionMode, gio, glib, glib::BindingFlags, pango,
1415
};
15-
use hex::FromHex;
1616
use ripasso::{crypto::CryptoImpl, pass::PasswordStore};
1717

18-
use crate::{collection_object::CollectionObject, password_object::PasswordObject};
19-
2018
glib::wrapper! {
2119
pub struct Window(ObjectSubclass<imp::Window>)
2220
@extends adw::ApplicationWindow, gtk::ApplicationWindow, gtk::Window, gtk::Widget,
@@ -580,13 +578,10 @@ fn get_stores(
580578
}?;
581579

582580
let own_fingerprint = store.get("own_fingerprint");
583-
let own_fingerprint = match own_fingerprint {
584-
None => None,
585-
Some(k) => match k.clone().into_string() {
586-
Err(_) => None,
587-
Ok(key) => <[u8; 20]>::from_hex(key).ok(),
588-
},
589-
};
581+
let own_fingerprint = own_fingerprint
582+
.map(|k| k.clone().into_string().map(|fp| fp.as_str().try_into()))
583+
.transpose()?
584+
.transpose()?;
590585

591586
final_stores.push(PasswordStore::new(
592587
store_name,

0 commit comments

Comments
 (0)