Class: MlDsa::BatchBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ml_dsa/batch_builder.rb

Overview

Collects sign or verify operations for batch execution. Obtained via batch. Do not mix sign and verify in one batch.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ BatchBuilder

Returns a new instance of BatchBuilder.



7
8
9
10
# File 'lib/ml_dsa/batch_builder.rb', line 7

def initialize
  @ops = []
  @mode = nil
end

Instance Method Details

#execute(config: MlDsa.config, yield_every: Internal::DEFAULT_YIELD_EVERY) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
42
43
44
45
46
# File 'lib/ml_dsa/batch_builder.rb', line 39

def execute(config: MlDsa.config, yield_every: Internal::DEFAULT_YIELD_EVERY)
  return [] if @ops.empty?
  if @mode == :sign
    MlDsa.sign_many(@ops, config: config, yield_every: yield_every)
  else
    MlDsa.verify_many(@ops, config: config, yield_every: yield_every)
  end
end

#sign(sk:, message:, context: nil, deterministic: false) ⇒ self

Add a sign operation to the batch.

Parameters:

  • sk (SecretKey)
  • message (String)
  • context (String, nil) (defaults to: nil) —

    FIPS 204 context (0..255 bytes)

  • deterministic (Boolean) (defaults to: false) —

    use deterministic signing

Returns:

  • (self) —

    for chaining



18
19
20
21
22
23
# File 'lib/ml_dsa/batch_builder.rb', line 18

def sign(sk:, message:, context: nil, deterministic: false)
  check_mode!(:sign)
  @ops << SignRequest.new(sk: sk, message: message,
    context: context, deterministic: deterministic)
  self
end

#verify(pk:, message:, signature:, context: nil) ⇒ self

Add a verify operation to the batch.

Parameters:

  • pk (PublicKey)
  • message (String)
  • signature (String)
  • context (String, nil) (defaults to: nil) —

    FIPS 204 context (0..255 bytes)

Returns:

  • (self) —

    for chaining



31
32
33
34
35
36
# File 'lib/ml_dsa/batch_builder.rb', line 31

def verify(pk:, message:, signature:, context: nil)
  check_mode!(:verify)
  @ops << VerifyRequest.new(pk: pk, message: message,
    signature: signature, context: context)
  self
end