Class: PQCrypto::Seal::Format::InnerCodec

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

Class Method Summary collapse

Class Method Details

.parse(bytes) ⇒ Object

Raises:



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/pq_crypto/seal/format.rb', line 217

def parse(bytes)
  source = String(bytes).b
  reader = Binary::Reader.new(source)
  raise FormatError, "unsupported inner version" unless reader.u8 == INNER_VERSION
  raise FormatError, "unknown inner flags" unless reader.u8 == INNER_FLAGS

  content_length = reader.u64
   = reader.u32
  raise FormatError, "private metadata is too large" if  > MAX_PRIVATE_METADATA_BYTES

   = reader.bytes()
  content = reader.bytes(content_length)
  VerifiedInner.new(
    content: content,
    metadata: ,
    padding_bytes: source.bytesize - reader.offset
  )
end

.prefix(content_length, metadata_length) ⇒ Object



212
213
214
215
# File 'lib/pq_crypto/seal/format.rb', line 212

def prefix(content_length, )
  Binary.u8(INNER_VERSION) + Binary.u8(INNER_FLAGS) +
    Binary.u64(content_length) + Binary.u32()
end