1 /**
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 module ffmpeg.libavutil.encryption_info;
19 extern (C) @nogc nothrow:
20 
21 struct AVSubsampleEncryptionInfo
22 {
23     /** The number of bytes that are clear. */
24     uint bytes_of_clear_data;
25 
26     /**
27      * The number of bytes that are protected.  If using pattern encryption,
28      * the pattern applies to only the protected bytes; if not using pattern
29      * encryption, all these bytes are encrypted.
30      */
31     uint bytes_of_protected_data;
32 }
33 
34 /**
35  * This describes encryption info for a packet.  This contains frame-specific
36  * info for how to decrypt the packet before passing it to the decoder.
37  *
38  * The size of this struct is not part of the public ABI.
39  */
40 struct AVEncryptionInfo
41 {
42     /** The fourcc encryption scheme, in big-endian byte order. */
43     uint scheme;
44 
45     /**
46      * Only used for pattern encryption.  This is the number of 16-byte blocks
47      * that are encrypted.
48      */
49     uint crypt_byte_block;
50 
51     /**
52      * Only used for pattern encryption.  This is the number of 16-byte blocks
53      * that are clear.
54      */
55     uint skip_byte_block;
56 
57     /**
58      * The ID of the key used to encrypt the packet.  This should always be
59      * 16 bytes long, but may be changed in the future.
60      */
61     ubyte* key_id;
62     uint key_id_size;
63 
64     /**
65      * The initialization vector.  This may have been zero-filled to be the
66      * correct block size.  This should always be 16 bytes long, but may be
67      * changed in the future.
68      */
69     ubyte* iv;
70     uint iv_size;
71 
72     /**
73      * An array of subsample encryption info specifying how parts of the sample
74      * are encrypted.  If there are no subsamples, then the whole sample is
75      * encrypted.
76      */
77     AVSubsampleEncryptionInfo* subsamples;
78     uint subsample_count;
79 }
80 
81 /**
82  * This describes info used to initialize an encryption key system.
83  *
84  * The size of this struct is not part of the public ABI.
85  */
86 struct AVEncryptionInitInfo
87 {
88     /**
89      * A unique identifier for the key system this is for, can be NULL if it
90      * is not known.  This should always be 16 bytes, but may change in the
91      * future.
92      */
93     ubyte* system_id;
94     uint system_id_size;
95 
96     /**
97      * An array of key IDs this initialization data is for.  All IDs are the
98      * same length.  Can be NULL if there are no known key IDs.
99      */
100     ubyte** key_ids;
101     /** The number of key IDs. */
102     uint num_key_ids;
103     /**
104      * The number of bytes in each key ID.  This should always be 16, but may
105      * change in the future.
106      */
107     uint key_id_size;
108 
109     /**
110      * Key-system specific initialization data.  This data is copied directly
111      * from the file and the format depends on the specific key system.  This
112      * can be NULL if there is no initialization data; in that case, there
113      * will be at least one key ID.
114      */
115     ubyte* data;
116     uint data_size;
117 
118     /**
119      * An optional pointer to the next initialization info in the list.
120      */
121     AVEncryptionInitInfo* next;
122 }
123 
124 /**
125  * Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
126  * number of subsamples.  This will allocate pointers for the key ID, IV,
127  * and subsample entries, set the size members, and zero-initialize the rest.
128  *
129  * @param subsample_count The number of subsamples.
130  * @param key_id_size The number of bytes in the key ID, should be 16.
131  * @param iv_size The number of bytes in the IV, should be 16.
132  *
133  * @return The new AVEncryptionInfo structure, or NULL on error.
134  */
135 AVEncryptionInfo* av_encryption_info_alloc (uint subsample_count, uint key_id_size, uint iv_size);
136 
137 /**
138  * Allocates an AVEncryptionInfo structure with a copy of the given data.
139  * @return The new AVEncryptionInfo structure, or NULL on error.
140  */
141 AVEncryptionInfo* av_encryption_info_clone (const(AVEncryptionInfo)* info);
142 
143 /**
144  * Frees the given encryption info object.  This MUST NOT be used to free the
145  * side-data data pointer, that should use normal side-data methods.
146  */
147 void av_encryption_info_free (AVEncryptionInfo* info);
148 
149 /**
150  * Creates a copy of the AVEncryptionInfo that is contained in the given side
151  * data.  The resulting object should be passed to av_encryption_info_free()
152  * when done.
153  *
154  * @return The new AVEncryptionInfo structure, or NULL on error.
155  */
156 AVEncryptionInfo* av_encryption_info_get_side_data (const(ubyte)* side_data, size_t side_data_size);
157 
158 /**
159  * Allocates and initializes side data that holds a copy of the given encryption
160  * info.  The resulting pointer should be either freed using av_free or given
161  * to av_packet_add_side_data().
162  *
163  * @return The new side-data pointer, or NULL.
164  */
165 ubyte* av_encryption_info_add_side_data (
166     const(AVEncryptionInfo)* info,
167     size_t* side_data_size);
168 
169 /**
170  * Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
171  * given sizes.  This will allocate pointers and set all the fields.
172  *
173  * @return The new AVEncryptionInitInfo structure, or NULL on error.
174  */
175 AVEncryptionInitInfo* av_encryption_init_info_alloc (
176     uint system_id_size,
177     uint num_key_ids,
178     uint key_id_size,
179     uint data_size);
180 
181 /**
182  * Frees the given encryption init info object.  This MUST NOT be used to free
183  * the side-data data pointer, that should use normal side-data methods.
184  */
185 void av_encryption_init_info_free (AVEncryptionInitInfo* info);
186 
187 /**
188  * Creates a copy of the AVEncryptionInitInfo that is contained in the given
189  * side data.  The resulting object should be passed to
190  * av_encryption_init_info_free() when done.
191  *
192  * @return The new AVEncryptionInitInfo structure, or NULL on error.
193  */
194 AVEncryptionInitInfo* av_encryption_init_info_get_side_data (
195     const(ubyte)* side_data,
196     size_t side_data_size);
197 
198 /**
199  * Allocates and initializes side data that holds a copy of the given encryption
200  * init info.  The resulting pointer should be either freed using av_free or
201  * given to av_packet_add_side_data().
202  *
203  * @return The new side-data pointer, or NULL.
204  */
205 ubyte* av_encryption_init_info_add_side_data (
206     const(AVEncryptionInitInfo)* info,
207     size_t* side_data_size);
208 
209 /* AVUTIL_ENCRYPTION_INFO_H */