Class: Linzer::Ed25519::Key

Inherits:
Key
  • Object
show all
Defined in:
lib/linzer/ed25519.rb

Overview

Ed25519 signing key implementation.

Ed25519 keys can be used for both signing (with private key) and verification (with public key). The algorithm identifier is ed25519.

Examples:

Generating a new key pair

key = Linzer.generate_ed25519_key("my-key-id")

Loading from PEM

private_key = Linzer.new_ed25519_key(File.read("ed25519.pem"), "key-1")
public_key = Linzer.new_ed25519_public_key(File.read("ed25519_pub.pem"), "key-1")

See Also:

Instance Attribute Summary

Attributes inherited from Key

#material

Instance Method Summary collapse

Methods inherited from Key

#initialize, #key_id

Constructor Details

This class inherits a constructor from Linzer::Key

Instance Method Details

#private?Boolean

Returns true if this key contains private key material.

Returns:

  • (Boolean)

    true if this key contains private key material



55
56
57
# File 'lib/linzer/ed25519.rb', line 55

def private?
  has_pem_private?
end

#public?Boolean

Returns true if this key contains public key material.

Returns:

  • (Boolean)

    true if this key contains public key material



50
51
52
# File 'lib/linzer/ed25519.rb', line 50

def public?
  has_pem_public?
end

#sign(data) ⇒ String

Signs data using the Ed25519 private key.

Parameters:

  • data (String)

    The data to sign (typically the signature base)

Returns:

  • (String)

    The 64-byte Ed25519 signature

Raises:

  • (SigningError)

    If this key does not contain private key material



33
34
35
36
# File 'lib/linzer/ed25519.rb', line 33

def sign(data)
  validate_signing_key
  material.sign(nil, data)
end

#verify(signature, data) ⇒ Boolean

Verifies a signature using the Ed25519 public key.

Parameters:

  • signature (String)

    The signature bytes to verify

  • data (String)

    The data that was signed

Returns:

  • (Boolean)

    true if the signature is valid, false otherwise

Raises:

  • (VerifyError)

    If this key does not contain public key material



44
45
46
47
# File 'lib/linzer/ed25519.rb', line 44

def verify(signature, data)
  validate_verify_key
  material.verify(nil, signature, data)
end