Serializes OpenPGP data structures.
This trait provides the same interface as the
Marshal trait (in
fact, it is just a wrapper around that trait), but only data
structures that it makes sense to export implement it.
Having a separate trait for data structures that it makes sense to export avoids an easy-to-make and hard-to-debug bug: inadvertently exporting an OpenPGP data structure without any framing information.
This bug is easy to make, because Rust infers types, which means that it is often not clear from the immediate context exactly what is being serialized. This bug is hard to debug, because errors parsing data that has been incorrectly exported, are removed from the serialization code.
The following example shows how to correctly export a revocation certificate. It should make clear how easy it is to forget to convert a bare signature into an OpenPGP packet before serializing it:
use openpgp::cert::prelude::*; use openpgp::Packet; use openpgp::serialize::Serialize; let (_cert, rev) = CertBuilder::general_purpose(None, Some("email@example.com")) .generate()?; let rev : Packet = rev.into(); rev.serialize(output)?;
Note: if you
Marshal, then, because
they both have the same methods, and all data structures that
Serialize also implement
Marshal, you will have to
use the Universal Function Call Syntax (UFCS) to call the methods
on those objects, for example:
If you really needed
Marshal, we strongly recommend importing it
in as small a scope as possible to avoid this, and to avoid
accidentally exporting data without the required framing.
Writes a serialized version of the object to
Exports a serialized version of the object to
This is similar to
serialize(..), with these exceptions: