summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openpgp/src/packet/literal.rs25
-rw-r--r--openpgp/src/parse/parse.rs2
-rw-r--r--openpgp/src/serialize/stream.rs2
3 files changed, 9 insertions, 20 deletions
diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs
index b384e62f..fa97d3e3 100644
--- a/openpgp/src/packet/literal.rs
+++ b/openpgp/src/packet/literal.rs
@@ -109,7 +109,7 @@ impl Literal {
self.filename.as_ref().map(|b| b.as_slice())
}
- /// Sets the literal packet's filename field from a byte sequence.
+ /// Sets the literal packet's filename field.
///
/// The standard does not specify the encoding. Filenames must
/// not be longer than 255 bytes.
@@ -117,8 +117,11 @@ impl Literal {
/// Note: when a literal data packet is protected by a signature,
/// only the literal data packet's body is protected, not the
/// meta-data. As such, this field should not be used.
- pub fn set_filename_from_bytes(&mut self, filename: &[u8])
- -> Result<Option<Vec<u8>>> {
+ pub fn set_filename<F>(&mut self, filename: F)
+ -> Result<Option<Vec<u8>>>
+ where F: AsRef<[u8]>
+ {
+ let filename = filename.as_ref();
Ok(::std::mem::replace(&mut self.filename, match filename.len() {
0 => None,
1..=255 => Some(filename.to_vec()),
@@ -128,20 +131,6 @@ impl Literal {
}))
}
- /// Sets the literal packet's filename field from a UTF-8 encoded
- /// string.
- ///
- /// This is a convenience function, since the field is actually a
- /// raw byte string. Filenames must not be longer than 255 bytes.
- ///
- /// Note: when a literal data packet is protected by a signature,
- /// only the literal data packet's body is protected, not the
- /// meta-data. As such, this field should not be used.
- pub fn set_filename(&mut self, filename: &str)
- -> Result<Option<Vec<u8>>> {
- self.set_filename_from_bytes(filename.as_bytes())
- }
-
/// Gets the literal packet's date field.
///
/// Note: when a literal data packet is protected by a signature,
@@ -184,7 +173,7 @@ impl Arbitrary for Literal {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let mut l = Literal::new(DataFormat::arbitrary(g));
l.set_body(Vec::<u8>::arbitrary(g));
- while let Err(_) = l.set_filename_from_bytes(&Vec::<u8>::arbitrary(g)) {
+ while let Err(_) = l.set_filename(&Vec::<u8>::arbitrary(g)) {
// Too long, try again.
}
l.set_date(Some(Timestamp::arbitrary(g).into())).unwrap();
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 4776ba0a..a06a710c 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1715,7 +1715,7 @@ impl Literal {
let mut literal = Literal::new(format.into());
if let Some(filename) = filename {
- literal.set_filename_from_bytes(&filename)
+ literal.set_filename(&filename)
.expect("length checked above");
}
literal.set_date(
diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs
index 2b53cb7a..40b18984 100644
--- a/openpgp/src/serialize/stream.rs
+++ b/openpgp/src/serialize/stream.rs
@@ -578,7 +578,7 @@ impl<'a> LiteralWriter<'a> {
/// The standard does not specify the encoding. Filenames must
/// not be longer than 255 bytes.
pub fn filename<B: AsRef<[u8]>>(mut self, filename: B) -> Result<Self> {
- self.template.set_filename_from_bytes(filename.as_ref())?;
+ self.template.set_filename(filename.as_ref())?;
Ok(self)
}