Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly define _reserved1 in tenc box and improve it's Const checks #30

Merged
merged 4 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/pymp4/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,26 @@ def _encode(self, obj, context):

TrackEncryptionBox = Struct(
"type" / If(this._.type != b"uuid", Const(b"tenc")),
"version" / Default(Int8ub, 0),
"version" / Default(OneOf(Int8ub, (0, 1)), 0),
"flags" / Default(Int24ub, 0),
"_reserved0" / Const(Int8ub, 0),
"_reserved1" / Const(Int8ub, 0),
"is_encrypted" / Int8ub,
"iv_size" / Int8ub,
"_reserved" / Const(Int8ub, 0),
"default_byte_blocks" / Default(IfThenElse(
this.version > 0,
BitStruct(
# count of encrypted blocks in the protection pattern, where each block is 16-bytes
"crypt" / Nibble,
# count of unencrypted blocks in the protection pattern
"skip" / Nibble
),
Const(Int8ub, 0)
), 0),
"is_encrypted" / OneOf(Int8ub, (0, 1)),
"iv_size" / OneOf(Int8ub, (0, 8, 16)),
"key_ID" / UUIDBytes(Bytes(16)),
"constant_iv" / Default(If(this.is_encrypted and this.iv_size == 0,
PrefixedArray(Int8ub, Byte),
),
None)

"constant_iv" / Default(If(
this.is_encrypted and this.iv_size == 0,
PrefixedArray(Int8ub, Byte)
), None)
)

SampleEncryptionBox = Struct(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dashboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def test_tenc_parse(self):
(type=b"tenc")
(version=0)
(flags=0)
(_reserved=0)
(default_byte_blocks=0)
(is_encrypted=1)
(iv_size=8)
(key_ID=UUID('337b9643-21b6-4355-9e59-3eccb46c7ef7'))
Expand Down