Class: HPKE::Context
Instance Attribute Summary collapse
-
#base_nonce ⇒ Object
readonly
Returns the value of attribute base_nonce.
-
#exporter_secret ⇒ Object
readonly
Returns the value of attribute exporter_secret.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#sequence_number ⇒ Object
readonly
Returns the value of attribute sequence_number.
Instance Method Summary collapse
- #compute_nonce(seq) ⇒ Object
- #export(exporter_context, len) ⇒ Object
- #increment_seq ⇒ Object
-
#initialize(initializer_hash, hpke) ⇒ Context
constructor
A new instance of Context.
Methods included from Util
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_nonce ⇒ Object (readonly)
Returns the value of attribute base_nonce.
227 228 229 |
# File 'lib/hpke.rb', line 227 def base_nonce @base_nonce end |
#exporter_secret ⇒ Object (readonly)
Returns the value of attribute exporter_secret.
227 228 229 |
# File 'lib/hpke.rb', line 227 def exporter_secret @exporter_secret end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
227 228 229 |
# File 'lib/hpke.rb', line 227 def key @key end |
#sequence_number ⇒ Object (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_seq ⇒ Object
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 |