/** @file\r
Helper functions for SecureBoot configuration module.\r
\r
-Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
#include "SecureBootConfigImpl.h"\r
\r
/**\r
- Read file content into BufferPtr, the size of the allocate buffer \r
+ Read file content into BufferPtr, the size of the allocate buffer\r
is *FileSize plus AddtionAllocateSize.\r
\r
@param[in] FileHandle The file to be read.\r
@param[in, out] BufferPtr Pointers to the pointer of allocated buffer.\r
@param[out] FileSize Size of input file\r
- @param[in] AddtionAllocateSize Addtion size the buffer need to be allocated. \r
+ @param[in] AddtionAllocateSize Addtion size the buffer need to be allocated.\r
In case the buffer need to contain others besides the file content.\r
- \r
+\r
@retval EFI_SUCCESS The file was read into the buffer.\r
@retval EFI_INVALID_PARAMETER A parameter was invalid.\r
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
if (EFI_ERROR (Status)) {\r
goto ON_EXIT;\r
}\r
- \r
+\r
Status = FileHandle->SetPosition (FileHandle, 0);\r
if (EFI_ERROR (Status)) {\r
goto ON_EXIT;\r
}\r
\r
ON_EXIT:\r
- \r
+\r
*BufferPtr = Buffer;\r
return Status;\r
}\r
Close an open file handle.\r
\r
@param[in] FileHandle The file handle to close.\r
- \r
+\r
**/\r
VOID\r
CloseFile (\r
)\r
{\r
if (FileHandle != NULL) {\r
- FileHandle->Close (FileHandle); \r
+ FileHandle->Close (FileHandle);\r
}\r
}\r
\r
\r
@param[in] Integer Pointer to the nonnegative integer to be converted\r
@param[in] IntSizeInWords Length of integer buffer in words\r
- @param[out] OctetString Converted octet string of the specified length \r
+ @param[out] OctetString Converted octet string of the specified length\r
@param[in] OSSizeInBytes Intended length of resulting octet string in bytes\r
\r
Returns:\r
Ptr1++, Ptr2--) {\r
*Ptr2 = *Ptr1;\r
}\r
- \r
+\r
for (; Ptr1 < (CONST UINT8 *)(Integer + IntSizeInWords) && *Ptr1 == 0; Ptr1++);\r
- \r
+\r
if (Ptr1 < (CONST UINT8 *)(Integer + IntSizeInWords)) {\r
return EFI_BUFFER_TOO_SMALL;\r
}\r
- \r
+\r
if (Ptr2 >= OctetString) {\r
ZeroMem (OctetString, Ptr2 - OctetString + 1);\r
}\r
- \r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
-/**\r
- Convert a String to Guid Value.\r
-\r
- @param[in] Str Specifies the String to be converted.\r
- @param[in] StrLen Number of Unicode Characters of String (exclusive \0)\r
- @param[out] Guid Return the result Guid value.\r
-\r
- @retval EFI_SUCCESS The operation is finished successfully.\r
- @retval EFI_NOT_FOUND Invalid string.\r
-\r
-**/\r
-EFI_STATUS\r
-StringToGuid (\r
- IN CHAR16 *Str, \r
- IN UINTN StrLen, \r
- OUT EFI_GUID *Guid\r
- )\r
-{\r
- CHAR16 *PtrBuffer;\r
- CHAR16 *PtrPosition;\r
- UINT16 *Buffer;\r
- UINTN Data;\r
- UINTN Index;\r
- UINT16 Digits[3];\r
-\r
- Buffer = (CHAR16 *) AllocateZeroPool (sizeof (CHAR16) * (StrLen + 1));\r
- if (Buffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- StrCpy (Buffer, Str);\r
-\r
- //\r
- // Data1\r
- //\r
- PtrBuffer = Buffer;\r
- PtrPosition = PtrBuffer; \r
- while (*PtrBuffer != L'\0') {\r
- if (*PtrBuffer == L'-') {\r
- break;\r
- }\r
- PtrBuffer++;\r
- }\r
- if (*PtrBuffer == L'\0') {\r
- FreePool (Buffer);\r
- return EFI_NOT_FOUND;\r
- }\r
-\r
- *PtrBuffer = L'\0';\r
- Data = StrHexToUintn (PtrPosition);\r
- Guid->Data1 = (UINT32)Data;\r
-\r
- //\r
- // Data2\r
- //\r
- PtrBuffer++;\r
- PtrPosition = PtrBuffer;\r
- while (*PtrBuffer != L'\0') {\r
- if (*PtrBuffer == L'-') {\r
- break;\r
- }\r
- PtrBuffer++;\r
- }\r
- if (*PtrBuffer == L'\0') {\r
- FreePool (Buffer);\r
- return EFI_NOT_FOUND;\r
- }\r
- *PtrBuffer = L'\0';\r
- Data = StrHexToUintn (PtrPosition);\r
- Guid->Data2 = (UINT16)Data;\r
-\r
- //\r
- // Data3\r
- //\r
- PtrBuffer++;\r
- PtrPosition = PtrBuffer;\r
- while (*PtrBuffer != L'\0') {\r
- if (*PtrBuffer == L'-') {\r
- break;\r
- }\r
- PtrBuffer++;\r
- }\r
- if (*PtrBuffer == L'\0') {\r
- FreePool (Buffer);\r
- return EFI_NOT_FOUND;\r
- }\r
- *PtrBuffer = L'\0';\r
- Data = StrHexToUintn (PtrPosition);\r
- Guid->Data3 = (UINT16)Data;\r
-\r
- //\r
- // Data4[0..1]\r
- //\r
- for ( Index = 0 ; Index < 2 ; Index++) {\r
- PtrBuffer++;\r
- if ((*PtrBuffer == L'\0') || ( *(PtrBuffer + 1) == L'\0')) {\r
- FreePool (Buffer);\r
- return EFI_NOT_FOUND;\r
- }\r
- Digits[0] = *PtrBuffer;\r
- PtrBuffer++;\r
- Digits[1] = *PtrBuffer;\r
- Digits[2] = L'\0';\r
- Data = StrHexToUintn (Digits);\r
- Guid->Data4[Index] = (UINT8)Data;\r
- }\r
-\r
- //\r
- // skip the '-'\r
- //\r
- PtrBuffer++;\r
- if ((*PtrBuffer != L'-' ) || ( *PtrBuffer == L'\0')) {\r
- return EFI_NOT_FOUND;\r
- }\r
\r
- //\r
- // Data4[2..7]\r
- //\r
- for ( ; Index < 8; Index++) {\r
- PtrBuffer++;\r
- if ((*PtrBuffer == L'\0') || ( *(PtrBuffer + 1) == L'\0')) {\r
- FreePool (Buffer);\r
- return EFI_NOT_FOUND;\r
- }\r
- Digits[0] = *PtrBuffer;\r
- PtrBuffer++;\r
- Digits[1] = *PtrBuffer;\r
- Digits[2] = L'\0';\r
- Data = StrHexToUintn (Digits);\r
- Guid->Data4[Index] = (UINT8)Data;\r
- }\r
-\r
- FreePool (Buffer);\r
- \r
return EFI_SUCCESS;\r
}\r
\r
@param[in] Guid Pointer to GUID to print.\r
@param[in] Buffer Buffer to print Guid into.\r
@param[in] BufferSize Size of Buffer.\r
- \r
+\r
@retval Number of characters printed.\r
\r
**/\r
\r
Size = UnicodeSPrint (\r
Buffer,\r
- BufferSize, \r
+ BufferSize,\r
L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
- (UINTN)Guid->Data1, \r
+ (UINTN)Guid->Data1,\r
(UINTN)Guid->Data2,\r
(UINTN)Guid->Data3,\r
(UINTN)Guid->Data4[0],\r