Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frost-client: don't allow overwriting contacts #483

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions frost-client/src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ pub(crate) fn import(args: &Command) -> Result<(), Box<dyn Error>> {
let mut config = Config::read(config)?;

let mut contact = Contact::from_text(&text_contact)?;
if config.contact.contains_key(&contact.name) {
return Err(eyre!(
"contact with name {} already exists. Either remove the existing \
one, or ask the sender to change their display name when exporting",
&contact.name
)
.into());
}
if config.contact.values().any(|c| c.pubkey == contact.pubkey) {
return Err(eyre!(
"pubkey {} already registered for {}",
hex::encode(&contact.pubkey),
&contact.name,
)
.into());
}
if config.communication_key.as_ref().map(|c| &c.pubkey) == Some(&contact.pubkey) {
return Err(eyre!(
"pubkey {} already registered for yourself",
hex::encode(&contact.pubkey)
)
.into());
}
// We don't want the version when writing to the config file.
contact.version = None;
config.contact.insert(contact.name.clone(), contact.clone());
Expand Down
Loading