pssh_box/
irdeto.rs

1//! Definitions for PSSH data in the Irdeto DRM system.
2
3
4use std::fmt;
5use std::io::{Read, Cursor};
6use byteorder::{LittleEndian, ReadBytesExt};
7use serde::{Serialize, Deserialize};
8use anyhow::Result;
9use crate::ToBytes;
10
11
12#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct IrdetoPsshData {
14    pub xml: String,
15}
16
17impl fmt::Debug for IrdetoPsshData {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        write!(f, "IrdetoPsshData<{}>", self.xml)
20    }
21}
22
23impl ToBytes for IrdetoPsshData {
24    fn to_bytes(&self) -> Vec<u8> {
25        self.xml.clone().into_bytes()
26    }
27}
28
29
30pub fn parse_pssh_data(buf: &[u8]) -> Result<IrdetoPsshData> {
31    let mut rdr = Cursor::new(buf);
32    let _ignore1 = rdr.read_u32::<LittleEndian>()?;
33    let _ignore2 = rdr.read_u32::<LittleEndian>()?;
34    let _ignore3 = rdr.read_u8()?;
35    let mut utf8buf = Vec::new();
36    let xmllen = (buf.len() - 9) as u64;
37    rdr.take(xmllen).read_to_end(&mut utf8buf)?;
38    let xml = String::from_utf8(utf8buf)?;
39    Ok(IrdetoPsshData { xml })
40}