summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2022-06-09 10:21:39 +0200
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2022-06-10 11:37:29 +0200
commitca93d5c5a6a5a61e1427c836f531abe3f39cac6d (patch)
treefb9021b90ef8885fdd1bfd7eee41c176f96ca91c
parent051588e6f8b274df67e4ffdcc97530a186a7bf1a (diff)
openpgp: Provide short names for AEADAlgorithm.
- Long names are still supported using the alternate format specifier. - Update NEWS file. - Fixes #803.
-rw-r--r--openpgp/NEWS4
-rw-r--r--openpgp/src/types/mod.rs49
2 files changed, 44 insertions, 9 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS
index c85c0177..8e9eb474 100644
--- a/openpgp/NEWS
+++ b/openpgp/NEWS
@@ -6,6 +6,10 @@
** New functionality
- Error::UnsupportedCert2
- TryFrom<Packet> for Unknown
+ - types::{Curve, SymmetricAlgorithm, AEADAlgorithm,
+ PublicKeyAlgorithm}'s Display implementation now provides short
+ names by default. The long descriptions are provided by the
+ alternate formatter (e.g. =format!("{:#}", ...)=)
** Deprecated functionality
- Error::UnsupportedCert, use Error::UnsupportedCert2 instead
- DataFormat::MIME, no replacement, see #863 for details
diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs
index ec452cdc..f949c506 100644
--- a/openpgp/src/types/mod.rs
+++ b/openpgp/src/types/mod.rs
@@ -868,17 +868,48 @@ impl From<AEADAlgorithm> for u8 {
}
}
+/// Formats the AEAD algorithm name.
+///
+/// There are two ways the AEAD algorithm name can be formatted. By
+/// default the short name is used. The alternate format uses the
+/// full algorithm name.
+///
+/// # Examples
+///
+/// ```
+/// use sequoia_openpgp as openpgp;
+/// use openpgp::types::AEADAlgorithm;
+///
+/// // default, short format
+/// assert_eq!("EAX", format!("{}", AEADAlgorithm::EAX));
+///
+/// // alternate, long format
+/// assert_eq!("EAX mode", format!("{:#}", AEADAlgorithm::EAX));
+/// ```
impl fmt::Display for AEADAlgorithm {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match *self {
- AEADAlgorithm::EAX =>
- f.write_str("EAX mode"),
- AEADAlgorithm::OCB =>
- f.write_str("OCB mode"),
- AEADAlgorithm::Private(u) =>
- f.write_fmt(format_args!("Private/Experimental AEAD algorithm {}", u)),
- AEADAlgorithm::Unknown(u) =>
- f.write_fmt(format_args!("Unknown AEAD algorithm {}", u)),
+ if f.alternate() {
+ match *self {
+ AEADAlgorithm::EAX =>
+ f.write_str("EAX mode"),
+ AEADAlgorithm::OCB =>
+ f.write_str("OCB mode"),
+ AEADAlgorithm::Private(u) =>
+ f.write_fmt(format_args!("Private/Experimental AEAD algorithm {}", u)),
+ AEADAlgorithm::Unknown(u) =>
+ f.write_fmt(format_args!("Unknown AEAD algorithm {}", u)),
+ }
+ } else {
+ match *self {
+ AEADAlgorithm::EAX =>
+ f.write_str("EAX"),
+ AEADAlgorithm::OCB =>
+ f.write_str("OCB"),
+ AEADAlgorithm::Private(u) =>
+ f.write_fmt(format_args!("Private AEAD algo {}", u)),
+ AEADAlgorithm::Unknown(u) =>
+ f.write_fmt(format_args!("Unknown AEAD algo {}", u)),
+ }
}
}
}