Class: Linzer::MLDSA::Key
- Inherits:
-
Key
- Object
- Key
- Linzer::MLDSA::Key
- Defined in:
- lib/linzer/ml_dsa.rb
Overview
An ML-DSA signing or verification key.
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
Instance Method Summary collapse
-
#initialize(material, params = {}) ⇒ Key
constructor
A new instance of Key.
-
#sign(data) ⇒ String
Signs an RFC 9421 signature base with an empty FIPS 204 context.
-
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP
algparameter matches this key's parameter set. -
#verify(signature, data) ⇒ Boolean
Verifies an RFC 9421 signature base with an empty FIPS 204 context.
Constructor Details
#initialize(material, params = {}) ⇒ Key
Returns a new instance of Key.
19 20 21 22 |
# File 'lib/linzer/ml_dsa.rb', line 19 def initialize(material, params = {}) @algorithm = String(params.fetch(:algorithm)) super end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
17 18 19 |
# File 'lib/linzer/ml_dsa.rb', line 17 def algorithm @algorithm end |
Instance Method Details
#sign(data) ⇒ String
Signs an RFC 9421 signature base with an empty FIPS 204 context.
42 43 44 45 46 47 |
# File 'lib/linzer/ml_dsa.rb', line 42 def sign(data) validate_signing_key material.sign(data, context: "") rescue MlDsa::Error => e raise SigningError, e., cause: e end |
#validate_signature_parameters(parameters) ⇒ true
Validates that the HTTP alg parameter matches this key's parameter set.
29 30 31 32 33 34 35 |
# File 'lib/linzer/ml_dsa.rb', line 29 def validate_signature_parameters(parameters) supplied_algorithm = parameters["alg"] || parameters[:alg] return true if supplied_algorithm.nil? || supplied_algorithm == algorithm raise VerifyError, "Signature algorithm #{supplied_algorithm} does not match key algorithm #{algorithm}" end |
#verify(signature, data) ⇒ Boolean
Verifies an RFC 9421 signature base with an empty FIPS 204 context.
55 56 57 58 59 60 61 62 63 |
# File 'lib/linzer/ml_dsa.rb', line 55 def verify(signature, data) validate_verify_key return false unless signature.is_a?(String) return false unless signature.bytesize == parameter_set.signature_bytes verification_material.verify(data, signature, context: "") rescue MlDsa::Error, ArgumentError, TypeError false end |