#[non_exhaustive]pub enum Curve {
NistP256,
NistP384,
NistP521,
BrainpoolP256,
BrainpoolP384,
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.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NistP256
NIST curve P-256.
NistP384
NIST curve P-384.
NistP521
NIST curve P-521.
BrainpoolP256
brainpoolP256r1.
BrainpoolP384
brainpoolP384r1.
BrainpoolP512
brainpoolP512r1.
Ed25519
D.J. Bernstein’s “Twisted” Edwards curve Ed25519.
Cv25519
Elliptic curve Diffie-Hellman using D.J. Bernstein’s Curve25519.
Unknown(Box<[u8]>)
Unknown curve.
Implementations§
Source§impl Curve
impl Curve
Sourcepub fn bits(&self) -> Result<usize>
pub fn bits(&self) -> Result<usize>
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.
This value is also equal to the length of a coordinate in bits.
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.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Curve;
assert_eq!(Curve::NistP256.bits()?, 256);
assert_eq!(Curve::NistP384.bits()?, 384);
assert_eq!(Curve::Ed25519.bits()?, 256);
assert!(Curve::Unknown(Box::new([0x2B, 0x11])).bits().is_err());
Sourcepub fn field_size(&self) -> Result<usize>
pub fn field_size(&self) -> Result<usize>
Returns the curve’s field size in bytes.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Curve;
assert_eq!(Curve::NistP256.field_size()?, 32);
assert_eq!(Curve::NistP384.field_size()?, 48);
assert_eq!(Curve::NistP521.field_size()?, 66);
assert_eq!(Curve::Ed25519.field_size()?, 32);
assert!(Curve::Unknown(Box::new([0x2B, 0x11])).field_size().is_err());
Source§impl Curve
impl Curve
Sourcepub fn from_oid(oid: &[u8]) -> Curve
pub fn from_oid(oid: &[u8]) -> Curve
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])));
Sourcepub fn oid(&self) -> &[u8] ⓘ
pub fn oid(&self) -> &[u8] ⓘ
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]);
Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
Returns whether this algorithm is supported.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::types::Curve;
assert!(Curve::Ed25519.is_supported());
assert!(!Curve::Unknown(Box::new([0x2B, 0x11])).is_supported());
Trait Implementations§
Source§impl Display for Curve
Formats the elliptic curve name.
impl Display for 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));