diff options
author | Justus Winter <justus@pep-project.org> | 2017-11-03 10:49:09 +0100 |
---|---|---|
committer | Justus Winter <justus@pep-project.org> | 2017-11-22 14:48:43 +0100 |
commit | 5aac6d12035ce749afcfb5a577694f957ee18c68 (patch) | |
tree | c5cfa92a0085a56f58688d13436a0052f1c4fd96 /src | |
parent | 1c9cefa15cf41559afa4b646126582b42a58de84 (diff) |
Add convenience function to parse files.
- Given a file, return an OpenPGP message object.
Diffstat (limited to 'src')
-rw-r--r-- | src/openpgp/parse/parse.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/openpgp/parse/parse.rs b/src/openpgp/parse/parse.rs index 6cfbddc5..5a2e59bb 100644 --- a/src/openpgp/parse/parse.rs +++ b/src/openpgp/parse/parse.rs @@ -1,4 +1,5 @@ use std; +use std::fs::File; use std::io::{Error,ErrorKind}; use num::FromPrimitive; @@ -485,6 +486,12 @@ impl Message { packets: packets, }) } + + pub fn from_file(mut file: File) -> Result<Message, std::io::Error> { + let mut bio = BufferedReaderGeneric::new(&mut file, None); + Message::deserialize(&mut bio) + } + } } #[test] @@ -512,7 +519,6 @@ fn deserialize_test () { // A message containing a compressed packet that contains a // literal packet. use std::path::PathBuf; - use std::fs::File; let path : PathBuf = [env!("CARGO_MANIFEST_DIR"), "src", "openpgp", "parse", |