summaryrefslogtreecommitdiffstats
path: root/openpgp/src/types
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 /openpgp/src/types
parent051588e6f8b274df67e4ffdcc97530a186a7bf1a (diff)
openpgp: Provide short names for AEADAlgorithm.
- Long names are still supported using the alternate format specifier. - Update NEWS file. - Fixes #803.
Diffstat (limited to 'openpgp/src/types')
-rw-r--r--openpgp/src/types/mod.rs49
1 files changed, 40 insertions, 9 deletions
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)),
+ }
}
}
}