summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-01-29 10:03:53 +0100
committerNeal H. Walfield <neal@pep.foundation>2019-01-29 10:11:10 +0100
commitee276a2dc55fd55f22494e9e70187f060fb2f151 (patch)
tree929535f9ce9bc062e6074126e36ed15ef3f746a4
parent14c40b714a9b08d846b2b48ece0788bd47797cb9 (diff)
openpgp: Change TPKBuilder::add_userid to take an Into<Cow>>.
- Change TPKBuilder::add_userid to take an Into<Cow<'a, str>>> instead of a &str.
-rw-r--r--openpgp-ffi/src/tpk.rs4
-rw-r--r--openpgp/src/tpk/builder.rs8
-rw-r--r--openpgp/src/tsk.rs2
3 files changed, 9 insertions, 5 deletions
diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs
index a3df23b7..b4026604 100644
--- a/openpgp-ffi/src/tpk.rs
+++ b/openpgp-ffi/src/tpk.rs
@@ -613,8 +613,8 @@ pub extern "system" fn pgp_tpk_builder_add_userid
{
let tpkb = ffi_param_ref_mut!(tpkb);
let tpkb_ = ffi_param_move!(*tpkb);
- let uid = ffi_param_cstr!(uid).to_string_lossy().to_string();
- let tpkb_ = tpkb_.add_userid(uid.as_ref());
+ let uid = ffi_param_cstr!(uid).to_string_lossy();
+ let tpkb_ = tpkb_.add_userid(uid);
*tpkb = box_raw!(tpkb_);
}
diff --git a/openpgp/src/tpk/builder.rs b/openpgp/src/tpk/builder.rs
index ff4670ab..014ec5e4 100644
--- a/openpgp/src/tpk/builder.rs
+++ b/openpgp/src/tpk/builder.rs
@@ -1,3 +1,5 @@
+use std::borrow::Cow;
+
use time;
use packet::{Features, KeyFlags};
use packet::Key;
@@ -118,8 +120,10 @@ impl TPKBuilder {
}
/// Adds a new user ID. The first user ID added will be the primary user ID.
- pub fn add_userid(mut self, uid: &str) -> Self {
- self.userids.push(uid.to_string());
+ pub fn add_userid<'a, S>(mut self, uid: S) -> Self
+ where S: Into<Cow<'a, str>>
+ {
+ self.userids.push(uid.into().into_owned());
self
}
diff --git a/openpgp/src/tsk.rs b/openpgp/src/tsk.rs
index d9ec86bf..fff2a7ed 100644
--- a/openpgp/src/tsk.rs
+++ b/openpgp/src/tsk.rs
@@ -84,7 +84,7 @@ impl TSK {
let mut key = TPKBuilder::autocrypt(None);
match primary_uid.into() {
- Some(uid) => { key = key.add_userid(&uid); }
+ Some(uid) => { key = key.add_userid(uid); }
None => {}
}