summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2022-06-09 10:10:22 +0200
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2022-06-10 11:37:25 +0200
commit4cc34996b76e20ace511d40d8013abdd21e5b5a3 (patch)
tree0d8a611a2eb65858ec660d232b4b326c71babf8a
parent68d546f9f2656595ca5fef3ba405a13155d87642 (diff)
openpgp: Provide short curve names by default.
- Leave long names as alternate format.
-rw-r--r--openpgp/src/types/mod.rs58
1 files changed, 46 insertions, 12 deletions
diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs
index 7e7c3032..8b03ad2f 100644
--- a/openpgp/src/types/mod.rs
+++ b/openpgp/src/types/mod.rs
@@ -390,21 +390,55 @@ impl Curve {
}
}
+/// Formats the elliptic curve name.
+///
+/// There are two ways the elliptic curve name can be formatted. By
+/// default the short name is used. The alternate format uses the
+/// full curve name.
+///
+/// # Examples
+///
+/// ```
+/// use sequoia_openpgp as openpgp;
+/// use openpgp::types::Curve;
+///
+/// // default, short format
+/// assert_eq!("NIST P-256", format!("{}", Curve::NistP256));
+///
+/// // alternate, long format
+/// assert_eq!("NIST curve P-256", format!("{:#}", Curve::NistP256));
+/// ```
impl fmt::Display for Curve {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Curve::*;
- match *self {
- NistP256 => f.write_str("NIST curve P-256"),
- NistP384 => f.write_str("NIST curve P-384"),
- NistP521 => f.write_str("NIST curve P-521"),
- BrainpoolP256 => f.write_str("brainpoolP256r1"),
- BrainpoolP512 => f.write_str("brainpoolP512r1"),
- Ed25519
- => f.write_str("D.J. Bernstein's \"Twisted\" Edwards curve Ed25519"),
- Cv25519
- => f.write_str("Elliptic curve Diffie-Hellman using D.J. Bernstein's Curve25519"),
- Unknown(ref oid)
- => write!(f, "Unknown curve (OID: {:?})", oid),
+ if f.alternate() {
+ match *self {
+ NistP256 => f.write_str("NIST curve P-256"),
+ NistP384 => f.write_str("NIST curve P-384"),
+ NistP521 => f.write_str("NIST curve P-521"),
+ BrainpoolP256 => f.write_str("brainpoolP256r1"),
+ BrainpoolP512 => f.write_str("brainpoolP512r1"),
+ Ed25519
+ => f.write_str("D.J. Bernstein's \"Twisted\" Edwards curve Ed25519"),
+ Cv25519
+ => f.write_str("Elliptic curve Diffie-Hellman using D.J. Bernstein's Curve25519"),
+ Unknown(ref oid)
+ => write!(f, "Unknown curve (OID: {:?})", oid),
+ }
+ } else {
+ match *self {
+ NistP256 => f.write_str("NIST P-256"),
+ NistP384 => f.write_str("NIST P-384"),
+ NistP521 => f.write_str("NIST P-521"),
+ BrainpoolP256 => f.write_str("brainpoolP256r1"),
+ BrainpoolP512 => f.write_str("brainpoolP512r1"),
+ Ed25519
+ => f.write_str("Ed25519"),
+ Cv25519
+ => f.write_str("Curve25519"),
+ Unknown(ref oid)
+ => write!(f, "Unknown curve {:?}", oid),
+ }
}
}
}