Skip to content

Commit

Permalink
Lint: apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Apr 4, 2024
1 parent 7f6ee88 commit de37b89
Show file tree
Hide file tree
Showing 42 changed files with 3,976 additions and 4,069 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/coding_style_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run coding style check through reusable workflow

# This workflow will run linting checks to ensure a level of uniformization among all Ledger applications.
#
# The presence of this workflow is mandatory as a minimal level of linting is required.
# You are however free to modify the content of the .clang-format file and thus the coding style of your application.
# We simply ask you to not diverge too much from the linting of the Boilerplate application.

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
pull_request:

jobs:
check_linting:
name: Check linting using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_lint.yml@v1
with:
source: './src'
extensions: 'h,c'
version: 11
49 changes: 26 additions & 23 deletions lib-app-bitcoin/apdu/apdu_constants.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*******************************************************************************
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#pragma once

#include "os.h"
#include "buffer.h"
#include "macros.h"
#include "os.h"

#define CLA 0xE0

Expand Down Expand Up @@ -49,12 +49,15 @@
#define ZCASH_USING_OVERWINTER 0x01
#define ZCASH_USING_OVERWINTER_SAPLING 0x02

unsigned short handler_sign_message(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_hash_sign(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_hash_input_start(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_hash_input_finalize_full(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_get_wallet_public_key(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_get_trusted_input(buffer_t* buffer, uint8_t p1, uint8_t p2);
unsigned short handler_sign_message(buffer_t *buffer, uint8_t p1, uint8_t p2);
unsigned short handler_hash_sign(buffer_t *buffer, uint8_t p1, uint8_t p2);
unsigned short handler_hash_input_start(buffer_t *buffer, uint8_t p1,
uint8_t p2);
unsigned short handler_hash_input_finalize_full(buffer_t *buffer, uint8_t p1,
uint8_t p2);
unsigned short handler_get_wallet_public_key(buffer_t *buffer, uint8_t p1,
uint8_t p2);
unsigned short handler_get_trusted_input(buffer_t *buffer, uint8_t p1,
uint8_t p2);
unsigned short handler_get_firmware_version(void);
unsigned short handler_get_coin_version(void);

172 changes: 86 additions & 86 deletions lib-app-bitcoin/apdu/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,103 +15,103 @@
* limitations under the License.
*****************************************************************************/

#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>

#include "buffer.h"
#include "io.h"
#include "ledger_assert.h"

#include "dispatcher.h"
#include "apdu_constants.h"
#include "dispatcher.h"

int apdu_dispatcher(const command_t *cmd) {
LEDGER_ASSERT(cmd != NULL, "NULL cmd");
LEDGER_ASSERT(cmd != NULL, "NULL cmd");

if (cmd->cla != CLA) {
return io_send_sw(SW_CLA_NOT_SUPPORTED);
}

buffer_t buf = {0};

if (cmd->cla != CLA) {
return io_send_sw(SW_CLA_NOT_SUPPORTED);
switch (cmd->ins) {
case INS_GET_WALLET_PUBLIC_KEY:
PRINTF("Get wallet public key\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}
buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_get_wallet_public_key(&buf, cmd->p1, cmd->p2);

case INS_GET_TRUSTED_INPUT:
PRINTF("Get trusted input\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_get_trusted_input(&buf, cmd->p1, cmd->p2);

case INS_HASH_INPUT_START:
PRINTF("Hash input start\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_input_start(&buf, cmd->p1, cmd->p2);

buffer_t buf = {0};

switch (cmd->ins) {
case INS_GET_WALLET_PUBLIC_KEY:
PRINTF("Get wallet public key\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}
buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_get_wallet_public_key(&buf, cmd->p1, cmd->p2);

case INS_GET_TRUSTED_INPUT:
PRINTF("Get trusted input\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_get_trusted_input(&buf, cmd->p1, cmd->p2);

case INS_HASH_INPUT_START:
PRINTF("Hash input start\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_input_start(&buf, cmd->p1, cmd->p2);

case INS_HASH_SIGN:
PRINTF("Hash sign\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_sign(&buf, cmd->p1, cmd->p2);

case INS_HASH_INPUT_FINALIZE_FULL:
PRINTF("Hash input finalize full\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_input_finalize_full(&buf, cmd->p1, cmd->p2);

case INS_SIGN_MESSAGE:
PRINTF("Sign message\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_sign_message(&buf, cmd->p1, cmd->p2);

case INS_GET_FIRMWARE_VERSION:
PRINTF("Get firmware version\n");

return handler_get_firmware_version();

case INS_GET_COIN_VER:
PRINTF("Get coin version\n");

return handler_get_coin_version();

default:
PRINTF("Instruction not supported\n");
return io_send_sw(SW_INS_NOT_SUPPORTED);
case INS_HASH_SIGN:
PRINTF("Hash sign\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_sign(&buf, cmd->p1, cmd->p2);

case INS_HASH_INPUT_FINALIZE_FULL:
PRINTF("Hash input finalize full\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_hash_input_finalize_full(&buf, cmd->p1, cmd->p2);

case INS_SIGN_MESSAGE:
PRINTF("Sign message\n");
if (!cmd->data) {
return io_send_sw(SW_INCORRECT_LENGTH);
}

buf.ptr = cmd->data;
buf.size = cmd->lc;
buf.offset = 0;
return handler_sign_message(&buf, cmd->p1, cmd->p2);

case INS_GET_FIRMWARE_VERSION:
PRINTF("Get firmware version\n");

return handler_get_firmware_version();

case INS_GET_COIN_VER:
PRINTF("Get coin version\n");

return handler_get_coin_version();

default:
PRINTF("Instruction not supported\n");
return io_send_sw(SW_INS_NOT_SUPPORTED);
}
}
100 changes: 47 additions & 53 deletions lib-app-bitcoin/app_main.c
Original file line number Diff line number Diff line change
@@ -1,72 +1,66 @@
/*******************************************************************************
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#include "swap.h"
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#include "io.h"
#include "swap.h"

#include "context.h"
#include "apdu_constants.h"
#include "context.h"
#include "dispatcher.h"
#include "ui.h"


void app_main(void) {
// Structured APDU command
command_t cmd;
// Structured APDU command
command_t cmd;

io_init();
io_init();

if (!G_called_from_swap) {
ui_idle_flow();
}
if (!G_called_from_swap) {
ui_idle_flow();
}

context_init();
context_init();

for (;;) {
// Length of APDU command received in G_io_apdu_buffer
int input_len = 0;
for (;;) {
// Length of APDU command received in G_io_apdu_buffer
int input_len = 0;

// Receive command bytes in G_io_apdu_buffer
if ((input_len = io_recv_command()) < 0) {
PRINTF("=> io_recv_command failure\n");
return;
}
// Receive command bytes in G_io_apdu_buffer
if ((input_len = io_recv_command()) < 0) {
PRINTF("=> io_recv_command failure\n");
return;
}

// Parse APDU command from G_io_apdu_buffer
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) {
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer);
io_send_sw(SW_INCORRECT_LENGTH);
continue;
}
// Parse APDU command from G_io_apdu_buffer
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) {
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer);
io_send_sw(SW_INCORRECT_LENGTH);
continue;
}

PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n",
cmd.cla,
cmd.ins,
cmd.p1,
cmd.p2,
cmd.lc,
cmd.lc,
cmd.data);
PRINTF(
"=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n",
cmd.cla, cmd.ins, cmd.p1, cmd.p2, cmd.lc, cmd.lc, cmd.data);

context.outLength = 0;
context.outLength = 0;

// Dispatch structured APDU command to handler
if (apdu_dispatcher(&cmd) < 0) {
PRINTF("=> apdu_dispatcher failure\n");
return;
}
// Dispatch structured APDU command to handler
if (apdu_dispatcher(&cmd) < 0) {
PRINTF("=> apdu_dispatcher failure\n");
return;
}
}
}
Loading

0 comments on commit de37b89

Please sign in to comment.