summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-03-21 16:10:26 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-03-21 16:39:30 +0100
commit7accf308157ed448095590a4d1763a99fb075537 (patch)
treea659e1de592b14f6d5b9745a7eeb9d1de25cd290 /openpgp
parent1e579754f0a2b21aabefcd73f51145cc33f820cd (diff)
openpgp: Rename UserAttribute's accessors.
- See #224.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/crypto/hash.rs4
-rw-r--r--openpgp/src/packet/user_attribute.rs16
-rw-r--r--openpgp/src/serialize/mod.rs8
-rw-r--r--openpgp/src/tpk/mod.rs8
-rw-r--r--openpgp/src/tsk.rs2
5 files changed, 22 insertions, 16 deletions
diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs
index e89d6df4..d2dcd4a9 100644
--- a/openpgp/src/crypto/hash.rs
+++ b/openpgp/src/crypto/hash.rs
@@ -163,14 +163,14 @@ impl Hash for UserAttribute {
let mut header = [0; 5];
header[0] = 0xD1;
- let len = self.user_attribute().len() as u32;
+ let len = self.value().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.user_attribute());
+ hash.update(self.value());
}
}
diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs
index d67a11bd..716faa20 100644
--- a/openpgp/src/packet/user_attribute.rs
+++ b/openpgp/src/packet/user_attribute.rs
@@ -57,14 +57,20 @@ impl UserAttribute {
}
}
- /// Gets the user attribute packet's value.
- pub fn user_attribute(&self) -> &[u8] {
+ /// Gets the user attribute packet's raw, unparsed value.
+ ///
+ /// Most likely you will want to use [`subpackets()`] to iterate
+ /// over the subpackets.
+ ///
+ /// [`subpackets()`]: #method.subpackets
+ pub fn value(&self) -> &[u8] {
self.value.as_slice()
}
- /// Sets the user attribute packet's value from a byte sequence.
- pub fn set_user_attribute(&mut self, value: &[u8]) -> Vec<u8> {
- ::std::mem::replace(&mut self.value, value.to_vec())
+ /// Gets a mutable reference to the user attribute packet's raw
+ /// value.
+ pub fn value_mut(&mut self) -> &mut Vec<u8> {
+ &mut self.value
}
/// Iterates over the subpackets.
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 39083586..9813df47 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1288,11 +1288,11 @@ impl SerializeInto for UserID {
impl Serialize for UserAttribute {
fn serialize<W: io::Write>(&self, o: &mut W) -> Result<()> {
- let len = self.user_attribute().len();
+ let len = self.value().len();
CTB::new(Tag::UserAttribute).serialize(o)?;
BodyLength::Full(len as u32).serialize(o)?;
- o.write_all(self.user_attribute())?;
+ o.write_all(self.value())?;
Ok(())
}
@@ -1300,8 +1300,8 @@ impl Serialize for UserAttribute {
impl SerializeInto for UserAttribute {
fn serialized_len(&self) -> usize {
- 1 + BodyLength::Full(self.user_attribute().len() as u32)
- .serialized_len() + self.user_attribute().len()
+ 1 + BodyLength::Full(self.value().len() as u32)
+ .serialized_len() + self.value().len()
}
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize> {
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 20638577..ace1d19a 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -2426,8 +2426,8 @@ impl TPK {
// for the user ids, we can't do the final sort here, because
// we rely on the self-signatures.
self.user_attributes.sort_by(
- |a, b| a.user_attribute.user_attribute()
- .cmp(&b.user_attribute.user_attribute()));
+ |a, b| a.user_attribute.value()
+ .cmp(&b.user_attribute.value()));
// And, dedup them.
self.user_attributes.dedup_by(|a, b| {
@@ -2529,8 +2529,8 @@ impl TPK {
}
// Fallback to a lexicographical comparison.
- a.user_attribute.user_attribute()
- .cmp(&b.user_attribute.user_attribute())
+ a.user_attribute.value()
+ .cmp(&b.user_attribute.value())
});
diff --git a/openpgp/src/tsk.rs b/openpgp/src/tsk.rs
index 080a9431..fd84fbe4 100644
--- a/openpgp/src/tsk.rs
+++ b/openpgp/src/tsk.rs
@@ -511,7 +511,7 @@ mod tests {
.unwrap();
let userattrs = tsk
.user_attributes()
- .map(|binding| binding.user_attribute().user_attribute())
+ .map(|binding| binding.user_attribute().value())
.collect::<Vec<_>>();
assert_eq!(userattrs.len(), 1);