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 |
# File 'lib/linzer/key.rb', line 37 def initialize(material, params = {}) @material = material @params = Hash(params).clone.freeze validate freeze end |
Instance Attribute Details
#material ⇒ Object (readonly)
Returns The underlying key material.
45 46 47 |
# File 'lib/linzer/key.rb', line 45 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.
53 54 55 |
# File 'lib/linzer/key.rb', line 53 def key_id @params[:id] end |
#private? ⇒ Boolean
Checks if this key can be used for signing.
93 94 95 |
# File 'lib/linzer/key.rb', line 93 def private? material.private? end |
#public? ⇒ Boolean
Checks if this key can be used for signature verification.
86 87 88 |
# File 'lib/linzer/key.rb', line 86 def public? material.public? end |
#sign(*args) ⇒ String
Subclasses must override this method.
Signs data using this key.
65 66 67 68 |
# File 'lib/linzer/key.rb', line 65 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.
78 79 80 81 |
# File 'lib/linzer/key.rb', line 78 def verify(*args) abstract_error = "Cannot verify signature, \"#{self.class}\" is an abstract class." raise Error, abstract_error end |