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