lib/pssh_box/builder.rb in pssh_box-0.0.1 vs lib/pssh_box/builder.rb in pssh_box-0.1.0

- old
+ new

@@ -23,24 +23,42 @@ private def self.build_pssh_bytes(key_ids, pssh_data, pssh_version, system_id) pssh_bytes = 'pssh'.bytes - pssh_bytes += int_to_four_bytes(pssh_version << 24).bytes - pssh_bytes += uuid_to_bytes(system_id).bytes + pssh_bytes += version_bytes(pssh_version) + pssh_bytes += system_id_bytes(system_id) if pssh_version == 1 - pssh_bytes += int_to_four_bytes(key_ids.length).bytes - key_ids.each do |key_id| - pssh_bytes += uuid_to_bytes(key_id).bytes - end + pssh_bytes += key_id_bytes(key_ids) end - pssh_bytes += int_to_four_bytes(pssh_data.length).bytes - pssh_bytes += pssh_data + pssh_bytes += pssh_data_bytes(pssh_data) - length_including_prefix = 4 + pssh_bytes.length - length_prefix_bytes = int_to_four_bytes(length_including_prefix).bytes + length_prefix_bytes(pssh_bytes.length) + pssh_bytes + end - length_prefix_bytes + pssh_bytes + def self.version_bytes(pssh_version) + int_to_four_bytes(pssh_version << 24).bytes + end + + def self.system_id_bytes(system_id) + uuid_to_bytes(system_id).bytes + end + + def self.key_id_bytes(key_ids) + key_id_bytes = int_to_four_bytes(key_ids.length).bytes + key_ids.each do |key_id| + key_id_bytes += uuid_to_bytes(key_id).bytes + end + key_id_bytes + end + + def self.pssh_data_bytes(pssh_data) + int_to_four_bytes(pssh_data.length).bytes + pssh_data + end + + def self.length_prefix_bytes(length) + length_including_prefix = 4 + length + int_to_four_bytes(length_including_prefix).bytes end def self.base64_encode_bytes(pssh_bytes) Base64.strict_encode64(pssh_bytes.pack('c*')) end