UEFI interface to base54 decode. * Decodes EncodedData into a new allocated buffer and returns it. Caller is responsible to FreePool() it. * If DecodedSize != NULL, then size od decoded data is put there. * If return value is not NULL, DecodedSize IS > 0 */
| 94 | * If return value is not NULL, DecodedSize IS > 0 |
| 95 | */ |
| 96 | UINT8 *Base64DecodeClover(IN CONST CHAR8 *EncodedData, OUT UINTN *DecodedSize) |
| 97 | { |
| 98 | UINTN EncodedSize; |
| 99 | INTN DecodedSizeInternal; |
| 100 | UINT8 *DecodedData; |
| 101 | base64_decodestate state_in; |
| 102 | |
| 103 | if (EncodedData == NULL) { |
| 104 | return NULL; |
| 105 | } |
| 106 | EncodedSize = strlen(EncodedData); |
| 107 | if (EncodedSize == 0) { |
| 108 | return NULL; |
| 109 | } |
| 110 | // to simplify, we'll allocate the same size, although smaller size is needed |
| 111 | DecodedData = (__typeof__(DecodedData))AllocateZeroPool(EncodedSize); |
| 112 | |
| 113 | base64_init_decodestate(&state_in); |
| 114 | DecodedSizeInternal = base64_decode_block(EncodedData, (const int)EncodedSize, (char*) DecodedData, &state_in); |
| 115 | |
| 116 | if ( DecodedSizeInternal == 0 ) { |
| 117 | FreePool(DecodedData); |
| 118 | DecodedData = NULL; |
| 119 | } |
| 120 | |
| 121 | if (DecodedSize != NULL) { |
| 122 | if ( DecodedSizeInternal < 0 ) panic("Base64DecodeClover : DecodedSizeInternal < 0"); |
| 123 | *DecodedSize = (UINTN)DecodedSizeInternal; |
| 124 | } |
| 125 | |
| 126 | return DecodedData; |
| 127 | } |
no test coverage detected