]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BrotliCustomDecompressLib/GuidedSectionExtraction.c
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / GuidedSectionExtraction.c
CommitLineData
841b2590
SB
1/** @file\r
2 BROTLI Decompress GUIDed Section Extraction Library.\r
3 It wraps Brotli decompress interfaces to GUIDed Section Extraction interfaces\r
4 and registers them into GUIDed handler table.\r
5\r
6 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
9d510e61 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
841b2590
SB
8\r
9**/\r
10\r
11#include <BrotliDecompressLibInternal.h>\r
12\r
13/**\r
14 Examines a GUIDed section and returns the size of the decoded buffer and the\r
15 size of an scratch buffer required to actually decode the data in a GUIDed section.\r
16\r
17 Examines a GUIDed section specified by InputSection.\r
18 If GUID for InputSection does not match the GUID that this handler supports,\r
19 then RETURN_UNSUPPORTED is returned.\r
20 If the required information can not be retrieved from InputSection,\r
21 then RETURN_INVALID_PARAMETER is returned.\r
22 If the GUID of InputSection does match the GUID that this handler supports,\r
23 then the size required to hold the decoded buffer is returned in OututBufferSize,\r
24 the size of an optional scratch buffer is returned in ScratchSize, and the Attributes field\r
25 from EFI_GUID_DEFINED_SECTION header of InputSection is returned in SectionAttribute.\r
26\r
27 If InputSection is NULL, then ASSERT().\r
28 If OutputBufferSize is NULL, then ASSERT().\r
29 If ScratchBufferSize is NULL, then ASSERT().\r
30 If SectionAttribute is NULL, then ASSERT().\r
31\r
32\r
33 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
34 @param[out] OutputBufferSize A pointer to the size, in bytes, of an output buffer required\r
35 if the buffer specified by InputSection were decoded.\r
36 @param[out] ScratchBufferSize A pointer to the size, in bytes, required as scratch space\r
37 if the buffer specified by InputSection were decoded.\r
38 @param[out] SectionAttribute A pointer to the attributes of the GUIDed section. See the Attributes\r
39 field of EFI_GUID_DEFINED_SECTION in the PI Specification.\r
40\r
41 @retval RETURN_SUCCESS The information about InputSection was returned.\r
42 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
43 @retval RETURN_INVALID_PARAMETER The information can not be retrieved from the section specified by InputSection.\r
44\r
45**/\r
46RETURN_STATUS\r
47EFIAPI\r
48BrotliGuidedSectionGetInfo (\r
49 IN CONST VOID *InputSection,\r
50 OUT UINT32 *OutputBufferSize,\r
51 OUT UINT32 *ScratchBufferSize,\r
52 OUT UINT16 *SectionAttribute\r
53 )\r
54{\r
55 ASSERT (InputSection != NULL);\r
56 ASSERT (OutputBufferSize != NULL);\r
57 ASSERT (ScratchBufferSize != NULL);\r
58 ASSERT (SectionAttribute != NULL);\r
59\r
60 if (IS_SECTION2 (InputSection)) {\r
61 if (!CompareGuid (\r
62 &gBrotliCustomDecompressGuid,\r
63 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
64 return RETURN_INVALID_PARAMETER;\r
65 }\r
66\r
67 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->Attributes;\r
68\r
69 return BrotliUefiDecompressGetInfo (\r
70 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
71 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
72 OutputBufferSize,\r
73 ScratchBufferSize\r
74 );\r
75 } else {\r
76 if (!CompareGuid (\r
77 &gBrotliCustomDecompressGuid,\r
78 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
79 return RETURN_INVALID_PARAMETER;\r
80 }\r
81\r
82 *SectionAttribute = ((EFI_GUID_DEFINED_SECTION *) InputSection)->Attributes;\r
83\r
84 return BrotliUefiDecompressGetInfo (\r
85 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
86 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
87 OutputBufferSize,\r
88 ScratchBufferSize\r
89 );\r
90 }\r
91}\r
92\r
93/**\r
94 Decompress a BROTLI compressed GUIDed section into a caller allocated output buffer.\r
95\r
96 Decodes the GUIDed section specified by InputSection.\r
97 If GUID for InputSection does not match the GUID that this handler supports, then RETURN_UNSUPPORTED is returned.\r
98 If the data in InputSection can not be decoded, then RETURN_INVALID_PARAMETER is returned.\r
99 If the GUID of InputSection does match the GUID that this handler supports, then InputSection\r
100 is decoded into the buffer specified by OutputBuffer and the authentication status of this\r
101 decode operation is returned in AuthenticationStatus. If the decoded buffer is identical to the\r
102 data in InputSection, then OutputBuffer is set to point at the data in InputSection. Otherwise,\r
103 the decoded data will be placed in caller allocated buffer specified by OutputBuffer.\r
104\r
105 If InputSection is NULL, then ASSERT().\r
106 If OutputBuffer is NULL, then ASSERT().\r
107 If ScratchBuffer is NULL and this decode operation requires a scratch buffer, then ASSERT().\r
108 If AuthenticationStatus is NULL, then ASSERT().\r
109\r
110 @param[in] InputSection A pointer to a GUIDed section of an FFS formatted file.\r
111 @param[out] OutputBuffer A pointer to a buffer that contains the result of a decode operation.\r
112 @param[out] ScratchBuffer A caller allocated buffer that may be required by this function\r
113 as a scratch buffer to perform the decode operation.\r
114 @param[out] AuthenticationStatus\r
115 A pointer to the authentication status of the decoded output buffer.\r
116 See the definition of authentication status in the EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI\r
117 section of the PI Specification. EFI_AUTH_STATUS_PLATFORM_OVERRIDE must\r
118 never be set by this handler.\r
119\r
120 @retval RETURN_SUCCESS The buffer specified by InputSection was decoded.\r
121 @retval RETURN_UNSUPPORTED The section specified by InputSection does not match the GUID this handler supports.\r
122 @retval RETURN_INVALID_PARAMETER The section specified by InputSection can not be decoded.\r
123\r
124**/\r
125RETURN_STATUS\r
126EFIAPI\r
127BrotliGuidedSectionExtraction (\r
128 IN CONST VOID *InputSection,\r
129 OUT VOID **OutputBuffer,\r
e3917e22 130 OUT VOID *ScratchBuffer OPTIONAL,\r
841b2590
SB
131 OUT UINT32 *AuthenticationStatus\r
132 )\r
133{\r
134 ASSERT (OutputBuffer != NULL);\r
135 ASSERT (InputSection != NULL);\r
136\r
137 if (IS_SECTION2 (InputSection)) {\r
138 if (!CompareGuid (\r
139 &gBrotliCustomDecompressGuid,\r
140 &(((EFI_GUID_DEFINED_SECTION2 *) InputSection)->SectionDefinitionGuid))) {\r
141 return RETURN_INVALID_PARAMETER;\r
142 }\r
143 //\r
144 // Authentication is set to Zero, which may be ignored.\r
145 //\r
146 *AuthenticationStatus = 0;\r
147\r
148 return BrotliUefiDecompress (\r
149 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
150 SECTION2_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION2 *) InputSection)->DataOffset,\r
151 *OutputBuffer,\r
152 ScratchBuffer\r
153 );\r
154 } else {\r
155 if (!CompareGuid (\r
156 &gBrotliCustomDecompressGuid,\r
157 &(((EFI_GUID_DEFINED_SECTION *) InputSection)->SectionDefinitionGuid))) {\r
158 return RETURN_INVALID_PARAMETER;\r
159 }\r
160 //\r
161 // Authentication is set to Zero, which may be ignored.\r
162 //\r
163 *AuthenticationStatus = 0;\r
164\r
165 return BrotliUefiDecompress (\r
166 (UINT8 *) InputSection + ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
167 SECTION_SIZE (InputSection) - ((EFI_GUID_DEFINED_SECTION *) InputSection)->DataOffset,\r
168 *OutputBuffer,\r
169 ScratchBuffer\r
170 );\r
171 }\r
172}\r
173\r
174/**\r
175 Register BrotliDecompress and BrotliDecompressGetInfo handlers with BrotliCustomerDecompressGuid.\r
176\r
177 @retval EFI_SUCCESS Register successfully.\r
178 @retval EFI_OUT_OF_RESOURCES No enough memory to store this handler.\r
179**/\r
180EFI_STATUS\r
181EFIAPI\r
182BrotliDecompressLibConstructor (\r
f826516d 183 VOID\r
841b2590
SB
184 )\r
185{\r
186 return ExtractGuidedSectionRegisterHandlers (\r
187 &gBrotliCustomDecompressGuid,\r
188 BrotliGuidedSectionGetInfo,\r
189 BrotliGuidedSectionExtraction\r
190 );\r
191}\r