in mp4parse/src/lib.rs [4192:4234]
fn read_pssh<T: Read>(src: &mut BMFFBox<T>) -> Result<ProtectionSystemSpecificHeaderBox> {
let len = src.bytes_left();
let mut box_content = read_buf(src, len)?;
let (system_id, kid, data) = {
let pssh = &mut Cursor::new(&box_content);
let (version, _) = read_fullbox_extra(pssh)?;
let system_id = read_buf(pssh, 16)?;
let mut kid = TryVec::<ByteData>::new();
if version > 0 {
const KID_ELEMENT_SIZE: usize = 16;
let count = be_u32(pssh)?.to_usize();
kid.reserve(
count
.checked_mul(KID_ELEMENT_SIZE)
.ok_or_else(|| Error::from(Status::PsshSizeOverflow))?,
)?;
for _ in 0..count {
let item = read_buf(pssh, KID_ELEMENT_SIZE.to_u64())?;
kid.push(item)?;
}
}
let data_size = be_u32(pssh)?;
let data = read_buf(pssh, data_size.into())?;
(system_id, kid, data)
};
let mut pssh_box = TryVec::new();
write_be_u32(&mut pssh_box, src.head.size.try_into()?)?;
pssh_box.extend_from_slice(b"pssh")?;
pssh_box.append(&mut box_content)?;
Ok(ProtectionSystemSpecificHeaderBox {
system_id,
kid,
data,
box_content: pssh_box,
})
}