Class: Nonnative::Ed25519Key

Inherits:
Object
  • Object
show all
Defined in:
lib/nonnative/ed25519_key.rb

Overview

Loads an Ed25519 private key from a PEM file for signing tokens.

Verifiers such as go-service use Ed25519 keys encoded as PKCS#8 PEM. This reads the PEM once and exposes the 32-byte seed required by JwtToken.

Examples:

key = Nonnative::Ed25519Key.new('config/ed25519.pem')
key.pem   # => "-----BEGIN PRIVATE KEY-----\n..."
key.seed  # => 32-byte binary String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Ed25519Key

Returns a new instance of Ed25519Key.

Parameters:

  • path (String) —

    path to a PKCS#8 Ed25519 private key PEM file



15
16
17
# File 'lib/nonnative/ed25519_key.rb', line 15

def initialize(path)
  @pem = File.read(path)
end

Instance Attribute Details

#pem ⇒ String (readonly)

Returns the PEM contents (PKCS#8 Ed25519 private key).

Returns:

  • (String) —

    the PEM contents (PKCS#8 Ed25519 private key)



20
21
22
# File 'lib/nonnative/ed25519_key.rb', line 20

def pem
  @pem
end

Instance Method Details

#seed ⇒ String

Extracts the raw 32-byte Ed25519 seed from the PEM.

Returns:

  • (String) —

    the raw 32-byte Ed25519 seed



25
26
27
# File 'lib/nonnative/ed25519_key.rb', line 25

def seed
  OpenSSL::PKey.read(@pem).raw_private_key
end