playready/binary_format/
device.rs

1#![allow(dead_code)]
2
3use binrw::{BinRead, BinWrite};
4
5pub const PRD_SCALAR_SIZE: usize = 96;
6
7#[derive(BinRead, BinWrite, Debug, Clone)]
8#[brw(big)]
9pub struct DeviceV2 {
10    pub group_certificate_length: u32,
11    #[br(count = group_certificate_length)]
12    pub group_certificate: Vec<u8>,
13    pub encryption_key: [u8; PRD_SCALAR_SIZE],
14    pub signing_key: [u8; PRD_SCALAR_SIZE],
15}
16
17#[derive(BinRead, BinWrite, Debug, Clone)]
18#[brw(big)]
19pub struct DeviceV3 {
20    pub group_key: [u8; PRD_SCALAR_SIZE],
21    pub encryption_key: [u8; PRD_SCALAR_SIZE],
22    pub signing_key: [u8; PRD_SCALAR_SIZE],
23    pub group_certificate_length: u32,
24    #[br(count = group_certificate_length)]
25    pub group_certificate: Vec<u8>,
26}
27
28#[derive(BinRead, BinWrite, Debug, Clone)]
29#[br(big, import(version: u8))]
30#[bw(big)]
31pub enum DeviceInner {
32    #[br(pre_assert(version == 2))]
33    V2(DeviceV2),
34    #[br(pre_assert(version == 3))]
35    V3(DeviceV3),
36}
37
38#[derive(BinRead, BinWrite, Debug, Clone)]
39#[brw(big, magic = b"PRD")]
40pub struct Device {
41    pub version: u8,
42    #[br(args(version))]
43    pub inner: DeviceInner,
44}