summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-06 16:21:22 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-06 16:21:22 +0100
commit3090a8b9ac820b0cca024cfe0bc3f858ab6778a6 (patch)
tree1bd662ba46f830d92f869c345aeffb87a6820f05 /openpgp
parentc99f7bbc3d59faa243af8f816496e78dada2c962 (diff)
openpgp: Notation data keys are UTF-8 strings.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/signature/subpacket.rs18
-rw-r--r--openpgp/src/parse/parse.rs3
-rw-r--r--openpgp/src/serialize/mod.rs2
3 files changed, 12 insertions, 11 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 43446a5c..bea12c00 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -480,14 +480,14 @@ impl SubpacketArea {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct NotationData {
flags: NotationDataFlags,
- name: Vec<u8>,
+ name: String,
value: Vec<u8>,
}
impl NotationData {
/// Creates a new Notation Data subpacket payload.
pub fn new<N, F>(name: N, value: &[u8], flags: F) -> Self
- where N: AsRef<[u8]>,
+ where N: AsRef<str>,
F: Into<Option<NotationDataFlags>>,
{
Self {
@@ -503,7 +503,7 @@ impl NotationData {
}
/// Returns the name.
- pub fn name(&self) -> &[u8] {
+ pub fn name(&self) -> &str {
&self.name
}
@@ -1206,7 +1206,7 @@ impl SubpacketArea {
self.subpackets(SubpacketTag::NotationData)
.into_iter().filter_map(|s| match s.value {
SubpacketValue::NotationData(ref v)
- if v.name == name.as_bytes() => Some(&v.value[..]),
+ if v.name == name => Some(&v.value[..]),
_ => None,
})
.collect()
@@ -2046,7 +2046,7 @@ impl signature::Builder {
self.hashed_area.packets.retain(|s| {
match s.value {
SubpacketValue::NotationData(ref v)
- if v.name == name.as_bytes() => false,
+ if v.name == name => false,
_ => true,
}
});
@@ -2740,7 +2740,7 @@ fn subpacket_test_2() {
let n = NotationData {
flags: NotationDataFlags::default().set_human_readable(true),
- name: b"rank@navy.mil".to_vec(),
+ name: "rank@navy.mil".into(),
value: b"midshipman".to_vec()
};
assert_eq!(sig.notation_data(), vec![&n]);
@@ -2922,17 +2922,17 @@ fn subpacket_test_2() {
let n1 = NotationData {
flags: NotationDataFlags::default().set_human_readable(true),
- name: b"rank@navy.mil".to_vec(),
+ name: "rank@navy.mil".into(),
value: b"third lieutenant".to_vec()
};
let n2 = NotationData {
flags: NotationDataFlags::default().set_human_readable(true),
- name: b"foo@navy.mil".to_vec(),
+ name: "foo@navy.mil".into(),
value: b"bar".to_vec()
};
let n3 = NotationData {
flags: NotationDataFlags::default().set_human_readable(true),
- name: b"whistleblower@navy.mil".to_vec(),
+ name: "whistleblower@navy.mil".into(),
value: b"true".to_vec()
};
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index dd0b8789..1f47bf99 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1301,7 +1301,8 @@ impl Subpacket {
}
SubpacketValue::NotationData(
NotationData::new(
- &php.parse_bytes("notation name", name_len)?,
+ std::str::from_utf8(
+ &php.parse_bytes("notation name", name_len)?)?,
&php.parse_bytes("notation value", value_len)?,
Some(flags.into())))
},
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index a4ea223c..20e5b92f 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1023,7 +1023,7 @@ impl Serialize for SubpacketValue {
write_be_u32(o, nd.flags().raw())?;
write_be_u16(o, nd.name().len() as u16)?;
write_be_u16(o, nd.value().len() as u16)?;
- o.write_all(nd.name())?;
+ o.write_all(nd.name().as_bytes())?;
o.write_all(nd.value())?;
},
PreferredHashAlgorithms(ref p) =>