MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / StrHexToBytes

Function StrHexToBytes

MdePkg/Library/BaseLib/SafeString.c:1636–1700  ·  view source on GitHub ↗

Convert a Null-terminated Unicode hexadecimal string to a byte array. This function outputs a byte array by interpreting the contents of the Unicode string specified by String in hexadecimal format. The format of the input Unicode string String is: [XX]* X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F]. The function decodes every two he

Source from the content-addressed store, hash-verified

1634 @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length / 2).
1635**/
1636RETURN_STATUS
1637EFIAPI
1638StrHexToBytes (
1639 IN CONST CHAR16 *String,
1640 IN UINTN Length,
1641 OUT UINT8 *Buffer,
1642 IN UINTN MaxBufferSize
1643 )
1644{
1645 UINTN Index;
1646
1647 ASSERT (((UINTN) String & BIT0) == 0);
1648
1649 //
1650 // 1. None of String or Buffer shall be a null pointer.
1651 //
1652 SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);
1653 SAFE_STRING_CONSTRAINT_CHECK ((Buffer != NULL), RETURN_INVALID_PARAMETER);
1654
1655 //
1656 // 2. Length shall not be greater than RSIZE_MAX.
1657 //
1658 if (RSIZE_MAX != 0) {
1659 SAFE_STRING_CONSTRAINT_CHECK ((Length <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
1660 }
1661
1662 //
1663 // 3. Length shall not be odd.
1664 //
1665 SAFE_STRING_CONSTRAINT_CHECK (((Length & BIT0) == 0), RETURN_INVALID_PARAMETER);
1666
1667 //
1668 // 4. MaxBufferSize shall equal to or greater than Length / 2.
1669 //
1670 SAFE_STRING_CONSTRAINT_CHECK ((MaxBufferSize >= Length / 2), RETURN_BUFFER_TOO_SMALL);
1671
1672 //
1673 // 5. String shall not contains invalid hexadecimal digits.
1674 //
1675 for (Index = 0; Index < Length; Index++) {
1676 if (!InternalIsHexaDecimalDigitCharacter (String[Index])) {
1677 break;
1678 }
1679 }
1680 if (Index != Length) {
1681 return RETURN_UNSUPPORTED;
1682 }
1683
1684 //
1685 // Convert the hex string to bytes.
1686 //
1687 for(Index = 0; Index < Length; Index++) {
1688
1689 //
1690 // For even characters, write the upper nibble for each buffer byte,
1691 // and for even characters, the lower nibble.
1692 //
1693 if ((Index & BIT0) == 0) {

Callers 7

StrToGuidFunction · 0.70
ConvertFromTextVendorFunction · 0.50
DevPathFromTextMACFunction · 0.50
DevPathFromTextBluetoothFunction · 0.50
ParseParameterDataFunction · 0.50

Calls 2

InternalHexCharToUintnFunction · 0.70

Tested by

no test coverage detected