Enum sequoia_openpgp::types::Curve [−][src]
pub enum Curve { NistP256, NistP384, NistP521, BrainpoolP256, BrainpoolP512, Ed25519, Cv25519, Unknown(Box<[u8]>), }
Expand description
Elliptic curves used in OpenPGP.
PublicKeyAlgorithm
does not differentiate between elliptic
curves. Instead, the curve is specified using an OID prepended to
the key material. We provide this type to be able to match on the
curves.
Note: This enum cannot be exhaustively matched to allow future extensions.
Variants
NIST curve P-256.
NIST curve P-384.
NIST curve P-521.
brainpoolP256r1.
brainpoolP512r1.
D.J. Bernstein’s “Twisted” Edwards curve Ed25519.
Elliptic curve Diffie-Hellman using D.J. Bernstein’s Curve25519.
Unknown curve.
Implementations
Returns the length of public keys over this curve in bits.
For the Kobliz curves this is the size of the underlying finite field. For X25519 it is 256.
Note: This information is useless and should not be used to gauge the security of a particular curve. This function exists only because some legacy PGP application like HKP need it.
Returns None
for unknown curves.
Examples
use sequoia_openpgp as openpgp; use openpgp::types::Curve; assert_eq!(Curve::NistP256.bits(), Some(256)); assert_eq!(Curve::NistP384.bits(), Some(384)); assert_eq!(Curve::Ed25519.bits(), Some(256)); assert_eq!(Curve::Unknown(Box::new([0x2B, 0x11])).bits(), None);
Parses the given OID.
Examples
use sequoia_openpgp as openpgp; use openpgp::types::Curve; assert_eq!(Curve::from_oid(&[0x2B, 0x81, 0x04, 0x00, 0x22]), Curve::NistP384); assert_eq!(Curve::from_oid(&[0x2B, 0x11]), Curve::Unknown(Box::new([0x2B, 0x11])));
Returns this curve’s OID.
Examples
use sequoia_openpgp as openpgp; use openpgp::types::Curve; assert_eq!(Curve::NistP384.oid(), &[0x2B, 0x81, 0x04, 0x00, 0x22]); assert_eq!(Curve::Unknown(Box::new([0x2B, 0x11])).oid(), &[0x2B, 0x11]);
Returns the length of a coordinate in bits.
Examples
use sequoia_openpgp as openpgp; use openpgp::types::Curve; assert!(if let Ok(256) = Curve::NistP256.len() { true } else { false }); assert!(if let Ok(384) = Curve::NistP384.len() { true } else { false }); assert!(if let Ok(256) = Curve::Ed25519.len() { true } else { false }); assert!(if let Err(_) = Curve::Unknown(Box::new([0x2B, 0x11])).len() { true } else { false });
Errors
Returns Error::UnsupportedEllipticCurve
if the curve is not
supported.
Returns whether this algorithm is supported.
Examples
use sequoia_openpgp as openpgp; use openpgp::types::Curve; assert!(Curve::NistP256.is_supported()); assert!(Curve::NistP384.is_supported()); assert!(Curve::Ed25519.is_supported()); assert!(!Curve::Unknown(Box::new([0x2B, 0x11])).is_supported());
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Curve
impl UnwindSafe for Curve
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self