Enum sequoia_openpgp::types::Curve

source ·
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§

§

NistP256

NIST curve P-256.

§

NistP384

NIST curve P-384.

§

NistP521

NIST curve P-521.

§

BrainpoolP256

brainpoolP256r1.

§

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

source

pub fn bits(&self) -> Option<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.

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);
source

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

source

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])));
source

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]);
source

pub fn len(&self) -> Result<usize>

👎Deprecated since 1.17.0: Use bits()

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.

source

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());
source

pub fn variants() -> impl Iterator<Item = Self>

Returns an iterator over all valid variants.

Returns an iterator over all known variants. This does not include the Curve::Unknown variant, except to include BrainpoolP384 which is missing from Curve.

Trait Implementations§

source§

impl Clone for Curve

source§

fn clone(&self) -> Curve

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Curve

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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));
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Curve

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Curve

source§

fn cmp(&self, other: &Curve) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Curve

source§

fn eq(&self, other: &Curve) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Curve

source§

fn partial_cmp(&self, other: &Curve) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Curve

source§

impl StructuralPartialEq for Curve

Auto Trait Implementations§

§

impl Freeze for Curve

§

impl RefUnwindSafe for Curve

§

impl Send for Curve

§

impl Sync for Curve

§

impl Unpin for Curve

§

impl UnwindSafe for Curve

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.