Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit e051aff

Browse files
committed
Use StructTag derive macro in license structures
1 parent f773540 commit e051aff

File tree

2 files changed

+99
-61
lines changed

2 files changed

+99
-61
lines changed

crates/playready/src/binary_format/xmr_license.rs

Lines changed: 86 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![allow(dead_code)]
22

3+
use super::StructTag;
34
use binrw::{helpers::until_eof, BinRead};
5+
use playready_macros::StructTag;
46

57
#[derive(BinRead, Debug, Clone, Copy, PartialEq)]
68
#[br(big, repr = u16)]
@@ -15,63 +17,72 @@ pub enum CipherType {
1517
Unknown = 0xffff,
1618
}
1719

18-
#[derive(BinRead, Debug, Clone)]
20+
#[derive(BinRead, StructTag, Debug, Clone)]
1921
#[br(big)]
22+
#[struct_tag(0x0039)]
2023
pub struct PlayEnablerType {
2124
pub player_enabler_type: [u8; 16],
2225
}
2326

24-
#[derive(BinRead, Debug, Clone)]
27+
#[derive(BinRead, StructTag, Debug, Clone)]
2528
#[br(big)]
29+
#[struct_tag(0x0029)]
2630
pub struct DomainRestrictionObject {
2731
pub account_id: [u8; 16],
2832
pub revision: u32,
2933
}
3034

31-
#[derive(BinRead, Debug, Clone)]
35+
#[derive(BinRead, StructTag, Debug, Clone)]
3236
#[br(big)]
37+
#[struct_tag(0x0013)]
3338
pub struct IssueDateObject {
3439
pub issue_date: u32,
3540
}
3641

37-
#[derive(BinRead, Debug, Clone)]
42+
#[derive(BinRead, StructTag, Debug, Clone)]
3843
#[br(big)]
44+
#[struct_tag(0x0032)]
3945
pub struct RevInfoVersionObject {
4046
pub sequence: u32,
4147
}
4248

43-
#[derive(BinRead, Debug, Clone)]
49+
#[derive(BinRead, StructTag, Debug, Clone)]
4450
#[br(big)]
51+
#[struct_tag(0x0034)]
4552
pub struct SecurityLevelObject {
4653
pub minimum_security_level: u16,
4754
}
4855

49-
#[derive(BinRead, Debug, Clone)]
56+
#[derive(BinRead, StructTag, Debug, Clone)]
5057
#[br(big)]
58+
#[struct_tag(0x0033)]
5159
pub struct EmbeddedLicenseSettingsObject {
5260
pub indicator: u16,
5361
}
5462

55-
#[derive(BinRead, Debug, Clone)]
63+
#[derive(BinRead, StructTag, Debug, Clone)]
5664
#[br(big)]
65+
#[struct_tag(0x002a)]
5766
pub struct ECCKeyObject {
5867
pub curve_type: u16,
5968
pub key_length: u16,
6069
#[br(count = key_length)]
6170
pub key: Vec<u8>,
6271
}
6372

64-
#[derive(BinRead, Debug, Clone)]
73+
#[derive(BinRead, StructTag, Debug, Clone)]
6574
#[br(big)]
75+
#[struct_tag(0x000b)]
6676
pub struct SignatureObject {
6777
pub signature_type: u16,
6878
pub signature_data_length: u16,
6979
#[br(count = signature_data_length)]
7080
pub signature_data: Vec<u8>,
7181
}
7282

73-
#[derive(BinRead, Debug, Clone)]
83+
#[derive(BinRead, StructTag, Debug, Clone)]
7484
#[br(big)]
85+
#[struct_tag(0x000a)]
7586
pub struct ContentKeyObject {
7687
pub key_id: [u8; 16],
7788
pub key_type: u16,
@@ -81,14 +92,16 @@ pub struct ContentKeyObject {
8192
pub encrypted_key: Vec<u8>,
8293
}
8394

84-
#[derive(BinRead, Debug, Clone)]
95+
#[derive(BinRead, StructTag, Debug, Clone)]
8596
#[br(big)]
97+
#[struct_tag(0x000d)]
8698
pub struct RightsSettingsObject {
8799
pub rights: u16,
88100
}
89101

90-
#[derive(BinRead, Debug, Clone)]
102+
#[derive(BinRead, StructTag, Debug, Clone)]
91103
#[br(big)]
104+
#[struct_tag(0x0005)]
92105
pub struct OutputProtectionLevelRestrictionObject {
93106
pub minimum_compressed_digital_video_opl: u16,
94107
pub minimum_uncompressed_digital_video_opl: u16,
@@ -97,21 +110,24 @@ pub struct OutputProtectionLevelRestrictionObject {
97110
pub minimum_digital_uncompressed_audio_opl: u16,
98111
}
99112

100-
#[derive(BinRead, Debug, Clone)]
113+
#[derive(BinRead, StructTag, Debug, Clone)]
101114
#[br(big)]
115+
#[struct_tag(0x0012)]
102116
pub struct ExpirationRestrictionObject {
103117
pub begin_date: u32,
104118
pub end_date: u32,
105119
}
106120

107-
#[derive(BinRead, Debug, Clone)]
121+
#[derive(BinRead, StructTag, Debug, Clone)]
108122
#[br(big)]
123+
#[struct_tag(0x0050)]
109124
pub struct RemovalDateObject {
110125
pub removal_date: u32,
111126
}
112127

113-
#[derive(BinRead, Debug, Clone)]
128+
#[derive(BinRead, StructTag, Debug, Clone)]
114129
#[br(big)]
130+
#[struct_tag(0x003b)]
115131
pub struct UplinkKIDObject {
116132
pub plink_kid: [u8; 16],
117133
pub chained_checksum_type: u16,
@@ -120,64 +136,73 @@ pub struct UplinkKIDObject {
120136
pub chained_checksum: Vec<u8>,
121137
}
122138

123-
#[derive(BinRead, Debug, Clone)]
139+
#[derive(BinRead, StructTag, Debug, Clone)]
124140
#[br(big, import(length: u32))]
141+
#[struct_tag(0x0008)]
125142
pub struct AnalogVideoOutputConfigurationRestriction {
126143
pub video_output_protection_id: [u8; 16],
127144
#[br(count = length - 24)]
128145
pub binary_configuration_data: Vec<u8>,
129146
}
130147

131-
#[derive(BinRead, Debug, Clone)]
148+
#[derive(BinRead, StructTag, Debug, Clone)]
132149
#[br(big, import(length: u32))]
150+
#[struct_tag(0x0059)]
133151
pub struct DigitalVideoOutputRestrictionObject {
134152
pub video_output_protection_id: [u8; 16],
135153
#[br(count = length - 24)]
136154
pub binary_configuration_data: Vec<u8>,
137155
}
138156

139-
#[derive(BinRead, Debug, Clone)]
157+
#[derive(BinRead, StructTag, Debug, Clone)]
140158
#[br(big, import(length: u32))]
159+
#[struct_tag(0x0031)]
141160
pub struct DigitalAudioOutputRestrictionObject {
142161
pub audio_output_protection_id: [u8; 16],
143162
#[br(count = length - 24)]
144163
pub binary_configuration_data: Vec<u8>,
145164
}
146165

147-
#[derive(BinRead, Debug, Clone)]
166+
#[derive(BinRead, StructTag, Debug, Clone)]
148167
#[br(big, import(length: u32))]
168+
#[struct_tag(0x002c)]
149169
pub struct PolicyMetadataObject {
150170
pub metadata_type: [u8; 16],
151171
#[br(count = length - 24)]
152172
pub policy_data: Vec<u8>,
153173
}
154174

155-
#[derive(BinRead, Debug, Clone)]
175+
#[derive(BinRead, StructTag, Debug, Clone)]
156176
#[br(big)]
177+
#[struct_tag(0x005a)]
157178
pub struct SecureStopRestrictionObject {
158179
pub metering_id: [u8; 16],
159180
}
160181

161-
#[derive(BinRead, Debug, Clone)]
182+
#[derive(BinRead, StructTag, Debug, Clone)]
162183
#[br(big)]
184+
#[struct_tag(0x0016)]
163185
pub struct MeteringRestrictionObject {
164186
pub metering_id: [u8; 16],
165187
}
166188

167-
#[derive(BinRead, Debug, Clone)]
189+
#[derive(BinRead, StructTag, Debug, Clone)]
168190
#[br(big)]
191+
#[struct_tag(0x0030)]
169192
pub struct ExpirationAfterFirstPlayRestrictionObject {
170193
pub seconds: u32,
171194
}
172195

173-
#[derive(BinRead, Debug, Clone)]
196+
#[derive(BinRead, StructTag, Debug, Clone)]
174197
#[br(big)]
198+
#[struct_tag(0x001a)]
175199
pub struct GracePeriodObject {
176200
pub grace_period: u32,
177201
}
178202

179-
#[derive(BinRead, Debug, Clone)]
203+
#[derive(BinRead, StructTag, Debug, Clone)]
180204
#[br(big)]
205+
#[struct_tag(0x0022)]
181206
pub struct SourceIdObject {
182207
pub source_id: u32,
183208
}
@@ -189,16 +214,18 @@ pub struct AuxiliaryKey {
189214
pub key: [u8; 16],
190215
}
191216

192-
#[derive(BinRead, Debug, Clone)]
217+
#[derive(BinRead, StructTag, Debug, Clone)]
193218
#[br(big)]
219+
#[struct_tag(0x0051)]
194220
pub struct AuxiliaryKeysObject {
195221
pub count: u16,
196222
#[br(count = count)]
197223
pub auxiliary_keys: Vec<AuxiliaryKey>,
198224
}
199225

200-
#[derive(BinRead, Debug, Clone)]
226+
#[derive(BinRead, StructTag, Debug, Clone)]
201227
#[br(big)]
228+
#[struct_tag(0x0052)]
202229
pub struct UplinkKeyObject3 {
203230
pub uplink_key_id: [u8; 16],
204231
pub chained_length: u16,
@@ -209,84 +236,87 @@ pub struct UplinkKeyObject3 {
209236
pub entries: Vec<u32>,
210237
}
211238

212-
#[derive(BinRead, Debug, Clone)]
239+
#[derive(BinRead, StructTag, Debug, Clone)]
213240
#[br(big)]
241+
#[struct_tag(0x003a)]
214242
pub struct CopyEnablerObject {
215243
pub copy_enabler_type: [u8; 16],
216244
}
217245

218-
#[derive(BinRead, Debug, Clone)]
246+
#[derive(BinRead, StructTag, Debug, Clone)]
219247
#[br(big)]
248+
#[struct_tag(0x003d)]
220249
pub struct CopyCountRestrictionObject {
221250
pub count: u32,
222251
}
223252

224-
#[derive(BinRead, Debug, Clone)]
253+
#[derive(BinRead, StructTag, Debug, Clone)]
225254
#[br(big)]
255+
#[struct_tag(0x0037)]
226256
pub struct MoveObject {
227257
pub minimum_move_protection_level: u32,
228258
}
229259

230260
#[derive(BinRead, Debug, Clone)]
231261
#[br(big, import { type_: u16, length: u32})]
232262
pub enum XmrObjectInner {
233-
#[br(pre_assert(type_ == 0x0005))]
263+
#[br(pre_assert(type_ == OutputProtectionLevelRestrictionObject::tag()))]
234264
OutputProtectionLevelRestrictionObject(OutputProtectionLevelRestrictionObject),
235-
#[br(pre_assert(type_ == 0x0008))]
265+
#[br(pre_assert(type_ == AnalogVideoOutputConfigurationRestriction::tag()))]
236266
AnalogVideoOutputConfigurationRestriction(
237267
#[br(args(length))] AnalogVideoOutputConfigurationRestriction,
238268
),
239-
#[br(pre_assert(type_ == 0x000a))]
269+
#[br(pre_assert(type_ == ContentKeyObject::tag()))]
240270
ContentKeyObject(ContentKeyObject),
241-
#[br(pre_assert(type_ == 0x000b))]
271+
#[br(pre_assert(type_ == SignatureObject::tag()))]
242272
SignatureObject(SignatureObject),
243-
#[br(pre_assert(type_ == 0x000d))]
273+
#[br(pre_assert(type_ == RightsSettingsObject::tag()))]
244274
RightsSettingsObject(RightsSettingsObject),
245-
#[br(pre_assert(type_ == 0x0012))]
275+
#[br(pre_assert(type_ == ExpirationRestrictionObject::tag()))]
246276
ExpirationRestrictionObject(ExpirationRestrictionObject),
247-
#[br(pre_assert(type_ == 0x0013))]
277+
#[br(pre_assert(type_ == IssueDateObject::tag()))]
248278
IssueDateObject(IssueDateObject),
249-
#[br(pre_assert(type_ == 0x0016))]
279+
#[br(pre_assert(type_ == MeteringRestrictionObject::tag()))]
250280
MeteringRestrictionObject(MeteringRestrictionObject),
251-
#[br(pre_assert(type_ == 0x001a))]
281+
#[br(pre_assert(type_ == GracePeriodObject::tag()))]
252282
GracePeriodObject(GracePeriodObject),
253-
#[br(pre_assert(type_ == 0x0022))]
283+
#[br(pre_assert(type_ == SourceIdObject::tag()))]
254284
SourceIdObject(SourceIdObject),
255-
#[br(pre_assert(type_ == 0x002a))]
285+
#[br(pre_assert(type_ == ECCKeyObject::tag()))]
256286
ECCKeyObject(ECCKeyObject),
257-
#[br(pre_assert(type_ == 0x002c))]
287+
#[br(pre_assert(type_ == PolicyMetadataObject::tag()))]
258288
PolicyMetadataObject(#[br(args(length))] PolicyMetadataObject),
259-
#[br(pre_assert(type_ == 0x0029))]
289+
#[br(pre_assert(type_ == DomainRestrictionObject::tag()))]
260290
DomainRestrictionObject(DomainRestrictionObject),
261-
#[br(pre_assert(type_ == 0x0030))]
291+
#[br(pre_assert(type_ == ExpirationAfterFirstPlayRestrictionObject::tag()))]
262292
ExpirationAfterFirstPlayRestrictionObject(ExpirationAfterFirstPlayRestrictionObject),
263-
#[br(pre_assert(type_ == 0x0031))]
293+
#[br(pre_assert(type_ == DigitalAudioOutputRestrictionObject::tag()))]
264294
DigitalAudioOutputRestrictionObject(#[br(args(length))] DigitalAudioOutputRestrictionObject),
265-
#[br(pre_assert(type_ == 0x0032))]
295+
#[br(pre_assert(type_ == RevInfoVersionObject::tag()))]
266296
RevInfoVersionObject(RevInfoVersionObject),
267-
#[br(pre_assert(type_ == 0x0033))]
297+
#[br(pre_assert(type_ == EmbeddedLicenseSettingsObject::tag()))]
268298
EmbeddedLicenseSettingsObject(EmbeddedLicenseSettingsObject),
269-
#[br(pre_assert(type_ == 0x0034))]
299+
#[br(pre_assert(type_ == SecurityLevelObject::tag()))]
270300
SecurityLevelObject(SecurityLevelObject),
271-
#[br(pre_assert(type_ == 0x0037))]
301+
#[br(pre_assert(type_ == MoveObject::tag()))]
272302
MoveObject(MoveObject),
273-
#[br(pre_assert(type_ == 0x0039))]
303+
#[br(pre_assert(type_ == PlayEnablerType::tag()))]
274304
PlayEnablerType(PlayEnablerType),
275-
#[br(pre_assert(type_ == 0x003a))]
305+
#[br(pre_assert(type_ == CopyEnablerObject::tag()))]
276306
CopyEnablerObject(CopyEnablerObject),
277-
#[br(pre_assert(type_ == 0x003b))]
307+
#[br(pre_assert(type_ == UplinkKIDObject::tag()))]
278308
UplinkKIDObject(UplinkKIDObject),
279-
#[br(pre_assert(type_ == 0x003d))]
309+
#[br(pre_assert(type_ == CopyCountRestrictionObject::tag()))]
280310
CopyCountRestrictionObject(CopyCountRestrictionObject),
281-
#[br(pre_assert(type_ == 0x0050))]
311+
#[br(pre_assert(type_ == RemovalDateObject::tag()))]
282312
RemovalDateObject(RemovalDateObject),
283-
#[br(pre_assert(type_ == 0x0051))]
313+
#[br(pre_assert(type_ == AuxiliaryKeysObject::tag()))]
284314
AuxiliaryKeysObject(AuxiliaryKeysObject),
285-
#[br(pre_assert(type_ == 0x0052))]
315+
#[br(pre_assert(type_ == UplinkKeyObject3::tag()))]
286316
UplinkKeyObject3(UplinkKeyObject3),
287-
#[br(pre_assert(type_ == 0x005a))]
317+
#[br(pre_assert(type_ == SecureStopRestrictionObject::tag()))]
288318
SecureStopRestrictionObject(SecureStopRestrictionObject),
289-
#[br(pre_assert(type_ == 0x0059))]
319+
#[br(pre_assert(type_ == DigitalVideoOutputRestrictionObject::tag()))]
290320
DigitalVideoOutputRestrictionObject(#[br(args(length))] DigitalVideoOutputRestrictionObject),
291321
Unknown(#[br(count = length)] Vec<u8>),
292322
}

0 commit comments

Comments
 (0)