Class: Linzer::Key Abstract
- Inherits:
-
Object
- Object
- Linzer::Key
- Defined in:
- lib/linzer/key.rb,
lib/linzer/key/helper.rb
Overview
Abstract base class for cryptographic keys used in HTTP message signatures.
This class provides the common interface for all key types supported by Linzer. Do not instantiate this class directly; use one of the concrete subclasses or the key generation/loading helper methods.
Direct Known Subclasses
ECDSA::Key, Ed25519::Key, HMAC::Key, JWS::Key, RSA::Key, RSAPSS::Key
Defined Under Namespace
Modules: Helper
Instance Attribute Summary collapse
-
#material ⇒ Object
readonly
The underlying key material.
Instance Method Summary collapse
-
#initialize(material, params = {}) ⇒ Key
constructor
Creates a new Key instance.
-
#key_id ⇒ String?
Returns the key identifier.
-
#private? ⇒ Boolean
Checks if this key can be used for signing.
-
#public? ⇒ Boolean
Checks if this key can be used for signature verification.
-
#sign(*args) ⇒ String
abstract
Signs data using this key.
-
#verify(*args) ⇒ Boolean
abstract
Verifies a signature against data using this key.
Constructor Details
#initialize(material, params = {}) ⇒ Key
Creates a new Key instance.
37 38 39 40 41 42 43 44 |
# File 'lib/linzer/key.rb', line 37 def initialize(material, params = {}) @material = material @params = Hash(params).clone.freeze validate @is_private = compute_private? @is_public = compute_public? freeze end |
Instance Attribute Details
#material ⇒ Object (readonly)
Returns The underlying key material.
47 48 49 |
# File 'lib/linzer/key.rb', line 47 def material @material end |
Instance Method Details
#key_id ⇒ String?
Returns the key identifier.
The key ID is used in the ‘keyid` parameter of HTTP signatures to identify which key was used for signing.
55 56 57 |
# File 'lib/linzer/key.rb', line 55 def key_id @params[:id] end |
#private? ⇒ Boolean
Checks if this key can be used for signing.
95 96 97 |
# File 'lib/linzer/key.rb', line 95 def private? @is_private end |
#public? ⇒ Boolean
Checks if this key can be used for signature verification.
88 89 90 |
# File 'lib/linzer/key.rb', line 88 def public? @is_public end |
#sign(*args) ⇒ String
Subclasses must override this method.
Signs data using this key.
67 68 69 70 |
# File 'lib/linzer/key.rb', line 67 def sign(*args) abstract_error = "Cannot sign data, \"#{self.class}\" is an abstract class." raise Error, abstract_error end |
#verify(*args) ⇒ Boolean
Subclasses must override this method.
Verifies a signature against data using this key.
80 81 82 83 |
# File 'lib/linzer/key.rb', line 80 def verify(*args) abstract_error = "Cannot verify signature, \"#{self.class}\" is an abstract class." raise Error, abstract_error end |