summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openpgp/src/autocrypt.rs6
-rw-r--r--openpgp/src/crypto/hash.rs4
-rw-r--r--openpgp/src/packet/userid.rs2
-rw-r--r--openpgp/src/parse/parse.rs5
-rw-r--r--openpgp/src/serialize/mod.rs6
-rw-r--r--openpgp/src/tpk/builder.rs15
-rw-r--r--openpgp/src/tpk/mod.rs14
7 files changed, 21 insertions, 31 deletions
diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs
index ff75ab96..c5617f83 100644
--- a/openpgp/src/autocrypt.rs
+++ b/openpgp/src/autocrypt.rs
@@ -845,7 +845,7 @@ In the light of the Efail vulnerability I am asking myself if it's
assert_eq!(tpk.primary().fingerprint(),
Fingerprint::from_hex(
&"156962B0F3115069ACA970C68E3B03A279B772D6"[..]).unwrap());
- assert_eq!(&tpk.userids().next().unwrap().userid().value[..],
+ assert_eq!(tpk.userids().next().unwrap().userid().userid(),
&b"holger krekel <holger@merlinux.eu>"[..]);
@@ -868,7 +868,7 @@ In the light of the Efail vulnerability I am asking myself if it's
assert_eq!(tpk.primary().fingerprint(),
Fingerprint::from_hex(
&"D4AB192964F76A7F8F8A9B357BD18320DEADFA11"[..]).unwrap());
- assert_eq!(&tpk.userids().next().unwrap().userid().value[..],
+ assert_eq!(tpk.userids().next().unwrap().userid().userid(),
&b"Vincent Breitmoser <look@my.amazin.horse>"[..]);
@@ -891,7 +891,7 @@ In the light of the Efail vulnerability I am asking myself if it's
assert_eq!(tpk.primary().fingerprint(),
Fingerprint::from_hex(
&"4F9F89F5505AC1D1A260631CDB1187B9DD5F693B"[..]).unwrap());
- assert_eq!(&tpk.userids().next().unwrap().userid().value[..],
+ assert_eq!(tpk.userids().next().unwrap().userid().userid(),
&b"Patrick Brunschwig <patrick@enigmail.net>"[..]);
let ac2 = AutocryptHeaders::from_bytes(&PATRICK_UNFOLDED[..]).unwrap();
diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs
index 0b351830..8c74f7f4 100644
--- a/openpgp/src/crypto/hash.rs
+++ b/openpgp/src/crypto/hash.rs
@@ -139,14 +139,14 @@ impl UserID {
let mut header = [0; 5];
header[0] = 0xB4;
- let len = self.value.len() as u32;
+ let len = self.userid().len() as u32;
header[1] = (len >> 24) as u8;
header[2] = (len >> 16) as u8;
header[3] = (len >> 8) as u8;
header[4] = (len) as u8;
hash.update(&header[..]);
- hash.update(&self.value[..]);
+ hash.update(self.userid());
}
}
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs
index 23b3849b..8459fd91 100644
--- a/openpgp/src/packet/userid.rs
+++ b/openpgp/src/packet/userid.rs
@@ -21,7 +21,7 @@ pub struct UserID {
/// [RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.11
///
/// Use `UserID::default()` to get a UserID with a default settings.
- pub(crate) value: Vec<u8>,
+ value: Vec<u8>,
}
impl From<Vec<u8>> for UserID {
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 899e571c..573bbb1d 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1469,10 +1469,7 @@ impl UserID {
let value = php_try!(php.parse_bytes_eof("value"));
- php.ok(Packet::UserID(UserID {
- common: Default::default(),
- value: value,
- }))
+ php.ok(Packet::UserID(UserID::from(value)))
}
}
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 156b83fc..5a6c3982 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -855,18 +855,18 @@ impl Serialize for UserID {
/// Writes a serialized version of the specified `UserID` packet to
/// `o`.
fn serialize<W: io::Write>(&self, o: &mut W) -> Result<()> {
- let len = self.value.len();
+ let len = self.userid().len();
CTB::new(Tag::UserID).serialize(o)?;
BodyLength::Full(len as u32).serialize(o)?;
- o.write_all(&self.value[..])?;
+ o.write_all(self.userid())?;
Ok(())
}
/// Serializes the packet to a vector.
fn to_vec(&self) -> Result<Vec<u8>> {
- let mut o = Vec::with_capacity(16 + self.value.len());
+ let mut o = Vec::with_capacity(16 + self.userid().len());
// Writing to a vec can't fail.
self.serialize(&mut o)?;
Ok(o)
diff --git a/openpgp/src/tpk/builder.rs b/openpgp/src/tpk/builder.rs
index ff932ade..caf85b0b 100644
--- a/openpgp/src/tpk/builder.rs
+++ b/openpgp/src/tpk/builder.rs
@@ -153,7 +153,6 @@ impl TPKBuilder {
pub fn generate(mut self) -> Result<(TPK, Signature)> {
use {PacketPile, Packet};
use constants::ReasonForRevocation;
- use packet::Common;
let mut packets = Vec::<Packet>::with_capacity(
1 + 1 + self.subkeys.len() + self.userids.len());
@@ -164,11 +163,8 @@ impl TPKBuilder {
}
// select the first UserID as primary, if present
- let maybe_first_uid = self.userids.first().cloned().map(|uid| {
- UserID{
- common: Common::default(),
- value: uid.as_bytes().into(),
- }
+ let maybe_first_uid = self.userids.first().map(|uid| {
+ UserID::from(uid.as_str())
});
// Generate & and self-sign primary key.
let (primary, sig) = Self::primary_key(
@@ -192,10 +188,7 @@ impl TPKBuilder {
// sign UserIDs. First UID was used as primary keys self-sig
if !self.userids.is_empty() {
for uid in self.userids[1..].iter() {
- let uid = UserID{
- common: Common::default(),
- value: uid.as_bytes().into(),
- };
+ let uid = UserID::from(uid.as_str());
let sig = Self::userid(&uid, &primary)?;
packets.push(Packet::UserID(uid));
@@ -377,7 +370,7 @@ mod tests {
.generate().unwrap();
let mut userids = tpk.userids()
- .map(|u| String::from_utf8_lossy(&u.userid.value[..]).into_owned())
+ .map(|u| String::from_utf8_lossy(u.userid.userid()).into_owned())
.collect::<Vec<String>>();
userids.sort();
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 1615cb8f..c4c60b73 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -1734,7 +1734,7 @@ impl TPK {
// one copy might be sorted to the front and the other to the
// back, and the following dedup wouldn't combine the user
// ids!
- self.userids.sort_by(|a, b| a.userid.value.cmp(&b.userid.value));
+ self.userids.sort_by(|a, b| a.userid.userid().cmp(&b.userid.userid()));
// Then, we dedup them.
self.userids.dedup_by(|a, b| {
@@ -1854,7 +1854,7 @@ impl TPK {
}
// Fallback to a lexicographical comparison.
- a.userid.value.cmp(&b.userid.value)
+ a.userid.userid().cmp(&b.userid.userid())
});
@@ -2540,7 +2540,7 @@ mod test {
i == 0).unwrap();
assert_eq!(tpk.primary.creation_time().to_pgp().unwrap(), 1511355130);
assert_eq!(tpk.userids.len(), 1);
- assert_eq!(tpk.userids[0].userid.value,
+ assert_eq!(tpk.userids[0].userid.userid(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(tpk.userids[0].selfsigs.len(), 1);
assert_eq!(tpk.userids[0].selfsigs[0].hash_prefix,
@@ -2561,7 +2561,7 @@ mod test {
"3E8877C877274692975189F5D03F6F865226FE8B");
assert_eq!(tpk.userids.len(), 1, "number of userids");
- assert_eq!(tpk.userids[0].userid.value,
+ assert_eq!(tpk.userids[0].userid.userid(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(tpk.userids[0].selfsigs.len(), 1);
assert_eq!(tpk.userids[0].selfsigs[0].hash_prefix,
@@ -2584,7 +2584,7 @@ mod test {
assert_eq!(tpk.user_attributes.len(), 0);
assert_eq!(tpk.userids.len(), 1, "number of userids");
- assert_eq!(tpk.userids[0].userid.value,
+ assert_eq!(tpk.userids[0].userid.userid(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(tpk.userids[0].selfsigs.len(), 1);
assert_eq!(tpk.userids[0].selfsigs[0].hash_prefix,
@@ -2823,7 +2823,7 @@ mod test {
let tpk = TPK::from_bytes(bytes!("neal-sigs-out-of-order.pgp")).unwrap();
let mut userids = tpk.userids()
- .map(|u| String::from_utf8_lossy(&u.userid.value[..]).into_owned())
+ .map(|u| String::from_utf8_lossy(u.userid.userid()).into_owned())
.collect::<Vec<String>>();
userids.sort();
@@ -2851,7 +2851,7 @@ mod test {
let tpk = TPK::from_bytes(bytes!("dkg-sigs-out-of-order.pgp")).unwrap();
let mut userids = tpk.userids()
- .map(|u| String::from_utf8_lossy(&u.userid.value[..]).into_owned())
+ .map(|u| String::from_utf8_lossy(u.userid.userid()).into_owned())
.collect::<Vec<String>>();
userids.sort();