Skip to content

Commit

Permalink
Reformat code for clang-format and provide disabled CI files
Browse files Browse the repository at this point in the history
  • Loading branch information
elric1 committed Sep 20, 2023
1 parent b076cd2 commit 3680da2
Show file tree
Hide file tree
Showing 39 changed files with 1,718 additions and 1,580 deletions.
39 changes: 39 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
Language: Cpp
BasedOnStyle: Chromium
IndentWidth: 4
ColumnLimit: 78
UseTab: Never
IndentCaseLabels: false
InsertBraces: false
PointerAlignment: Right

BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: true

BinPackArguments: true
BinPackParameters: true

AlignAfterOpenBracket: Align

AlignConsecutiveMacros:
Enabled: true
AcrossComments: true
AcrossEmptyLines: false

AlignConsecutiveDeclarations:
Enabled: true
AcrossComments: false
AcrossEmptyLines: false

AlignConsecutiveAssignments:
Enabled: true
AcrossComments: false
AcrossEmptyLines: false

AlignArrayOfStructures: Left
SortIncludes: Never
SpaceAfterCStyleCast: false
AllowShortEnumsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
...
13 changes: 13 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: pre-commit

on: [pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# To install hooks, run:
# pre-commit install --hook-type pre-commit
# pre-commit install --hook-type commit-msg

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- 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]
19 changes: 9 additions & 10 deletions app/src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,29 @@
#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
60 changes: 37 additions & 23 deletions app/src/apdu_pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ 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 +62,14 @@ 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 +87,8 @@ 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 +103,8 @@ 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 +123,29 @@ 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 +154,19 @@ 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 +175,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 3680da2

Please sign in to comment.