Skip to content

Commit

Permalink
add version and type configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed May 19, 2021
1 parent c6e037f commit 89e7978
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 76 deletions.
3 changes: 3 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ button.tiny {
padding-right:10px;
padding-bottom:0px;
}
button.tiny:checked{
color: white;
}
.monospace{
font-family: "source code pro";
color: rgb(200,200,200);
Expand Down
25 changes: 24 additions & 1 deletion src/model/g_site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ impl GSite {
let self_ = imp::GSite::from_instance(&self);
*self_.siteDescriptor.borrow().siteName.borrow_mut() = name.to_owned();
}
pub fn set_descriptor_version(&self, version: spectre::AlgorithmVersion){
self.update_descriptor(SiteDescriptor{
siteName: RefCell::new(self.descriptor().siteName.borrow().to_owned()),
resultType: self.descriptor().resultType,
algorithmVersion: version
});
}
pub fn set_descriptor_type(&self, p_type: spectre::ResultType){
self.update_descriptor(SiteDescriptor{
siteName: RefCell::new(self.descriptor().siteName.borrow().to_owned()),
resultType: p_type,
algorithmVersion: self.descriptor().algorithmVersion
});
}
pub fn descriptor_name(&self) -> String {
self.descriptor().siteName.borrow().clone()
}
Expand Down Expand Up @@ -149,12 +163,21 @@ impl GSite {
pub fn is_search(&self) -> bool {
let is_search = *imp::GSite::from_instance(&self).isSearch.borrow();
is_search
// *self_.
}
pub fn set_site(&self, new_site : &spectre::Site){
let self_ = imp::GSite::from_instance(&self);
self_.site.replace(Some(*new_site));
}
pub fn get_password(&self, key : spectre::UserKey) -> String {
let d = self.descriptor();
if d.siteName.borrow().len() > 0{
println!("Generated pwd with version: V{:?}",d.algorithmVersion as i32);
let res = spectre::site_result(&d.siteName.borrow(), key, d.resultType, d.algorithmVersion);
res
}else{
String::from("")
}
}
}


Expand Down
54 changes: 50 additions & 4 deletions src/spectre/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt::Debug;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
extern crate num;
pub extern crate num;

pub type UserKey = spectrebind::SpectreUserKey;
impl Debug for UserKey{
Expand All @@ -24,7 +24,7 @@ impl Default for UserKey{
}
}
#[repr(u32)]
#[derive(FromPrimitive, Clone, Copy)]
#[derive(FromPrimitive, Clone, Copy, PartialEq)]
pub enum AlgorithmVersion {
/** V0 did math with chars whose signedness was platform-dependent. */
V0 = spectrebind::SpectreAlgorithmV0,
Expand All @@ -39,7 +39,7 @@ pub const AlgorithmVersionDefault: AlgorithmVersion = AlgorithmVersion::V3;
pub const AlgorithmVersionLatest: AlgorithmVersion = AlgorithmVersion::V3;

#[repr(u32)]
#[derive(FromPrimitive, Clone, Copy)]
#[derive(FromPrimitive, Clone, Copy, PartialEq)]
pub enum ResultType {
/** 16: pg^VMAUBk5x3p%HP%i4= */
TemplateMaximum = spectrebind::SpectreResultTemplateMaximum,
Expand All @@ -65,6 +65,50 @@ pub enum ResultType {
/** 4160: Derive a unique binary key. */
DeriveKey = spectrebind::SpectreResultDeriveKey,
}
impl ResultType {
pub fn iterable() -> Vec<ResultType> {
vec![ResultType::TemplateMaximum,
ResultType::TemplateLong,
ResultType::TemplateMedium,
ResultType::TemplateShort,
ResultType::TemplateBasic,
ResultType::TemplatePIN,
ResultType::TemplateName,
ResultType::TemplatePhrase]
}
}
impl std::str::FromStr for ResultType {
type Err = std::string::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {

match s {
"Maximum" => return Ok(ResultType::TemplateMaximum),
"Long" => return Ok(ResultType::TemplateLong),
"Medium" => return Ok(ResultType::TemplateMedium),
"Short" => return Ok(ResultType::TemplateShort),
"Basic" => return Ok(ResultType::TemplateBasic),
"PIN" => return Ok(ResultType::TemplatePIN),
"Name" => return Ok(ResultType::TemplateName),
"Phrase" => return Ok(ResultType::TemplatePhrase),
default => return Ok(ResultTypeDefault)
}
}
}
impl std::string::ToString for ResultType {
fn to_string(&self) -> String {
match self {
ResultType::TemplateMaximum => return "Maximum".to_owned(),
ResultType::TemplateLong => return "Long".to_owned(),
ResultType::TemplateMedium => return "Medium".to_owned(),
ResultType::TemplateShort => return "Short".to_owned(),
ResultType::TemplateBasic => return "Basic".to_owned(),
ResultType::TemplatePIN => return "PIN".to_owned(),
ResultType::TemplateName => return "Name".to_owned(),
ResultType::TemplatePhrase => return "Phrase".to_owned(),
default => return "".to_owned()
}
}
}
pub const ResultTypeDefault: ResultType = ResultType::TemplateLong;

pub fn name_for_format(format: u32) -> String {
Expand Down Expand Up @@ -263,6 +307,9 @@ impl Site {
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
}
pub fn last_used(&self) -> i64 {
self.lastUsed as i64
}
pub fn get_algorithm(&self) -> AlgorithmVersion {
num::FromPrimitive::from_u32(self.loginType as u32).unwrap()
}
Expand Down Expand Up @@ -368,7 +415,6 @@ impl User {
pub fn has_site(&self, site_name: &String) -> bool {
for s in self.get_sites() {
unsafe {
println!("{:?}",s.as_ref().unwrap().get_name());
if (*s).get_name() == site_name.clone() {
return true;
}
Expand Down
35 changes: 21 additions & 14 deletions src/ui/password_list_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ mod imp {
copy_button.set_size_request(120, -1);
copy_button.add_css_class("suggested-action");
copy_button.connect_clicked(glib::clone!(@weak obj, @weak copy_button => move |_| {
crate::ui::password_window::helper::copy_to_clipboard_with_notification(&copy_button, &obj.get_password());
let self_ = PasswordListBox::from_instance(&obj);
crate::ui::password_window::helper::copy_to_clipboard_with_notification(&copy_button, &self_.site.borrow().as_ref().unwrap().get_password(*self_.user_key.borrow().as_ref().unwrap()));

}));
hbox_bottom.append(&copy_button);

Expand Down Expand Up @@ -182,27 +184,32 @@ impl PasswordListBox {
// }
pub fn set_site(&self, site: &GSite) {
let self_ = imp::PasswordListBox::from_instance(&self);
// self_.password_label.borrow().as_ref().unwrap().set_text(spectre::site_result(name, user_key: UserKey, result_type: ResultType, algorithm_version: AlgorithmVersion));
self_.site_label.borrow().as_ref().unwrap().set_text(&site.name());
*self_.site.borrow_mut() = Some(site.clone());
self_
.password_label
.borrow()
.as_ref()
.unwrap()
.set_text(&self.get_password());
.set_text(&self_.site.borrow().as_ref().unwrap().get_password(*self_.user_key.borrow().as_ref().unwrap()));
}

pub fn get_password(&self) -> String {
let self_ = imp::PasswordListBox::from_instance(&self);
// pub fn get_password(&self) -> String {
// let self_ = imp::PasswordListBox::from_instance(&self);

// TODO remove hardcoded password_type
let password_type: spectre::ResultType = spectre::ResultType::TemplateLong;
spectre::site_result(
&self_.site.borrow().as_ref().unwrap().name(),
*self_.user_key.borrow().as_ref().unwrap(),
password_type,
spectre::AlgorithmVersionDefault,
)
}
// // TODO remove hardcoded password_type
// let password_type: spectre::ResultType = spectre::ResultType::TemplateLong;
// let site_name = self_.site.borrow().as_ref().unwrap().name();
// if site_name.len() > 0{
// spectre::site_result(
// &self_.site.borrow().as_ref().unwrap().name(),
// *self_.user_key.borrow().as_ref().unwrap(),
// password_type,
// spectre::AlgorithmVersionDefault,
// )
// }else{
// String::from("")
// }

// }
}
Loading

0 comments on commit 89e7978

Please sign in to comment.