mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
fixup sorting so that it only goes by lowercase values
This commit is contained in:
parent
bd5b482cb0
commit
4c180810a5
3 changed files with 128 additions and 100 deletions
|
|
@ -512,14 +512,14 @@ impl<'a> ActionManager<'a> {
|
||||||
extra.push_str("; ");
|
extra.push_str("; ");
|
||||||
extra.push_str(t!("vault.u2f.appinfo.authcount", xous::LANG));
|
extra.push_str(t!("vault.u2f.appinfo.authcount", xous::LANG));
|
||||||
extra.push_str(&pw.count.to_string());
|
extra.push_str(&pw.count.to_string());
|
||||||
let li = ListItem {
|
let li = ListItem::new(
|
||||||
name: desc.to_string(), // these allocs will be slow, but we do it only once on boot
|
desc.to_string(), // these allocs will be slow, but we do it only once on boot
|
||||||
extra: extra.to_string(),
|
extra.to_string(),
|
||||||
dirty: true,
|
true,
|
||||||
guid: guid.to_string(),
|
guid.to_string(),
|
||||||
atime: pw.atime,
|
pw.atime,
|
||||||
count: pw.count,
|
pw.count,
|
||||||
};
|
);
|
||||||
log::debug!("updating {} to list item {}", li.extra, li.key());
|
log::debug!("updating {} to list item {}", li.extra, li.key());
|
||||||
assert!(
|
assert!(
|
||||||
self.item_lists.lock().unwrap().insert_unique(entry.mode, li).is_some(),
|
self.item_lists.lock().unwrap().insert_unique(entry.mode, li).is_some(),
|
||||||
|
|
@ -923,9 +923,9 @@ impl<'a> ActionManager<'a> {
|
||||||
}
|
}
|
||||||
#[cfg(feature="vaultperf")]
|
#[cfg(feature="vaultperf")]
|
||||||
self.perfentry(&self.pm, PERFMETA_NONE, 3, std::line!());
|
self.perfentry(&self.pm, PERFMETA_NONE, 3, std::line!());
|
||||||
if prev_entry.name != desc { // this check should be redundant, but, leave it in to be safe
|
if prev_entry.name() != &desc { // this check should be redundant, but, leave it in to be safe
|
||||||
prev_entry.name.clear();
|
prev_entry.name_clear();
|
||||||
prev_entry.name.push_str(&desc);
|
prev_entry.name_push_str(&desc);
|
||||||
}
|
}
|
||||||
#[cfg(feature="vaultperf")]
|
#[cfg(feature="vaultperf")]
|
||||||
self.perfentry(&self.pm, PERFMETA_NONE, 3, std::line!());
|
self.perfentry(&self.pm, PERFMETA_NONE, 3, std::line!());
|
||||||
|
|
@ -946,14 +946,14 @@ impl<'a> ActionManager<'a> {
|
||||||
extra.push_str(t!("vault.u2f.appinfo.authcount", xous::LANG));
|
extra.push_str(t!("vault.u2f.appinfo.authcount", xous::LANG));
|
||||||
extra.push_str(&pw_rec.count.to_string());
|
extra.push_str(&pw_rec.count.to_string());
|
||||||
|
|
||||||
let li = ListItem {
|
let li = ListItem::new(
|
||||||
name: desc.to_string(), // these allocs will be slow, but we do it only once on boot
|
desc.to_string(), // these allocs will be slow, but we do it only once on boot
|
||||||
extra: extra.to_string(),
|
extra.to_string(),
|
||||||
dirty: true,
|
true,
|
||||||
guid: key.name,
|
key.name,
|
||||||
atime: pw_rec.atime,
|
pw_rec.atime,
|
||||||
count: pw_rec.count,
|
pw_rec.count,
|
||||||
};
|
);
|
||||||
il.push(self.mode_cache, li);
|
il.push(self.mode_cache, li);
|
||||||
#[cfg(feature="vaultperf")]
|
#[cfg(feature="vaultperf")]
|
||||||
self.perfentry(&self.pm, PERFMETA_ENDBLOCK, 4, std::line!());
|
self.perfentry(&self.pm, PERFMETA_ENDBLOCK, 4, std::line!());
|
||||||
|
|
@ -1022,14 +1022,14 @@ impl<'a> ActionManager<'a> {
|
||||||
ai.count,
|
ai.count,
|
||||||
);
|
);
|
||||||
let desc = format!("{} (U2F)", ai.name);
|
let desc = format!("{} (U2F)", ai.name);
|
||||||
let li = ListItem {
|
let li = ListItem::new(
|
||||||
name: desc,
|
desc,
|
||||||
extra,
|
extra,
|
||||||
dirty: true,
|
true,
|
||||||
guid: key.name,
|
key.name,
|
||||||
count: ai.count,
|
ai.count,
|
||||||
atime: ai.atime,
|
ai.atime,
|
||||||
};
|
);
|
||||||
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
||||||
} else {
|
} else {
|
||||||
let err = format!("{}:{}:{}: ({})[moved data]...",
|
let err = format!("{}:{}:{}: ({})[moved data]...",
|
||||||
|
|
@ -1080,14 +1080,14 @@ impl<'a> ActionManager<'a> {
|
||||||
};
|
};
|
||||||
let desc = format!("{} / {} (FIDO2)", result.rp_id, String::from_utf8(result.credential_id).unwrap_or("---".to_string()));
|
let desc = format!("{} / {} (FIDO2)", result.rp_id, String::from_utf8(result.credential_id).unwrap_or("---".to_string()));
|
||||||
let extra = format!("{}", name);
|
let extra = format!("{}", name);
|
||||||
let li = ListItem {
|
let li = ListItem::new(
|
||||||
name: desc,
|
desc,
|
||||||
extra,
|
extra,
|
||||||
dirty: true,
|
true,
|
||||||
guid: key.name,
|
key.name,
|
||||||
count: 0,
|
0,
|
||||||
atime: 0,
|
0,
|
||||||
};
|
);
|
||||||
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -1139,14 +1139,14 @@ impl<'a> ActionManager<'a> {
|
||||||
if totp.is_hotp {"HOTP"} else {"TOTP"}
|
if totp.is_hotp {"HOTP"} else {"TOTP"}
|
||||||
);
|
);
|
||||||
let desc = format!("{}", totp.name);
|
let desc = format!("{}", totp.name);
|
||||||
let li = ListItem {
|
let li = ListItem::new(
|
||||||
name: desc,
|
desc,
|
||||||
extra,
|
extra,
|
||||||
dirty: true,
|
true,
|
||||||
guid: key.name,
|
key.name,
|
||||||
count: 0,
|
0,
|
||||||
atime: 0,
|
0,
|
||||||
};
|
);
|
||||||
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
self.item_lists.lock().unwrap().insert_unique(self.mode_cache, li);
|
||||||
} else {
|
} else {
|
||||||
let err = format!("{}:{}:{}: ({})[moved data]...",
|
let err = format!("{}:{}:{}: ({})[moved data]...",
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub struct ListKey {
|
||||||
impl ListKey {
|
impl ListKey {
|
||||||
pub fn key_from_parts(name: &str, guid: &str) -> Self {
|
pub fn key_from_parts(name: &str, guid: &str) -> Self {
|
||||||
ListKey {
|
ListKey {
|
||||||
name: name.to_owned(),
|
name: name.to_owned().to_lowercase(),
|
||||||
guid: guid.to_owned(),
|
guid: guid.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,52 +24,60 @@ impl ListKey {
|
||||||
// re-uses the existing storage to avoid allocations
|
// re-uses the existing storage to avoid allocations
|
||||||
pub fn reset_from_parts(&mut self, name: &str, guid: &str) {
|
pub fn reset_from_parts(&mut self, name: &str, guid: &str) {
|
||||||
self.name.clear();
|
self.name.clear();
|
||||||
self.name.push_str(name);
|
self.name.push_str(&name.to_lowercase());
|
||||||
self.guid.clear();
|
self.guid.clear();
|
||||||
self.guid.push_str(guid);
|
self.guid.push_str(guid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ord for ListKey {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
match self.name.cmp(&other.name) {
|
||||||
|
Ordering::Equal => {
|
||||||
|
self.guid.cmp(&other.guid)
|
||||||
|
},
|
||||||
|
Ordering::Greater => Ordering::Greater,
|
||||||
|
Ordering::Less => Ordering::Less,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PartialOrd::<ListItem> for ListKey {
|
||||||
|
fn partial_cmp(&self, other: &ListItem) -> Option<Ordering> {
|
||||||
|
Some(
|
||||||
|
match self.name.cmp(&other.sortable_name) {
|
||||||
|
Ordering::Equal => {
|
||||||
|
self.guid.cmp(&other.guid)
|
||||||
|
},
|
||||||
|
Ordering::Greater => Ordering::Greater,
|
||||||
|
Ordering::Less => Ordering::Less,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl PartialOrd for ListKey {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
impl PartialEq for ListKey {
|
impl PartialEq for ListKey {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.name == other.name && self.guid == other.guid
|
self.name == other.name && self.guid == other.guid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl PartialOrd for ListKey {
|
impl Eq for ListKey {}
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
||||||
Some(
|
|
||||||
match self.name.to_lowercase().cmp(&other.name.to_lowercase()) {
|
|
||||||
Ordering::Equal => {
|
|
||||||
self.guid.cmp(&other.guid)
|
|
||||||
},
|
|
||||||
Ordering::Greater => Ordering::Greater,
|
|
||||||
Ordering::Less => Ordering::Less,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl PartialEq::<ListItem> for ListKey {
|
impl PartialEq::<ListItem> for ListKey {
|
||||||
fn eq(&self, other: &ListItem) -> bool {
|
fn eq(&self, other: &ListItem) -> bool {
|
||||||
self.name == other.name && self.guid == other.guid
|
self.name == other.sortable_name && self.guid == other.guid
|
||||||
}
|
|
||||||
}
|
|
||||||
impl PartialOrd::<ListItem> for ListKey {
|
|
||||||
fn partial_cmp(&self, other: &ListItem) -> Option<Ordering> {
|
|
||||||
Some(
|
|
||||||
match self.name.to_lowercase().cmp(&other.name.to_lowercase()) {
|
|
||||||
Ordering::Equal => {
|
|
||||||
self.guid.cmp(&other.guid)
|
|
||||||
},
|
|
||||||
Ordering::Greater => Ordering::Greater,
|
|
||||||
Ordering::Less => Ordering::Less,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Display list for items. "name" is the key by which the list is sorted.
|
/// Display list for items. "name" is the key by which the list is sorted.
|
||||||
/// "extra" is more information about the item, which should not be part of the sort.
|
/// "extra" is more information about the item, which should not be part of the sort.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ListItem {
|
pub struct ListItem {
|
||||||
pub name: String,
|
name: String,
|
||||||
|
sortable_name: String,
|
||||||
pub extra: String,
|
pub extra: String,
|
||||||
/// used by drawing routines to optimize refresh time
|
/// used by drawing routines to optimize refresh time
|
||||||
pub dirty: bool,
|
pub dirty: bool,
|
||||||
|
|
@ -79,30 +87,9 @@ pub struct ListItem {
|
||||||
pub atime: u64,
|
pub atime: u64,
|
||||||
pub count: u64,
|
pub count: u64,
|
||||||
}
|
}
|
||||||
impl ListItem {
|
|
||||||
// good riddance.
|
|
||||||
/* pub fn clone(&self) -> ListItem {
|
|
||||||
ListItem {
|
|
||||||
name: self.name.to_string(),
|
|
||||||
extra: self.extra.to_string(),
|
|
||||||
dirty: self.dirty,
|
|
||||||
guid: self.guid.to_string(),
|
|
||||||
atime: self.atime,
|
|
||||||
count: self.count,
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
/// This is made available for edit/delete routines to generate the key without having to
|
|
||||||
/// make a whole ListItem record (which is somewhat expensive).
|
|
||||||
pub fn key_from_parts(name: &str, guid: &str) -> String {
|
|
||||||
name.to_lowercase() + &guid.to_string()
|
|
||||||
}
|
|
||||||
pub fn key(&self) -> String {
|
|
||||||
Self::key_from_parts(&self.name, &self.guid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Ord for ListItem {
|
impl Ord for ListItem {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
match self.name.to_lowercase().cmp(&other.name.to_lowercase()) {
|
match self.sortable_name.cmp(&other.sortable_name) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
self.guid.cmp(&other.guid)
|
self.guid.cmp(&other.guid)
|
||||||
},
|
},
|
||||||
|
|
@ -120,7 +107,7 @@ impl PartialOrd::<ListKey> for ListItem {
|
||||||
fn partial_cmp(&self, other: &ListKey) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &ListKey) -> Option<Ordering> {
|
||||||
// log::info!("self {}:{}\nother: {}:{}", self.name, self.guid, other.name, other.guid);
|
// log::info!("self {}:{}\nother: {}:{}", self.name, self.guid, other.name, other.guid);
|
||||||
Some(
|
Some(
|
||||||
match self.name.to_lowercase().cmp(&other.name.to_lowercase()) {
|
match self.sortable_name.cmp(&other.name) {
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
self.guid.cmp(&other.guid)
|
self.guid.cmp(&other.guid)
|
||||||
},
|
},
|
||||||
|
|
@ -132,16 +119,57 @@ impl PartialOrd::<ListKey> for ListItem {
|
||||||
}
|
}
|
||||||
impl PartialEq::<ListKey> for ListItem {
|
impl PartialEq::<ListKey> for ListItem {
|
||||||
fn eq(&self, other: &ListKey) -> bool {
|
fn eq(&self, other: &ListKey) -> bool {
|
||||||
self.name == other.name && self.guid == other.guid
|
self.sortable_name == other.name && self.guid == other.guid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl PartialEq for ListItem {
|
impl PartialEq for ListItem {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.name == other.name && self.guid == other.guid
|
self.sortable_name == other.sortable_name && self.guid == other.guid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Eq for ListItem {}
|
impl Eq for ListItem {}
|
||||||
|
|
||||||
|
impl ListItem {
|
||||||
|
pub fn new(
|
||||||
|
name: String,
|
||||||
|
extra: String,
|
||||||
|
dirty: bool,
|
||||||
|
guid: String,
|
||||||
|
atime: u64,
|
||||||
|
count: u64,
|
||||||
|
) -> Self {
|
||||||
|
let sortable_name = name.to_lowercase();
|
||||||
|
Self {
|
||||||
|
name,
|
||||||
|
sortable_name,
|
||||||
|
extra,
|
||||||
|
dirty,
|
||||||
|
guid,
|
||||||
|
atime,
|
||||||
|
count,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// This is made available for edit/delete routines to generate the key without having to
|
||||||
|
/// make a whole ListItem record (which is somewhat expensive).
|
||||||
|
pub fn key_from_parts(name: &str, guid: &str) -> String {
|
||||||
|
name.to_lowercase() + &guid.to_string()
|
||||||
|
}
|
||||||
|
pub fn key(&self) -> String {
|
||||||
|
Self::key_from_parts(&self.name, &self.guid)
|
||||||
|
}
|
||||||
|
pub fn name(&self) -> &String {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
pub fn name_clear(&mut self) {
|
||||||
|
self.name.clear();
|
||||||
|
self.sortable_name.clear();
|
||||||
|
}
|
||||||
|
pub fn name_push_str(&mut self, name: &String) {
|
||||||
|
self.name.push_str(name);
|
||||||
|
self.sortable_name.push_str(&name.to_lowercase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FilteredListView {
|
pub struct FilteredListView {
|
||||||
list: Vec<ListItem>,
|
list: Vec<ListItem>,
|
||||||
sorted: bool,
|
sorted: bool,
|
||||||
|
|
@ -240,7 +268,7 @@ impl FilteredListView {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// step 1. binary search to find if the criteria is even anywhere in the list.
|
// step 1. binary search to find if the criteria is even anywhere in the list.
|
||||||
match self.list.binary_search_by(|probe| probe.name.partial_cmp(criteria).unwrap()) {
|
match self.list.binary_search_by(|probe| probe.sortable_name.partial_cmp(criteria).unwrap()) {
|
||||||
Ok(mut index) | Err(mut index) => {
|
Ok(mut index) | Err(mut index) => {
|
||||||
if !self.list[index].name.to_lowercase().starts_with(criteria) {
|
if !self.list[index].name.to_lowercase().starts_with(criteria) {
|
||||||
self.filter_range = None
|
self.filter_range = None
|
||||||
|
|
|
||||||
|
|
@ -467,7 +467,7 @@ impl VaultUx {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if item.dirty {
|
if item.dirty {
|
||||||
log::debug!("drawing {}", item.name);
|
log::debug!("drawing {}", item.name());
|
||||||
let mut box_text = TextView::new(self.content,
|
let mut box_text = TextView::new(self.content,
|
||||||
graphics_server::TextBounds::BoundingBox(
|
graphics_server::TextBounds::BoundingBox(
|
||||||
Rectangle::new(
|
Rectangle::new(
|
||||||
|
|
@ -485,7 +485,7 @@ impl VaultUx {
|
||||||
box_text.border_width = 4;
|
box_text.border_width = 4;
|
||||||
}
|
}
|
||||||
match mode_at_entry {
|
match mode_at_entry {
|
||||||
VaultMode::Fido | VaultMode::Password => {write!(box_text, "{}\n{}", item.name, item.extra).ok();},
|
VaultMode::Fido | VaultMode::Password => {write!(box_text, "{}\n{}", item.name(), item.extra).ok();},
|
||||||
VaultMode::Totp => {
|
VaultMode::Totp => {
|
||||||
let fields = item.extra.split(':').collect::<Vec<&str>>();
|
let fields = item.extra.split(':').collect::<Vec<&str>>();
|
||||||
if fields.len() == 5 {
|
if fields.len() == 5 {
|
||||||
|
|
@ -509,7 +509,7 @@ impl VaultUx {
|
||||||
).unwrap_or(t!("vault.error.record_error", xous::LANG).to_string());
|
).unwrap_or(t!("vault.error.record_error", xous::LANG).to_string());
|
||||||
// why code on top? because the item.name can be very long, and it can wrap which would cause
|
// why code on top? because the item.name can be very long, and it can wrap which would cause
|
||||||
// the code to become hidden.
|
// the code to become hidden.
|
||||||
write!(box_text, "{}\n{}", code, item.name).ok();
|
write!(box_text, "{}\n{}", code, item.name()).ok();
|
||||||
} else {
|
} else {
|
||||||
let code = generate_totp_code(
|
let code = generate_totp_code(
|
||||||
step_seconds,
|
step_seconds,
|
||||||
|
|
@ -517,7 +517,7 @@ impl VaultUx {
|
||||||
).unwrap_or(t!("vault.error.record_error", xous::LANG).to_string());
|
).unwrap_or(t!("vault.error.record_error", xous::LANG).to_string());
|
||||||
// why code on top? because the item.name can be very long, and it can wrap which would cause
|
// why code on top? because the item.name can be very long, and it can wrap which would cause
|
||||||
// the code to become hidden.
|
// the code to become hidden.
|
||||||
write!(box_text, "HOTP {}\n{}", code, item.name).ok();
|
write!(box_text, "HOTP {}\n{}", code, item.name()).ok();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write!(box_text, "{}", t!("vault.error.record_error", xous::LANG)).ok();
|
write!(box_text, "{}", t!("vault.error.record_error", xous::LANG)).ok();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue