Class: PQCrypto::Seal::Format::SectionCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/pq_crypto/seal/format.rb

Class Method Summary collapse

Class Method Details

.parse(bytes, offset, header) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pq_crypto/seal/format.rb', line 190

def parse(bytes, offset, header)
  raw, = Binary.read_bytes(bytes, offset, Format.section_length(header))
  reader = Binary::Reader.new(raw)
  wrap_suite = reader.u16
  unless wrap_suite == WRAP_SUITE_MLKEM768_X25519_AEGIS256
    raise UnsupportedSuiteError, "unsupported wrap suite #{wrap_suite}"
  end

  section_id = reader.bytes(SECTION_ID_BYTES)
  Section.new(
    wrap_suite_id: wrap_suite,
    section_id: section_id,
    raw: raw,
    slots_offset: reader.offset,
    slots_length: raw.bytesize - reader.offset
  )
end