Class: CryptoRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/universa_tools/crypto_record.rb

Overview

Universa KeyRecord. This structure is intended to hold small encrypted entity, usually a key to other, big encrypted entity. KeyRecord maximum plaintext size is small, so everything that could be large than say 128 bytes should be encrypted using a key stored as plaintext in the KR.

This class is not directly instantiable, use one of its ancestors, like Pbkdf2CryptoRecord, or decode packed binary record.

Direct Known Subclasses

Pbkdf2CryptoRecord

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_packed(packed) ⇒ Object

Unpack single KeyRecord packed into binary form.



10
11
12
# File 'lib/universa_tools/crypto_record.rb', line 10

def self.from_packed packed
  decode_array(Boss.load(packed))
end

.pack_all(records) ⇒ Binary

Pack many key records into single binary packed form. To unpack it ise unpack_all

Parameters:

Returns:

  • (Binary)

    binary packed string.



29
30
31
32
# File 'lib/universa_tools/crypto_record.rb', line 29

def self.pack_all(records)
  # hack: we call private method, we do not want to make it public
  Boss.pack(records.map{ |x| x.send :serialized})
end

.unpack_all(packed_records) ⇒ Object

Unpack array of key records



15
16
17
# File 'lib/universa_tools/crypto_record.rb', line 15

def self.unpack_all(packed_records)
  Boss.load(packed_records).map { |array| decode_array(array) }
end

Instance Method Details

#packBinary

Pack a self in binary form, this is different from pack_all/unpack_all.

Returns:

  • (Binary)

    stinrg with encoded key record



21
22
23
# File 'lib/universa_tools/crypto_record.rb', line 21

def pack
  Boss.pack(serialized)
end