koi_net.protocol.secure

Functions

der_to_raw_signature(der_signature[, curve])

Converts a DER-encoded signature to raw r||s format.

raw_to_der_signature(raw_signature[, curve])

Converts a raw r||s signature to DER format.

Classes

PrivateKey(priv_key)

PublicKey(pub_key)

class koi_net.protocol.secure.PrivateKey(priv_key)[source]

Bases: object

Parameters:

priv_key (EllipticCurvePrivateKey)

classmethod from_pem(priv_key_pem, password)[source]

Loads PrivateKey from encrypted PEM string.

Parameters:
  • priv_key_pem (str)

  • password (str)

classmethod generate()[source]

Generates a new Private Key.

priv_key: EllipticCurvePrivateKey
public_key()[source]

Returns instance of PublicKey dervied from this private key.

Return type:

PublicKey

sign(message)[source]

Returns base64 encoded raw signature bytes of the form r||s.

Return type:

str

Parameters:

message (bytes)

to_pem(password)[source]

Saves PrivateKey to encrypted PEM string.

Return type:

str

Parameters:

password (str)

class koi_net.protocol.secure.PublicKey(pub_key)[source]

Bases: object

Parameters:

pub_key (EllipticCurvePublicKey)

classmethod from_der(pub_key_der)[source]

Loads PublicKey from base64 encoded DER string.

Parameters:

pub_key_der (str)

classmethod from_pem(pub_key_pem)[source]

Loads PublicKey from PEM string.

Parameters:

pub_key_pem (str)

pub_key: EllipticCurvePublicKey
to_der()[source]

Saves PublicKey to base64 encoded DER string.

Return type:

str

to_node_rid(name)[source]

Returns an orn:koi-net.node RID from hashed DER string.

Return type:

KoiNetNode

to_pem()[source]

Saves PublicKey to PEM string.

Return type:

str

verify(signature, message)[source]

Verifies a signature for a message.

Raises cryptography.exceptions.InvalidSignature on failure.

Parameters:
  • signature (str)

  • message (bytes)

koi_net.protocol.secure.der_to_raw_signature(der_signature, curve=<cryptography.hazmat.primitives.asymmetric.ec.SECP256R1 object>)[source]

Converts a DER-encoded signature to raw r||s format.

Return type:

bytes

Parameters:

der_signature (bytes)

koi_net.protocol.secure.raw_to_der_signature(raw_signature, curve=<cryptography.hazmat.primitives.asymmetric.ec.SECP256R1 object>)[source]

Converts a raw r||s signature to DER format.

Return type:

bytes

Parameters:

raw_signature (bytes)