Skip to content

Commit

Permalink
Merge pull request #32 from Concordium/add-linter
Browse files Browse the repository at this point in the history
Add linter
  • Loading branch information
orhoj authored Oct 20, 2021
2 parents ac932f3 + 6b0c3b9 commit 5c637d4
Show file tree
Hide file tree
Showing 73 changed files with 1,238 additions and 1,322 deletions.
18 changes: 18 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
BasedOnStyle: Google
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 120
PointerAlignment: Right
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: true
AllowAllParametersOfDeclarationOnNextLine: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
SortIncludes: false
16 changes: 16 additions & 0 deletions .github/workflows/build-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ jobs:
make clean
scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Lint
uses: DoozyX/[email protected]
with:
source: './src ./unit_tests'
extensions: 'c,h'
clangFormatVersion: 9
style: file
inplace: false

e2e-tests:
name: End to end tests
needs: [compile-nano-s, compile-nano-x]
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ load: all
delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

lint:
find . -regex './src/.*\.\(c\|h\)\|./unit_tests/.*\.\(c\|h\)' -exec clang-format -style=file -i {} \;

# Import rules to compile the glyphs supplied in the glyphs/ directory
include $(BOLOS_SDK)/Makefile.glyphs

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ make emulator
```
The file will be available at `bin/app.elf`.

## Linting
A make target is available for linting:
```bash
make lint
```

## Testing

### Running unit tests
Expand Down
7 changes: 2 additions & 5 deletions src/accountSenderView.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "ux.h"
#include "globals.h"
#include "ux.h"

UX_STEP_NOCB(
ux_sign_flow_account_sender_view,
bnnn_paging,
{
.title = "Sender",
.text = (char *) global_account_sender.sender
});
{.title = "Sender", .text = (char *) global_account_sender.sender});
2 changes: 2 additions & 0 deletions src/accountSenderView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _ACCOUNT_SENDER_VIEW_H_
#define _ACCOUNT_SENDER_VIEW_H_

#include "ux.h"

extern const ux_flow_step_t ux_sign_flow_account_sender_view;

#endif
60 changes: 29 additions & 31 deletions src/base58check.c
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
/*******************************************************************************
* Ledger App - Bitcoin Wallet
* (c) 2016-2019 Ledger
*
* - Only the 'base58_encode()' method (renamed from btchip_encode_base58).
* Reformatting of the method has been done, and removal of all PRINTF()
* invocations, and changed the algorithm to insert a space for every 10 characters.
*
* 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
*
* - Only the 'base58_encode()' method (renamed from btchip_encode_base58).
* Reformatting of the method has been done, and removal of all PRINTF()
* invocations, and changed the algorithm to insert a space for every 10 characters.
*
* 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 <stdlib.h>
#include <string.h>

#include "os.h"
#include "cx.h"
#include <string.h>

#define MAX_ENC_INPUT_SIZE 120

unsigned char const BASE58ALPHABET[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
unsigned char const BASE58ALPHABET[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int base58_encode(const unsigned char *in, size_t length, unsigned char *out, size_t *outlen) {
size_t i = 0, j;
Expand Down Expand Up @@ -60,7 +59,7 @@ int base58_encode(const unsigned char *in, size_t length, unsigned char *out, si
stopAt = outputSize - 1;
for (startAt = zeroCount; startAt < length; startAt++) {
int carry = in[startAt];
for (j = outputSize - 1; (int)j >= 0; j--) {
for (j = outputSize - 1; (int) j >= 0; j--) {
carry += 256 * out[j];
out[j] = carry % 58;
carry /= 58;
Expand Down Expand Up @@ -96,10 +95,9 @@ int base58_encode(const unsigned char *in, size_t length, unsigned char *out, si
out[i] = BASE58ALPHABET[out[i - distance - offset]];
}
}
}
else {
for (i = *outlen + spaces - 1; (int)i >= 0; --i) {
if ((*outlen + spaces - 1 - i) == nextSpace) {
} else {
for (i = *outlen + spaces - 1; (int) i >= 0; --i) {
if ((*outlen + spaces - 1 - i) == nextSpace) {
out[i] = ' ';
nextSpace += (pageSize + 1);
offset++;
Expand Down
17 changes: 7 additions & 10 deletions src/descriptionView.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "ux.h"
#include "globals.h"
#include "util.h"
#include "descriptionView.h"

#include "globals.h"
#include "responseCodes.h"
#include "util.h"
#include "ux.h"

static descriptionContext_t *ctx = &global.withDescription.descriptionContext;

Expand All @@ -12,13 +13,9 @@ UX_STEP_CB(
ux_sign_description_step,
bnnn_paging,
handleDescriptionPart(),
{
(char *) global.withDescription.descriptionContext.header,
(char *) global.withDescription.descriptionContext.text
});
UX_FLOW(ux_sign_description,
&ux_sign_description_step
);
{(char *) global.withDescription.descriptionContext.header,
(char *) global.withDescription.descriptionContext.text});
UX_FLOW(ux_sign_description, &ux_sign_description_step);

void handleDescriptionPart(void) {
if (ctx->textLength == 0) {
Expand Down
8 changes: 3 additions & 5 deletions src/descriptionView.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#ifndef _DESCRIPTION_VIEW_H_
#define _DESCRIPTION_VIEW_H_

#include "stdint.h"

void displayDescriptionPart(volatile unsigned int *flags);
void handleDescriptionPart(void);

typedef enum {
DESC_NAME,
DESC_URL,
DESC_DESCRIPTION
} descriptionState_t;
typedef enum { DESC_NAME, DESC_URL, DESC_DESCRIPTION } descriptionState_t;

typedef struct {
uint32_t textLength;
Expand Down
59 changes: 20 additions & 39 deletions src/exportPrivateKeySeed.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <os.h>
#include "ux.h"
#include "cx.h"
#include <stdint.h>
#include "util.h"
#include "globals.h"
#include <string.h>

#include "cx.h"
#include "globals.h"
#include "responseCodes.h"
#include "util.h"
#include "ux.h"

// Allow the user to decline exporting the private keys seeds.

Expand All @@ -21,35 +22,17 @@ void exportPrivateKey(void);
UX_STEP_NOCB(
ux_export_private_key_0_step,
nn,
{
(char *) global.exportPrivateKeySeedContext.displayHeader,
(char *) global.exportPrivateKeySeedContext.display
});
UX_STEP_CB(
ux_export_private_key_accept_step,
pb,
exportPrivateKey(),
{
&C_icon_validate_14,
"Accept"
});
UX_STEP_CB(
ux_export_private_key_decline_step,
pb,
sendUserRejection(),
{
&C_icon_crossmark,
"Decline"
});
UX_FLOW(ux_export_private_key,
{(char *) global.exportPrivateKeySeedContext.displayHeader, (char *) global.exportPrivateKeySeedContext.display});
UX_STEP_CB(ux_export_private_key_accept_step, pb, exportPrivateKey(), {&C_icon_validate_14, "Accept"});
UX_STEP_CB(ux_export_private_key_decline_step, pb, sendUserRejection(), {&C_icon_crossmark, "Decline"});
UX_FLOW(
ux_export_private_key,
&ux_export_private_key_0_step,
&ux_export_private_key_accept_step,
&ux_export_private_key_decline_step
);

&ux_export_private_key_decline_step);

#define ID_CRED_SEC 0
#define PRF_KEY 1
#define PRF_KEY 1

#define pathLength 6

Expand Down Expand Up @@ -85,24 +68,22 @@ void exportPrivateKey(void) {
#define NORMAL_ACCOUNTS 0

// Export the PRF key seed
#define P1_PRF_KEY 0x00
#define P1_PRF_KEY_RECOVERY 0x01
#define P1_PRF_KEY 0x00
#define P1_PRF_KEY_RECOVERY 0x01
// Export the PRF key seed and the IdCredSec seed
#define P1_BOTH 0x02
#define P1_BOTH 0x02

void handleExportPrivateKeySeed(uint8_t *dataBuffer, uint8_t p1, uint8_t p2, volatile unsigned int *flags) {
if ((p1 != P1_BOTH && p1 != P1_PRF_KEY && p1 != P1_PRF_KEY_RECOVERY) || p2 != 0x01) {
THROW(ERROR_INVALID_PARAM);
}

uint32_t identity = U4BE(dataBuffer, 0);
uint32_t keyDerivationPath[5] = {
CONCORDIUM_PURPOSE | HARDENED_OFFSET,
CONCORDIUM_COIN_TYPE | HARDENED_OFFSET,
ACCOUNT_SUBTREE | HARDENED_OFFSET,
NORMAL_ACCOUNTS | HARDENED_OFFSET,
identity | HARDENED_OFFSET
};
uint32_t keyDerivationPath[5] = {CONCORDIUM_PURPOSE | HARDENED_OFFSET,
CONCORDIUM_COIN_TYPE | HARDENED_OFFSET,
ACCOUNT_SUBTREE | HARDENED_OFFSET,
NORMAL_ACCOUNTS | HARDENED_OFFSET,
identity | HARDENED_OFFSET};
memmove(ctx->path, keyDerivationPath, sizeof(keyDerivationPath));

ctx->exportBoth = p1 == P1_BOTH;
Expand Down
5 changes: 3 additions & 2 deletions src/exportPrivateKeySeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
/**
* Handles the export of private keys (that are used as key seeds) that are allowed to leave the device.
* The export paths are restricted so that the method cannot access any account paths.
* @param p1 has to be 0x00 for export of PRF key for decryption, 0x01 for export of PRF key for recovering credentials and 0x02 for export of PRF key and IdCredSec.
* @param p1 has to be 0x00 for export of PRF key for decryption, 0x01 for export of PRF key for recovering credentials
* and 0x02 for export of PRF key and IdCredSec.
* @param p2 has to be 0x01. This was introduced to ensure that old clients fail when calling this functionality.
*/
*/
void handleExportPrivateKeySeed(uint8_t *dataBuffer, uint8_t p1, uint8_t p2, volatile unsigned int *flags);

typedef struct {
Expand Down
39 changes: 9 additions & 30 deletions src/getPublicKey.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "os.h"
#include "ux.h"
#include "util.h"
#include "globals.h"
#include "menu.h"
#include "os.h"
#include "responseCodes.h"
#include "globals.h"
#include "util.h"
#include "ux.h"

static keyDerivationPath_t *keyPath = &path;
static exportPublicKeyContext_t *ctx = &global.exportPublicKeyContext;
Expand All @@ -17,38 +17,18 @@ UX_STEP_VALID(
ux_generate_public_flow_0_step,
pnn,
sendPublicKey(true),
{
&C_icon_validate_14,
"Public key",
(char *) global.exportPublicKeyContext.display
});
UX_STEP_VALID(
ux_generate_public_flow_1_step,
pb,
sendUserRejection(),
{
&C_icon_crossmark,
"Decline"
});
UX_FLOW(ux_generate_public_flow,
&ux_generate_public_flow_0_step,
&ux_generate_public_flow_1_step,
FLOW_LOOP
);
{&C_icon_validate_14, "Public key", (char *) global.exportPublicKeyContext.display});
UX_STEP_VALID(ux_generate_public_flow_1_step, pb, sendUserRejection(), {&C_icon_crossmark, "Decline"});
UX_FLOW(ux_generate_public_flow, &ux_generate_public_flow_0_step, &ux_generate_public_flow_1_step, FLOW_LOOP);

// UI definitions for comparison of public-key on the device
// with the public-key that the caller received.
UX_STEP_VALID(
ux_sign_compare_public_key_0_step,
bnnn_paging,
ui_idle(),
{
.title = "Compare",
.text = (char *) global.exportPublicKeyContext.publicKey
});
UX_FLOW(ux_sign_compare_public_key,
&ux_sign_compare_public_key_0_step
);
{.title = "Compare", .text = (char *) global.exportPublicKeyContext.publicKey});
UX_FLOW(ux_sign_compare_public_key, &ux_sign_compare_public_key_0_step);

// Builds a display version of the identity/account path. A pre-condition
// for running this method is that 'parseKeyDerivation' has been
Expand Down Expand Up @@ -87,7 +67,6 @@ void sendPublicKey(bool compare) {
tx += sizeof(signedPublicKey);
}


// Send back success response including the public-key (and signature, if wanted).
if (compare) {
// Show the public-key so that the user can verify the public-key.
Expand Down
Loading

0 comments on commit 5c637d4

Please sign in to comment.