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 it in the shapes the token backends need: the raw PEM for PasetoToken and the 32-byte seed for 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



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

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

Instance Attribute Details

#pemString (readonly)

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

Returns:

  • (String)

    the PEM contents (PKCS#8 Ed25519 private key)



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

def pem
  @pem
end

Instance Method Details

#seedString

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

Returns:

  • (String)

    the raw 32-byte Ed25519 seed



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

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