Class: Linzer::JWS::Key

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

Overview

JWS-compatible signing key implementation.

Wraps a JWT::JWK key object to provide the Linzer Key interface. This enables using JWK-format keys with HTTP Message Signatures.

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 can create signatures.

Returns:

  • (Boolean)

    true if this key can create signatures



110
111
112
# File 'lib/linzer/jws.rb', line 110

def private?
  !!signing_key
end

#public?Boolean

Returns true if this key can verify signatures.

Returns:

  • (Boolean)

    true if this key can verify signatures



105
106
107
# File 'lib/linzer/jws.rb', line 105

def public?
  !!verify_key
end

#sign(data) ⇒ String

Signs data using the JWS key.

Parameters:

  • data (String)

    The data to sign

Returns:

  • (String)

    The signature bytes

Raises:



86
87
88
89
90
# File 'lib/linzer/jws.rb', line 86

def sign(data)
  validate_signing_key
  algo = resolve_algorithm
  algo.sign(data: data, signing_key: signing_key)
end

#verify(signature, data) ⇒ Boolean

Verifies a signature using the JWS key.

Parameters:

  • signature (String)

    The signature bytes to verify

  • data (String)

    The data that was signed

Returns:

  • (Boolean)

    true if valid, false otherwise

Raises:

  • (VerifyError)

    If this key cannot be used for verification



98
99
100
101
102
# File 'lib/linzer/jws.rb', line 98

def verify(signature, data)
  validate_verify_key
  algo = resolve_algorithm
  algo.verify(data: data, signature: signature, verification_key: verify_key)
end