Class: HPKE::Context

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/hpke.rb

Direct Known Subclasses

ContextR, ContextS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#i2osp, #os2ip, #xor

Constructor Details

#initialize(initializer_hash, hpke) ⇒ Context

Returns a new instance of Context.



229
230
231
232
233
234
235
# File 'lib/hpke.rb', line 229

def initialize(initializer_hash, hpke)
  @hpke = hpke
  @key = initializer_hash[:key]
  @base_nonce = initializer_hash[:base_nonce]
  @sequence_number = initializer_hash[:sequence_number]
  @exporter_secret = initializer_hash[:exporter_secret]
end

Instance Attribute Details

#base_nonceObject (readonly)

Returns the value of attribute base_nonce.



227
228
229
# File 'lib/hpke.rb', line 227

def base_nonce
  @base_nonce
end

#exporter_secretObject (readonly)

Returns the value of attribute exporter_secret.



227
228
229
# File 'lib/hpke.rb', line 227

def exporter_secret
  @exporter_secret
end

#keyObject (readonly)

Returns the value of attribute key.



227
228
229
# File 'lib/hpke.rb', line 227

def key
  @key
end

#sequence_numberObject (readonly)

Returns the value of attribute sequence_number.



227
228
229
# File 'lib/hpke.rb', line 227

def sequence_number
  @sequence_number
end

Instance Method Details

#compute_nonce(seq) ⇒ Object



237
238
239
240
# File 'lib/hpke.rb', line 237

def compute_nonce(seq)
  seq_bytes = i2osp(seq, @hpke.n_n)
  xor(@base_nonce, seq_bytes)
end

#export(exporter_context, len) ⇒ Object



248
249
250
# File 'lib/hpke.rb', line 248

def export(exporter_context, len)
  @hpke.export(@exporter_secret, exporter_context, len)
end

#increment_seqObject

Raises:

  • (Exception)


242
243
244
245
246
# File 'lib/hpke.rb', line 242

def increment_seq
  raise Exception.new('MessageLimitReachedError') if @sequence_number >= (1 << (8 * @hpke.n_n)) - 1

  @sequence_number += 1
end