Enum sequoia_openpgp::types::Curve[][src]

pub enum Curve {
    NistP256,
    NistP384,
    NistP521,
    BrainpoolP256,
    BrainpoolP512,
    Ed25519,
    Cv25519,
    Unknown(Box<[u8]>),
}

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

impl Curve[src]

pub fn bits(&self) -> Option<usize>[src]

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

impl Curve[src]

pub fn from_oid(oid: &[u8]) -> Curve[src]

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

pub fn oid(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

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

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

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.

pub fn is_supported(&self) -> bool[src]

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

impl Clone for Curve[src]

fn clone(&self) -> Curve[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Curve[src]

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

Formats the value using the given formatter. Read more

impl Display for Curve[src]

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

Formats the value using the given formatter. Read more

impl Hash for Curve[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl Ord for Curve[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Curve> for Curve[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Curve) -> bool[src]

This method tests for !=.

impl PartialOrd<Curve> for Curve[src]

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl Eq for Curve[src]

impl StructuralEq for Curve[src]

impl StructuralPartialEq for Curve[src]

Auto Trait Implementations

impl RefUnwindSafe for Curve

impl Send for Curve

impl Sync for Curve

impl Unpin for Curve

impl UnwindSafe for Curve

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> DynClone for T where
    T: Clone
[src]

pub fn __clone_box(&self, Private) -> *mut ()[src]

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.