ecdsa.curves module

class ecdsa.curves.Curve(name, curve, generator, oid, openssl_name=None)[source]

Bases: object

static from_der(data, valid_encodings=None)[source]

Decode the curve parameters from DER file.

Parameters:
  • data (bytes-like object) – the binary string to decode the parameters from

  • valid_encodings (set-like object) – set of names of allowed encodings, by default all (set by passing None), supported ones are named_curve and explicit

classmethod from_pem(string, valid_encodings=None)[source]

Decode the curve parameters from PEM file.

Parameters:
  • string (str) – the text string to decode the parameters from

  • valid_encodings (set-like object) – set of names of allowed encodings, by default all (set by passing None), supported ones are named_curve and explicit

to_der(encoding=None, point_encoding='uncompressed')[source]

Serialise the curve parameters to binary string.

Parameters:
  • encoding (str) – the format to save the curve parameters in. Default is named_curve, with fallback being the explicit if the OID is not set for the curve.

  • point_encoding (str) – the point encoding of the generator when explicit curve encoding is used. Ignored for named_curve format.

Returns:

DER encoded ECParameters structure

Return type:

bytes

to_pem(encoding=None, point_encoding='uncompressed')[source]

Serialise the curve parameters to the PEM format.

Parameters:
  • encoding (str) – the format to save the curve parameters in. Default is named_curve, with fallback being the explicit if the OID is not set for the curve.

  • point_encoding (str) – the point encoding of the generator when explicit curve encoding is used. Ignored for named_curve format.

Returns:

PEM encoded ECParameters structure

Return type:

str

exception ecdsa.curves.UnknownCurveError[source]

Bases: Exception

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

ecdsa.curves.curve_by_name(name)[source]

Select a curve based on its name.

Returns a Curve object with a name name. Note that name is case-sensitve.

Parameters:

name (str) – Name of the curve to return, like NIST256p or prime256v1

Raises:

UnknownCurveError – When the name doesn’t match any of the supported curves

Return type:

Curve

ecdsa.curves.find_curve(oid_curve)[source]

Select a curve based on its OID

Parameters:

oid_curve (tuple[int,...]) – ASN.1 Object Identifier of the curve to return, like (1, 2, 840, 10045, 3, 1, 7) for NIST256p.

Raises:

UnknownCurveError – When the oid doesn’t match any of the supported curves

Return type:

Curve

ecdsa.curves.orderlen(order)[source]