From ed92d030212e230c7a12d2b265feb470ffd5caa8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Sat, 14 Sep 2024 11:19:41 +0200
Subject: [PATCH 3/5] lavf/mxfdec: Add and use mxf_is_encrypted_triplet_key()
---
libavformat/mxfdec.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
@@ -1584,6 +1584,25 @@ static int mxf_match_uid(const UID key, const uint8_t uid_prefix[], int len)
return 1;
}
+/*
+ * Checks if key is mxf_is_encrypted_triplet_key, while also knowing that key[0..3] == mxf_klv_key
+ * Returns: boolean
+ */
+static int mxf_is_encrypted_triplet_key(const UID key)
+{
+ return key[4 ] == mxf_encrypted_triplet_key[4 ] &&
+ key[5 ] == mxf_encrypted_triplet_key[5 ] &&
+ key[6 ] == mxf_encrypted_triplet_key[6 ] &&
+ key[8 ] == mxf_encrypted_triplet_key[8 ] &&
+ key[9 ] == mxf_encrypted_triplet_key[9 ] &&
+ key[10] == mxf_encrypted_triplet_key[10] &&
+ key[11] == mxf_encrypted_triplet_key[11] &&
+ key[12] == mxf_encrypted_triplet_key[12] &&
+ key[13] == mxf_encrypted_triplet_key[13] &&
+ key[14] == mxf_encrypted_triplet_key[14] &&
+ key[15] == mxf_encrypted_triplet_key[15];
+}
+
static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid)
{
while (uls->uid[0]) {
@@ -3754,7 +3773,7 @@ static int mxf_read_header(AVFormatContext *s)
PRINT_KEY(s, "read header", klv.key);
av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
- if (mxf_match_uid(klv.key, mxf_encrypted_triplet_key, sizeof(mxf_encrypted_triplet_key)) ||
+ if (mxf_is_encrypted_triplet_key(klv.key) ||
IS_KLV_KEY_FAST(klv.key, mxf_essence_element_key) ||
IS_KLV_KEY_FAST(klv.key, mxf_canopus_essence_element_key) ||
IS_KLV_KEY_FAST(klv.key, mxf_avid_essence_element_key) ||
@@ -4005,7 +4024,7 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt)
pos = klv.next_klv - klv.length;
PRINT_KEY(s, "read packet", klv.key);
av_log(s, AV_LOG_TRACE, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);
- if (mxf_match_uid(klv.key, mxf_encrypted_triplet_key, sizeof(mxf_encrypted_triplet_key))) {
+ if (mxf_is_encrypted_triplet_key(klv.key)) {
ret = mxf_decrypt_triplet(s, pkt, &klv);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");
--
2.39.2