Skip to content

Commit

Permalink
[coco][fuji] base64_decode_compute
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed May 1, 2024
1 parent 69aaf3c commit 8b577c1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 44 additions & 1 deletion lib/device/drivewire/fuji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ void drivewireFuji::base64_encode_output()
{
uint8_t lenl = fnUartBUS.read();
uint8_t lenh = fnUartBUS.read();
uint16_t len = lenl << 8 | lenl;
uint16_t len = lenh << 8 | lenl;

if (!len)
{
Expand All @@ -1369,6 +1369,47 @@ void drivewireFuji::base64_encode_output()
errorCode = 1;
}

void drivewireFuji::base64_decode_input()
{
uint8_t lenl = fnUartBUS.read();
uint8_t lenh = fnUartBUS.read();
uint16_t len = lenh << 8 | lenl;

if (!len)
{
Debug_printf("Refusing to input zero length. Exiting.\n");
errorCode = 144;
return;
}

std::vector<unsigned char> p(len);
fnUartBUS.readBytes(p.data(), len);
base64.base64_buffer += std::string((const char *)p.data(), len);

errorCode = 1;
}

void drivewireFuji::base64_decode_compute()
{
size_t out_len;

Debug_printf("FUJI: BASE64 DECODE COMPUTE\n");

std::unique_ptr<unsigned char[]> p = Base64::decode(base64.base64_buffer.c_str(), base64.base64_buffer.size(), &out_len);
if (!p)
{
Debug_printf("base64_encode compute failed\n");
errorCode = 144;
return;
}

base64.base64_buffer.clear();
base64.base64_buffer = std::string((const char *)p.get(), out_len);

Debug_printf("Resulting BASE64 encoded data is: %u bytes\n", out_len);
errorCode = 1;
}

// Initializes base settings and adds our devices to the DRIVEWIRE bus
void drivewireFuji::setup(systemBus *drivewirebus)
{
Expand Down Expand Up @@ -1542,8 +1583,10 @@ void drivewireFuji::process()
base64_encode_output();
break;
case FUJICMD_BASE64_DECODE_INPUT:
base64_decode_input();
break;
case FUJICMD_BASE64_DECODE_COMPUTE:
base64_decode_compute();
break;
case FUJICMD_BASE64_DECODE_LENGTH:
break;
Expand Down
2 changes: 2 additions & 0 deletions lib/device/drivewire/fuji.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class drivewireFuji : public virtualDevice
void base64_encode_compute(); // 0xCF
void base64_encode_length(); // 0xCE
void base64_encode_output(); // 0xCD
void base64_decode_input(); // 0xCB
void base64_decode_compute(); // 0xCC
void send_error();
void send_response(); // 0x01
void ready(); // 0x00
Expand Down

0 comments on commit 8b577c1

Please sign in to comment.