Skip to content

Commit

Permalink
CI: enable clang-format and fix the files
Browse files Browse the repository at this point in the history
To review this commit, go to the directly previous commit,
edit .pre-commit-config.yaml to uncomment the same things that were
uncommented in this commit, exec pre-commit run --all-files, and diff
against this commit.

In short:
```
:; COMMIT=$(git rev-parse HEAD)
:; git checkout HEAD~
:; git diff $COMMIT -- .pre-commit-config.yaml | patch -p1 -R
:; pre-commit run --all-files
:; git diff $COMMIT
```

To get back to your tree:
```
:; git reset --hard $COMMIT
:; git checkout -
```
  • Loading branch information
elric1 committed Sep 20, 2023
1 parent 69bfdb3 commit 1fad89a
Show file tree
Hide file tree
Showing 37 changed files with 1,790 additions and 1,546 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repos:
- id: check-yaml
- id: check-added-large-files

# - repo: https://github.com/pre-commit/mirrors-clang-format
# rev: v16.0.6
# hooks:
# - id: clang-format
# types_or: [c]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.6
hooks:
- id: clang-format
types_or: [c]
22 changes: 12 additions & 10 deletions app/src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,32 @@
#include "apdu.h"
#include "globals.h"

const uint8_t version[4] = {
0 /* wallet */,
MAJOR_VERSION,
MINOR_VERSION,
PATCH_VERSION
};

void handle_unimplemented(__attribute__((unused))command_t *cmd) {
const uint8_t version[4]
= {0 /* wallet */, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION};

void
handle_unimplemented(__attribute__((unused)) command_t *cmd)
{
TZ_PREAMBLE(("cmd=0x%p", cmd));

PRINTF("[ERROR] Unimplemented instruction 0x%02x\n", cmd->ins);
TZ_FAIL(EXC_INVALID_INS);
TZ_POSTAMBLE;
}

void handle_apdu_version(__attribute__((unused))command_t *cmd) {
void
handle_apdu_version(__attribute__((unused)) command_t *cmd)
{
TZ_PREAMBLE(("cmd=0x%p", cmd));

TZ_ASSERT(EXC_UNEXPECTED_STATE, global.step == ST_IDLE);
io_send_response_pointer((void *)&version, sizeof(version), SW_OK);
TZ_POSTAMBLE;
}

void handle_apdu_git(__attribute__((unused))command_t *cmd) {
void
handle_apdu_git(__attribute__((unused)) command_t *cmd)
{
static const char commit[] = COMMIT;
TZ_PREAMBLE(("cmd=0x%p", cmd));

Expand Down
4 changes: 2 additions & 2 deletions app/src/apdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define INS_SIGN_WITH_HASH 0x0F

// Last valid instruction code
#define INS_MAX 0x0F
#define INS_MAX 0x0F

/*
* All of the handlers must be defined together below. We
Expand Down Expand Up @@ -82,7 +82,7 @@
*
*/

typedef void (tz_handler)(command_t *);
typedef void(tz_handler)(command_t *);
typedef tz_handler *tz_handler_t;

tz_handler handle_unimplemented;
Expand Down
70 changes: 47 additions & 23 deletions app/src/apdu_pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ static void prompt_address(void);
static void format_pkh(char *);
static void stream_cb(tz_ui_cb_type_t);

static void provide_pubkey(void) {
buffer_t bufs[2] = {0};
uint8_t byte;
static void
provide_pubkey(void)
{
buffer_t bufs[2] = {0};
uint8_t byte;
cx_ecfp_public_key_t pubkey;
TZ_PREAMBLE(("void"));

// Application could be PIN-locked, and pubkey->W_len would then be 0,
// so throwing an error rather than returning an empty key
TZ_ASSERT(EXC_SECURITY, os_global_pin_is_validated() == BOLOS_UX_OK);
TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
TZ_CHECK(generate_public_key(&pubkey,
global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));

byte = pubkey.W_len;
Expand All @@ -60,12 +63,15 @@ static void provide_pubkey(void) {
TZ_POSTAMBLE;
}

static void format_pkh(char *buffer) {
static void
format_pkh(char *buffer)
{
cx_ecfp_public_key_t pubkey = {0};
uint8_t hash[21];
uint8_t hash[21];
TZ_PREAMBLE(("buffer=%p", buffer));

TZ_CHECK(generate_public_key(&pubkey, global.path_with_curve.derivation_type,
TZ_CHECK(generate_public_key(&pubkey,
global.path_with_curve.derivation_type,
&global.path_with_curve.bip32_path));
// clang-format off
TZ_CHECK(public_key_hash(hash+1, 20, NULL,
Expand All @@ -83,7 +89,9 @@ static void format_pkh(char *buffer) {
TZ_POSTAMBLE;
}

static void stream_cb(tz_ui_cb_type_t type) {
static void
stream_cb(tz_ui_cb_type_t type)
{
TZ_PREAMBLE(("type=%u", type));

// clang-format off
Expand All @@ -98,7 +106,9 @@ static void stream_cb(tz_ui_cb_type_t type) {
}

#ifdef HAVE_BAGL
static void prompt_address(void) {
static void
prompt_address(void)
{
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));

Expand All @@ -117,25 +127,33 @@ static void prompt_address(void) {

#include "nbgl_use_case.h"

static void cancel_callback(void) {
static void
cancel_callback(void)
{
stream_cb(TZ_UI_STREAM_CB_REJECT);
nbgl_useCaseStatus("Address rejected", false, ui_home_init);
}

static void approve_callback(void) {
static void
approve_callback(void)
{
stream_cb(TZ_UI_STREAM_CB_ACCEPT);
nbgl_useCaseStatus("ADDRESS\nVERIFIED", true, ui_home_init);
}

static void confirmation_callback(bool confirm) {
static void
confirmation_callback(bool confirm)
{
if (confirm) {
approve_callback();
approve_callback();
} else {
cancel_callback();
cancel_callback();
}
}

static void verify_address(void) {
static void
verify_address(void)
{
char buf[TZ_UI_STREAM_CONTENTS_SIZE + 1];
TZ_PREAMBLE(("void"));

Expand All @@ -144,16 +162,21 @@ static void verify_address(void) {
TZ_POSTAMBLE;
}

static void prompt_address(void) {
static void
prompt_address(void)
{
TZ_PREAMBLE(("void"));

global.step = ST_PROMPT;
nbgl_useCaseReviewStart(&C_tezos, "Verify Tezos\naddress", NULL, "Cancel", verify_address, cancel_callback);
nbgl_useCaseReviewStart(&C_tezos, "Verify Tezos\naddress", NULL, "Cancel",
verify_address, cancel_callback);
TZ_POSTAMBLE;
}
#endif

void handle_apdu_get_public_key(command_t *cmd) {
void
handle_apdu_get_public_key(command_t *cmd)
{
bool prompt = cmd->ins == INS_PROMPT_PUBLIC_KEY;
TZ_PREAMBLE(("cmd=%p", cmd));

Expand All @@ -162,17 +185,18 @@ void handle_apdu_get_public_key(command_t *cmd) {

// do not expose pks without prompt through U2F (permissionless legacy
// comm in browser)
TZ_ASSERT(EXC_HID_REQUIRED, prompt || G_io_apdu_media != IO_APDU_MEDIA_U2F);
TZ_ASSERT(EXC_HID_REQUIRED,
prompt || G_io_apdu_media != IO_APDU_MEDIA_U2F);

global.path_with_curve.derivation_type = cmd->p2;
TZ_ASSERT(EXC_WRONG_PARAM,
check_derivation_type(global.path_with_curve.derivation_type));
TZ_CHECK(read_bip32_path(&global.path_with_curve.bip32_path,
cmd->data, cmd->lc));
TZ_CHECK(read_bip32_path(&global.path_with_curve.bip32_path, cmd->data,
cmd->lc));
if (prompt)
prompt_address();
prompt_address();
else
provide_pubkey();
provide_pubkey();

TZ_POSTAMBLE;
}
Loading

0 comments on commit 1fad89a

Please sign in to comment.