diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml new file mode 100644 index 0000000..75d0b1a --- /dev/null +++ b/.github/workflows/check_version.yml @@ -0,0 +1,58 @@ +name: "Verify PRs to main" + +on: + pull_request: + branches: + - main + +jobs: + configure: + runs-on: ubuntu-latest + outputs: + uid_gid: ${{ steps.get-user.outputs.uid_gid }} + steps: + - id: get-user + run: echo "::set-output name=uid_gid::$(id -u):$(id -g)" + + get_version: + needs: configure + runs-on: ubuntu-latest + container: + image: zondax/builder-bolos:latest + options: --user ${{ needs.configure.outputs.uid_gid }} + env: + BOLOS_ENV: /opt/bolos + HOME: /home/zondax_circle + outputs: + version: ${{ steps.store-version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + + - name: Invoke `version` + shell: bash -l {0} + env: + BOLOS_SDK: ${{ github.workspace }}/deps/nanos-secure-sdk + run: make version + + - id: store-version + run: echo ::set-output name=version::$(cat ./app/app.version) + + check_app_version: + needs: get_version + runs-on: ubuntu-latest + steps: + - id: checkTag + uses: mukunku/tag-exists-action@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ needs.get_version.outputs.version }} + + - run: echo ${{ steps.checkTag.outputs.exists }} + + - name: Tag exists + if: ${{ steps.checkTag.outputs.exists == 'true' }} + run: exit 1 \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f370f9c..c987097 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -145,7 +145,7 @@ jobs: export PATH=~/.cargo/bin:$PATH cd tests_zemu && yarn testSR25519 - build_package: + build_package_0: needs: [ configure, build, build_ledger, test_zemu, test_zemu_sr25519 ] if: ${{ github.ref == 'refs/heads/main' }} runs-on: ubuntu-latest @@ -163,41 +163,101 @@ jobs: submodules: true - name: Install deps run: pip install ledgerblue - - name: Build + + - name: Build NanoS light shell: bash -l {0} run: | source $HOME/.cargo/env make SUBSTRATE_PARSER_FULL=0 - - name: Set tag name var (1) - id: vars_1 - run: echo ::set-output name=tag_name::$(./app/pkg/installer_s.sh version) + mv ./app/pkg/installer_s.sh ./app/pkg/installer_nanos_light.sh + - name: Set tag + id: nanos_light + run: echo ::set-output name=tag_name::$(./app/pkg/installer_nanos_light.sh version) - name: Create or Update Release (1) - id: create_release_1 + id: create_release_0 + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + files: ./app/pkg/installer_nanos_light.sh + tag_name: ${{ steps.nanos_light.outputs.tag_name }} + draft: false + prerelease: false + + build_package_1: + needs: [ configure, build, build_ledger, test_zemu, test_zemu_sr25519 ] + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + container: + image: zondax/builder-bolos:latest + options: --user ${{ needs.configure.outputs.uid_gid }} + env: + BOLOS_SDK: ${{ github.workspace }}/deps/nanos-secure-sdk + BOLOS_ENV: /opt/bolos + HOME: /home/zondax_circle + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install deps + run: pip install ledgerblue + + - name: Build NanoS XL + shell: bash -l {0} + run: | + source $HOME/.cargo/env + make SUBSTRATE_PARSER_FULL=1 + mv ./app/pkg/installer_s.sh ./app/pkg/installer_nanos_xl.sh + - name: Set tag + id: nanos_xl + run: echo ::set-output name=tag_name::$(./app/pkg/installer_nanos_xl.sh version) + - name: Update Release + id: update_release_1 uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: - files: ./app/pkg/installer_s.sh - tag_name: ${{ steps.vars_1.outputs.tag_name }} + files: ./app/pkg/installer_nanos_xl.sh + tag_name: ${{ steps.nanos_xl.outputs.tag_name }} draft: false prerelease: false - - name: Clear and rebuild XL version + + build_package_2: + needs: [ configure, build, build_ledger, test_zemu, test_zemu_sr25519 ] + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + container: + image: zondax/builder-bolos:latest + options: --user ${{ needs.configure.outputs.uid_gid }} + env: + BOLOS_SDK: ${{ github.workspace }}/deps/nanosplus-secure-sdk + BOLOS_ENV: /opt/bolos + HOME: /home/zondax_circle + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install deps + run: pip install ledgerblue + + - name: Build NanoSP XL shell: bash -l {0} run: | source $HOME/.cargo/env make SUBSTRATE_PARSER_FULL=1 - cp rust/app/pkg/installer_s.sh rust/app/pkg/installer_baking_s.sh - cp app/pkg/installer_s.sh app/pkg/installer_XL_s.sh - - name: Set tag name var (2) - id: vars_2 - run: echo ::set-output name=tag_name::$(./app/pkg/installer_XL_s.sh version) - - name: Create or Update Release (2) - id: create_release_2 + mv ./app/pkg/installer_s2.sh ./app/pkg/installer_nanosp_xl.sh + - name: Set tag + id: nanosp_xl + run: echo ::set-output name=tag_name::$(./app/pkg/installer_nanosp_xl.sh version) + - name: Update Release + id: update_release_2 uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: - files: ./app/pkg/installer_XL_s.sh - tag_name: ${{ steps.vars_2.outputs.tag_name }} + files: ./app/pkg/installer_nanosp_xl.sh + tag_name: ${{ steps.nanosp_xl.outputs.tag_name }} draft: false prerelease: false diff --git a/.gitmodules b/.gitmodules index a5e87aa..b88a7f6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "deps/nanox-secure-sdk"] path = deps/nanox-secure-sdk url = https://github.com/LedgerHQ/nanox-secure-sdk.git +[submodule "deps/nanosplus-secure-sdk"] + path = deps/nanosplus-secure-sdk + url = https://github.com/LedgerHQ/nanosplus-secure-sdk diff --git a/app/.gitignore b/app/.gitignore index 760c384..66d5371 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -49,4 +49,4 @@ bin/app.apdu \output/app.* pkg/zxtool.sh -pkg/installer_?.sh +pkg/installer_*.sh diff --git a/app/Makefile b/app/Makefile index 9c65060..a4bf23d 100755 --- a/app/Makefile +++ b/app/Makefile @@ -1,6 +1,6 @@ #******************************************************************************* # Ledger App -# (c) 2018-2021 Zondax GmbH +# (c) 2018 - 2022 Zondax GmbH # (c) 2017 Ledger # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -95,9 +95,10 @@ endef $(error "$(error_message)") endif -APP_LOAD_PARAMS = --appFlags 0x200 --delete $(COMMON_LOAD_PARAMS) --path $(APPPATH) +APP_LOAD_PARAMS = --curve ed25519 --delete $(COMMON_LOAD_PARAMS) --path $(APPPATH) ifeq ($(TARGET_NAME),TARGET_NANOS) +APP_LOAD_PARAMS += --appFlags 0x000 APP_STACK_SIZE:=3216 ICONNAME:=$(CURDIR)/nanos_icon.gif OUTPUT_ELF ?= $(CURDIR)/output/app_s.elf @@ -105,12 +106,21 @@ OUTPUT_INSTALLER := $(CURDIR)/pkg/installer_s.sh endif ifeq ($(TARGET_NAME),TARGET_NANOX) +APP_LOAD_PARAMS += --appFlags 0x200 SCRIPT_LD:=$(CURDIR)/script_x.ld ICONNAME:=$(CURDIR)/nanox_icon.gif OUTPUT_ELF ?= $(CURDIR)/output/app_x.elf OUTPUT_INSTALLER:= $(CURDIR)/pkg/installer_x.sh endif +ifeq ($(TARGET_NAME),TARGET_NANOS2) +APP_LOAD_PARAMS += --appFlags 0x200 +SCRIPT_LD:=$(CURDIR)/script_s2.ld +ICONNAME:=$(CURDIR)/nanox_icon.gif +OUTPUT_ELF ?= $(CURDIR)/output/app_s2.elf +OUTPUT_INSTALLER:= $(CURDIR)/pkg/installer_s2.sh +endif + $(info TARGET_NAME = [$(TARGET_NAME)]) $(info ICONNAME = [$(ICONNAME)]) @@ -137,7 +147,10 @@ DEFINES += HAVE_BOLOS_APP_STACK_CANARY DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL="" -ifeq ($(TARGET_NAME),TARGET_NANOX) +ifeq ($(TARGET_NAME),TARGET_NANOS) +DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128 +else +# Assume Nano X/S+ DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300 DEFINES += HAVE_GLO096 @@ -148,20 +161,16 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX DEFINES += HAVE_UX_FLOW +endif +ifeq ($(TARGET_NAME),TARGET_NANOX) +# X specific DEFINES += HAVE_BLE DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000 SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl -else -# Assume Nano S -DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=32 -DEFINES += BAGL_WIDTH_MARGIN=10 -DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128 endif -# X specific - # App specific #Feature temporarily disabled @@ -230,11 +239,11 @@ clean: rust_clean # load, delete and listvariants are provided to comply with Ledger requirements .PHONY: load load: - python -m ledgerblue.loadApp $(APP_LOAD_PARAMS) + python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) .PHONY: delete delete: - python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS) + python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS) # Import generic rules from the SDK include $(BOLOS_SDK)/Makefile.rules @@ -246,6 +255,10 @@ dep/%.d: %.c Makefile listvariants: ifeq ($(TARGET_NAME),TARGET_NANOS) @echo VARIANTS COIN NODL NODL_XL -else ifeq ($(TARGET_NAME),TARGET_NANOX) +else @echo VARIANTS COIN NODL endif + +.PHONY: version +version: + @echo "v$(APPVERSION)" > app.version diff --git a/app/Makefile.version b/app/Makefile.version index 52a5d81..5843b67 100644 --- a/app/Makefile.version +++ b/app/Makefile.version @@ -3,4 +3,4 @@ APPVERSION_M=3 # This is the `spec_version` field of `Runtime` APPVERSION_N=55 # This is the patch version of this release -APPVERSION_P=1 +APPVERSION_P=2 diff --git a/app/script_s2.ld b/app/script_s2.ld new file mode 100644 index 0000000..db3150b --- /dev/null +++ b/app/script_s2.ld @@ -0,0 +1,170 @@ +/******************************************************************************* +* Ledger Blue - Secure firmware +* (c) 2016, 2017, 2018, 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. +********************************************************************************/ + +/** + * Global chip memory layout and constants + * + */ + +MEMORY +{ + DISCARD (rwx) : ORIGIN = 0xd0000000, LENGTH = 1M + + FLASH (rx) : ORIGIN = 0xc0de0000, LENGTH = 400K + DATA (r) : ORIGIN = 0xc0de0000, LENGTH = 400K + SRAM (rwx) : ORIGIN = 0xda7a0000, LENGTH = 30K +} + +PAGE_SIZE = 512; +STACK_SIZE = 8192; +END_STACK = ORIGIN(SRAM) + LENGTH(SRAM); + +ENTRY(main); + +SECTIONS +{ + /****************************************************************/ + /* This section locates the code in FLASH */ + /****************************************************************/ + + /** put text in Flash memory, VMA will be equal to LMA */ + .text : + { + /* provide start code symbol, shall be zero */ + _text = .; + _nvram_start = .; + + /* ensure main is always @ 0xC0D00000 */ + *(.boot*) + + /* place the other code and rodata defined BUT nvram variables that are displaced in a r/w area */ + *(.text*) + *(.rodata) + *(.rodata.[^N]*) /*.data.rel.ro* not here to detect invalid PIC usage */ + *(.rodata.N[^_]*) + + . = ALIGN(4); + + /* all code placed */ + _etext = .; + + . = ALIGN(PAGE_SIZE); + + _nvram_data = .; + + /* NVM data (ex-filesystem) */ + *(.bss.N_* .rodata.N_*) + + . = ALIGN(PAGE_SIZE); + _envram_data = .; + + _install_parameters = .; + _nvram_end = .; + } > FLASH = 0x00 + + .data (NOLOAD): + { + . = ALIGN(4); + + /** + * Place RAM initialized variables + */ + _data = .; + + *(vtable) + *(.data*) + + _edata = .; + + } > DISCARD /*> SRAM AT>FLASH = 0x00 */ + + .bss : + { + /** + * Place RAM uninitialized variables + */ + _bss = .; + *(.bss*) + _ebss = .; + + + /** + * Reserve stack size + */ + . = ALIGN(4); + app_stack_canary = .; + PROVIDE(app_stack_canary = .); + . += 4; + _stack_validation = .; + . = _stack_validation + STACK_SIZE; + _stack = ABSOLUTE(END_STACK) - STACK_SIZE; + PROVIDE( _stack = ABSOLUTE(END_STACK) - STACK_SIZE); + _estack = ABSOLUTE(END_STACK); + PROVIDE( _estack = ABSOLUTE(END_STACK) ); + + } > SRAM = 0x00 + + /****************************************************************/ + /* DEBUG */ + /****************************************************************/ + + /* remove the debugging information from the standard libraries */ + DEBUG (NOLOAD) : + { + libc.a ( * ) + libm.a ( * ) + libgcc.a ( * ) + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > DISCARD + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } +} + +PROVIDE(_nvram = ABSOLUTE(_nvram_start)); +PROVIDE(_envram = ABSOLUTE(_nvram_end)); \ No newline at end of file diff --git a/app/src/common/tx.c b/app/src/common/tx.c index b346eb3..7a979b9 100644 --- a/app/src/common/tx.c +++ b/app/src/common/tx.c @@ -21,7 +21,7 @@ #include #include "zxmacros.h" -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) #define RAM_BUFFER_SIZE 8192 #define FLASH_BUFFER_SIZE 16384 #elif defined(TARGET_NANOS) @@ -37,7 +37,7 @@ typedef struct { uint8_t buffer[FLASH_BUFFER_SIZE]; } storage_t; -#if defined(TARGET_NANOS) || defined(TARGET_NANOX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) storage_t NV_CONST N_appdata_impl __attribute__ ((aligned(64))); #define N_appdata (*(NV_VOLATILE storage_t *)PIC(&N_appdata_impl)) #endif diff --git a/app/src/crypto_helper.c b/app/src/crypto_helper.c index 27be157..0833a0b 100644 --- a/app/src/crypto_helper.c +++ b/app/src/crypto_helper.c @@ -17,7 +17,7 @@ #include "crypto_helper.h" #include "base58.h" -#if defined(TARGET_NANOS) || defined(TARGET_NANOX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) #include "cx.h" int ss58hash(const unsigned char *in, unsigned int inLen, diff --git a/app/src/parser.c b/app/src/parser.c index b4ab325..2a3a44a 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -23,7 +23,7 @@ #include "coin_ss58.h" #include "substrate_dispatch.h" -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) // For some reason NanoX requires this function void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function){ while(1) {}; diff --git a/app/src/parser_txdef.h b/app/src/parser_txdef.h index 1b6d4fa..051e630 100644 --- a/app/src/parser_txdef.h +++ b/app/src/parser_txdef.h @@ -23,7 +23,7 @@ extern "C" { #include #include "substrate_methods.h" -#ifdef TARGET_NANOX +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) #define MAX_CALL_NESTING_SIZE 6 #define MAX_CALL_VEC_SIZE 6 #else diff --git a/cmake/cmake-modules b/cmake/cmake-modules index d98828f..03be0c7 160000 --- a/cmake/cmake-modules +++ b/cmake/cmake-modules @@ -1 +1 @@ -Subproject commit d98828f54f6974717798e63195cfbf08fe2daad0 +Subproject commit 03be0c7e1ad14d4e9767c72e26a4515024aec5ae diff --git a/deps/ledger-zxlib/.circleci/config.yml b/deps/ledger-zxlib/.circleci/config.yml deleted file mode 100644 index 0c981f7..0000000 --- a/deps/ledger-zxlib/.circleci/config.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: ubuntu:18.04 - steps: - - run: - name: Install dependencies - command: apt update && apt-get -y install build-essential git sudo wget cmake libssl-dev libgmp-dev autoconf libtool - - checkout - - run: git submodule update --init --recursive - - run: cmake . && make - - run: export GTEST_COLOR=1 && ctest -VV - -workflows: - version: 2 - build_all: - jobs: - - build diff --git a/deps/ledger-zxlib/.github/workflows/main.yml b/deps/ledger-zxlib/.github/workflows/main.yml new file mode 100644 index 0000000..485c5c5 --- /dev/null +++ b/deps/ledger-zxlib/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: "Test/Build" +on: + workflow_dispatch: + push: + pull_request: + branches: [ main ] + +jobs: + configure: + runs-on: ubuntu-latest + outputs: + uid_gid: ${{ steps.get-user.outputs.uid_gid }} + steps: + - id: get-user + run: echo "::set-output name=uid_gid::$(id -u):$(id -g)" + + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install deps + run: | + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + brew install conan + conan config install https://github.com/conan-io/conanclientcert.git + - run: cmake -DCMAKE_BUILD_TYPE=Debug . && make diff --git a/deps/ledger-zxlib/README.md b/deps/ledger-zxlib/README.md index 9dabbf5..d75ac57 100644 --- a/deps/ledger-zxlib/README.md +++ b/deps/ledger-zxlib/README.md @@ -1,5 +1,5 @@ # ledger-zxlib [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -[![CircleCI](https://circleci.com/gh/Zondax/ledger-zxlib/tree/master.svg?style=shield)](https://circleci.com/gh/Zondax/ledger-zxlib/tree/master) +[![GithubActions](https://github.com/zondax/ledger-zxlib/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-zxlib/blob/main/.github/workflows/main.yaml) [![CodeFactor](https://www.codefactor.io/repository/github/zondax/ledger-zxlib/badge)](https://www.codefactor.io/repository/github/zondax/ledger-zxlib) diff --git a/deps/ledger-zxlib/app/common/view.c b/deps/ledger-zxlib/app/common/view.c index 36e7684..0a5fc19 100644 --- a/deps/ledger-zxlib/app/common/view.c +++ b/deps/ledger-zxlib/app/common/view.c @@ -61,6 +61,11 @@ void h_error_accept(__Z_UNUSED unsigned int _) { app_reply_error(); } +void h_initialize(__Z_UNUSED unsigned int _) { + view_idle_show(0, NULL); + UX_WAIT(); +} + /////////////////////////////////// // Paging related @@ -195,6 +200,11 @@ zxerr_t h_review_update_data() { return zxerr_no_data; } + if (viewdata.viewfuncGetItem == NULL) { + zemu_log_stack("h_review_update_data - GetItem==NULL"); + return zxerr_no_data; + } + char buffer[20]; snprintf(buffer, sizeof(buffer), "update Idx %d/%d", viewdata.itemIdx, viewdata.pageIdx); zemu_log_stack(buffer); diff --git a/deps/ledger-zxlib/app/common/view.h b/deps/ledger-zxlib/app/common/view.h index 21a3e42..6c9e777 100644 --- a/deps/ledger-zxlib/app/common/view.h +++ b/deps/ledger-zxlib/app/common/view.h @@ -44,6 +44,9 @@ zxerr_t secret_enabled(); /// view_init (initializes UI) void view_init(); +/// view_initialize_show (idle view - main menu + status) +void view_initialize_show(uint8_t item_idx, char *statusString); + /// view_idle_show (idle view - main menu + status) void view_idle_show(uint8_t item_idx, char *statusString); diff --git a/deps/ledger-zxlib/app/common/view_internal.h b/deps/ledger-zxlib/app/common/view_internal.h index 3720ba3..4f08a73 100644 --- a/deps/ledger-zxlib/app/common/view_internal.h +++ b/deps/ledger-zxlib/app/common/view_internal.h @@ -24,13 +24,15 @@ #define CUR_FLOW G_ux.flow_stack[G_ux.stack_count-1] -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) #define MAX_CHARS_PER_KEY_LINE 64 #define MAX_CHARS_PER_VALUE1_LINE 4096 #define MAX_CHARS_HEXMESSAGE 160 #else -#define MAX_CHARS_PER_KEY_LINE (17+1) +#ifndef MAX_CHARS_PER_VALUE_LINE #define MAX_CHARS_PER_VALUE_LINE (17) +#endif +#define MAX_CHARS_PER_KEY_LINE (MAX_CHARS_PER_VALUE_LINE+1) #define MAX_CHARS_PER_VALUE1_LINE (2*MAX_CHARS_PER_VALUE_LINE+1) #define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE+1) #define MAX_CHARS_HEXMESSAGE 40 @@ -100,6 +102,8 @@ max_char_display get_max_char_per_line(); /////////////////////////////////////////////// /////////////////////////////////////////////// +void view_initialize_show_impl(uint8_t item_idx, char *statusString); + void view_idle_show_impl(uint8_t item_idx, char *statusString); void view_message_impl(char *title, char *message); diff --git a/deps/ledger-zxlib/app/common/view_s.c b/deps/ledger-zxlib/app/common/view_s.c index 1dd7d56..d323b5c 100644 --- a/deps/ledger-zxlib/app/common/view_s.c +++ b/deps/ledger-zxlib/app/common/view_s.c @@ -30,6 +30,8 @@ #if defined(TARGET_NANOS) +void h_initialize(); + #define BAGL_WIDTH 128 #define BAGL_HEIGHT 32 #define BAGL_WIDTH_MARGIN 10 @@ -71,6 +73,17 @@ const ux_menu_entry_t menu_main[] = { UX_MENU_END }; +const ux_menu_entry_t menu_initialize[] = { + {NULL, NULL, 0, &C_icon_app, MENU_MAIN_APP_LINE1, viewdata.key, 33, 12}, + {NULL, h_initialize, 0, &C_icon_app, "Click to", "Initialize", 33, 12}, + {NULL, h_expert_toggle, 0, &C_icon_app, "Expert mode:", viewdata.value, 33, 12}, + {NULL, NULL, 0, &C_icon_app, APPVERSION_LINE1, APPVERSION_LINE2, 33, 12}, + {NULL, NULL, 0, &C_icon_app, "Developed by:", "Zondax.ch", 33, 12}, + {NULL, NULL, 0, &C_icon_app, "License: ", "Apache 2.0", 33, 12}, + {NULL, os_exit, 0, &C_icon_dashboard, "Quit", NULL, 50, 29}, + UX_MENU_END +}; + static const bagl_element_t view_message[] = { UI_BACKGROUND, UI_LabelLine(UIID_LABEL + 0, 0, 8, UI_SCREEN_WIDTH, UI_11PX, UI_WHITE, UI_BLACK, viewdata.key), @@ -238,6 +251,16 @@ bool exceed_pixel_in_display(const uint8_t length) { ////////////////////////// ////////////////////////// +void view_initialize_show_impl(uint8_t item_idx, char *statusString) { + if (statusString == NULL ) { + snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", MENU_MAIN_APP_LINE2); + } else { + snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", statusString); + } + h_expert_update(); + UX_MENU_DISPLAY(item_idx, menu_initialize, NULL); +} + void view_idle_show_impl(uint8_t item_idx, char *statusString) { if (statusString == NULL ) { snprintf(viewdata.key, MAX_CHARS_PER_VALUE_LINE, "%s", MENU_MAIN_APP_LINE2); diff --git a/deps/ledger-zxlib/app/common/view_x.c b/deps/ledger-zxlib/app/common/view_x.c index 7db6f93..f8dd8bc 100644 --- a/deps/ledger-zxlib/app/common/view_x.c +++ b/deps/ledger-zxlib/app/common/view_x.c @@ -33,7 +33,7 @@ #include #include -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) void h_expert_toggle(); void h_expert_update(); @@ -76,6 +76,15 @@ const ux_flow_step_t *const ux_idle_flow [] = { /////////// +UX_STEP_NOCB(ux_message_flow_1_step, pbb, { &C_icon_app, viewdata.key, viewdata.value,}); + +UX_FLOW( + ux_message_flow, + &ux_message_flow_1_step +); + +/////////// + UX_STEP_NOCB(ux_error_flow_1_step, bnnn_paging, { .title = viewdata.key, .text = viewdata.value, }); UX_STEP_VALID(ux_error_flow_2_step, pb, h_error_accept(0), { &C_icon_validate_14, "Ok"}); @@ -235,7 +244,7 @@ void h_secret_click() { ////////////////////////// ////////////////////////// -void view_idle_show_impl(uint8_t item_idx, char *statusString) { +void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, char *statusString) { if (statusString == NULL ) { if (app_mode_secret()) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", MENU_MAIN_APP_LINE2_SECRET); @@ -263,6 +272,16 @@ void view_review_show_impl(){ ux_flow_init(0, ux_review_flow, NULL); } +void view_message_impl(char *title, char *message) { + snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", title); + snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", message); + ux_layout_bnnn_paging_reset(); + if(G_ux.stack_count == 0) { + ux_stack_push(); + } + ux_flow_init(0, ux_message_flow, NULL); +} + void view_error_show_impl() { ux_layout_bnnn_paging_reset(); if(G_ux.stack_count == 0) { diff --git a/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt b/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt index 4f7a8ee..c64d5d8 100644 --- a/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt +++ b/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt @@ -26,6 +26,6 @@ add_subdirectory( ${CMAKE_BINARY_DIR}/googletest-build ) -if (CMAKE_VERSION VERSION_LESS 2.8.11) +if (CMAKE_VERSION VERSION_LESS 3.0.0) include_directories("${gtest_SOURCE_DIR}/include") endif () diff --git a/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt.gtest.in b/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt.gtest.in index 31b2fbd..b30f8be 100644 --- a/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt.gtest.in +++ b/deps/ledger-zxlib/cmake/gtest/CMakeLists.txt.gtest.in @@ -1,5 +1,5 @@ # Based on https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project -cmake_minimum_required(VERSION 2.8.2) +cmake_minimum_required(VERSION 3.0.0) project(googletest-download NONE) diff --git a/deps/ledger-zxlib/dockerized_build.mk b/deps/ledger-zxlib/dockerized_build.mk index 50f2e4d..50d9c37 100644 --- a/deps/ledger-zxlib/dockerized_build.mk +++ b/deps/ledger-zxlib/dockerized_build.mk @@ -27,6 +27,7 @@ DOCKER_APP_BIN=$(DOCKER_APP_SRC)/app/bin/app.elf DOCKER_BOLOS_SDKS=/project/deps/nanos-secure-sdk DOCKER_BOLOS_SDKX=/project/deps/nanox-secure-sdk +DOCKER_BOLOS_SDKS2=/project/deps/nanosplus-secure-sdk # Note: This is not an SSH key, and being public represents no risk SCP_PUBKEY=049bc79d139c70c83a4b19e8922e5ee3e0080bb14a2e8b0752aa42cda90a1463f689b0fa68c1c0246845c2074787b649d0d8a6c0b97d4607065eee3057bdf16b83 @@ -85,6 +86,8 @@ all: @$(MAKE) buildS @$(MAKE) clean_build @$(MAKE) buildX + @$(MAKE) clean_build + @$(MAKE) buildS2 .PHONY: check_python check_python: @@ -112,6 +115,10 @@ build_rustS: build_rustX: $(call run_docker,$(DOCKER_BOLOS_SDKX),make -C $(DOCKER_APP_SRC) rust) +.PHONY: build_rustS2 +build_rustS2: + $(call run_docker,$(DOCKER_BOLOS_SDKS2),make -C $(DOCKER_APP_SRC) rust) + .PHONY: convert_icon convert_icon: @convert $(LEDGER_SRC)/tmp.gif -monochrome -size 16x16 -depth 1 $(LEDGER_SRC)/nanos_icon.gif @@ -125,6 +132,10 @@ buildS: build_rustS buildX: build_rustX $(call run_docker,$(DOCKER_BOLOS_SDKX),make -j $(NPROC) -C $(DOCKER_APP_SRC)) +.PHONY: buildS2 +buildS2: build_rustS2 + $(call run_docker,$(DOCKER_BOLOS_SDKS2),make -j $(NPROC) -C $(DOCKER_APP_SRC)) + .PHONY: clean_output clean_output: @echo "Removing output files" @@ -149,6 +160,10 @@ shellS: shellX: $(call run_docker,$(DOCKER_BOLOS_SDKX) -t,bash) +.PHONY: shellS2 +shellS2: + $(call run_docker,$(DOCKER_BOLOS_SDKS2) -t,bash) + .PHONY: load load: ${LEDGER_SRC}/pkg/installer_s.sh load @@ -165,6 +180,14 @@ loadX: deleteX: ${LEDGER_SRC}/pkg/installer_x.sh delete +.PHONY: loadS2 +loadS2: + ${LEDGER_SRC}/pkg/installer_s2.sh load + +.PHONY: deleteS2 +deleteS2: + ${LEDGER_SRC}/pkg/installer_s2.sh delete + .PHONY: show_info_recovery_mode show_info_recovery_mode: @echo "This command requires a Ledger Nano S in recovery mode. To go into recovery mode, follow:" diff --git a/deps/ledger-zxlib/include/segwit_addr.h b/deps/ledger-zxlib/include/segwit_addr.h index d03bb11..f97bcfa 100644 --- a/deps/ledger-zxlib/include/segwit_addr.h +++ b/deps/ledger-zxlib/include/segwit_addr.h @@ -89,7 +89,7 @@ int bech32_encode( * data_len: Pointer to a size_t that will be updated to be the number * of entries in data. * In: input: Pointer to a null-terminated Bech32 string. - * Returns 1 if succesful. + * Returns 1 if successful. */ int bech32_decode( char *hrp, diff --git a/deps/ledger-zxlib/include/utf8.h b/deps/ledger-zxlib/include/utf8.h index 2ca0941..fe2e8d9 100644 --- a/deps/ledger-zxlib/include/utf8.h +++ b/deps/ledger-zxlib/include/utf8.h @@ -1,30 +1,30 @@ -// The latest version of this library is available on GitHub; -// https://github.com/sheredom/utf8.h - -// This is free and unencumbered software released into the public domain. -// -// Anyone is free to copy, modify, publish, use, compile, sell, or -// distribute this software, either in source code form or as a compiled -// binary, for any purpose, commercial or non-commercial, and by any -// means. -// -// In jurisdictions that recognize copyright laws, the author or authors -// of this software dedicate any and all copyright interest in the -// software to the public domain. We make this dedication for the benefit -// of the public at large and to the detriment of our heirs and -// successors. We intend this dedication to be an overt act of -// relinquishment in perpetuity of all present and future rights to this -// software under copyright law. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// For more information, please refer to +/* The latest version of this library is available on GitHub; + * https://github.com/sheredom/utf8.h */ + +/* This is free and unencumbered software released into the public domain. + * + * Anyone is free to copy, modify, publish, use, compile, sell, or + * distribute this software, either in source code form or as a compiled + * binary, for any purpose, commercial or non-commercial, and by any + * means. + * + * In jurisdictions that recognize copyright laws, the author or authors + * of this software dedicate any and all copyright interest in the + * software to the public domain. We make this dedication for the benefit + * of the public at large and to the detriment of our heirs and + * successors. We intend this dedication to be an overt act of + * relinquishment in perpetuity of all present and future rights to this + * software under copyright law. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * For more information, please refer to */ #ifndef SHEREDOM_UTF8_H_INCLUDED #define SHEREDOM_UTF8_H_INCLUDED @@ -91,201 +91,201 @@ extern "C" { #define utf8_constexpr14 constexpr #define utf8_constexpr14_impl constexpr #else -// constexpr and weak are incompatible. so only enable one of them +/* constexpr and weak are incompatible. so only enable one of them */ #define utf8_constexpr14 utf8_weak #define utf8_constexpr14_impl #endif #if defined(__cplusplus) && __cplusplus >= 202002L -using utf8_int8_t = char8_t; // Introduced in C++20 +using utf8_int8_t = char8_t; /* Introduced in C++20 */ #else typedef char utf8_int8_t; #endif -// Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > -// src2 respectively, case insensitive. +/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > + * src2 respectively, case insensitive. */ utf8_constexpr14 utf8_nonnull utf8_pure int utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2); -// Append the utf8 string src onto the utf8 string dst. +/* Append the utf8 string src onto the utf8 string dst. */ utf8_nonnull utf8_weak utf8_int8_t * utf8cat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); -// Find the first match of the utf8 codepoint chr in the utf8 string src. +/* Find the first match of the utf8 codepoint chr in the utf8 string src. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8chr(const utf8_int8_t *src, utf8_int32_t chr); -// Return less than 0, 0, greater than 0 if src1 < src2, -// src1 == src2, src1 > src2 respectively. +/* Return less than 0, 0, greater than 0 if src1 < src2, + * src1 == src2, src1 > src2 respectively. */ utf8_constexpr14 utf8_nonnull utf8_pure int utf8cmp(const utf8_int8_t *src1, const utf8_int8_t *src2); -// Copy the utf8 string src onto the memory allocated in dst. +/* Copy the utf8 string src onto the memory allocated in dst. */ utf8_nonnull utf8_weak utf8_int8_t * -utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); + utf8cpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src); -// Number of utf8 codepoints in the utf8 string src that consists entirely -// of utf8 codepoints not from the utf8 string reject. +/* Number of utf8 codepoints in the utf8 string src that consists entirely + * of utf8 codepoints not from the utf8 string reject. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject); -// Duplicate the utf8 string src by getting its size, malloc'ing a new buffer -// copying over the data, and returning that. Or 0 if malloc failed. +/* Duplicate the utf8 string src by getting its size, malloc'ing a new buffer + * copying over the data, and returning that. Or 0 if malloc failed. */ utf8_weak utf8_int8_t *utf8dup(const utf8_int8_t *src); -// Number of utf8 codepoints in the utf8 string str, -// excluding the null terminating byte. +/* Number of utf8 codepoints in the utf8 string str, + * excluding the null terminating byte. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8len(const utf8_int8_t *str); -// Similar to utf8len, except that only at most n bytes of src are looked. +/* Similar to utf8len, except that only at most n bytes of src are looked. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nlen(const utf8_int8_t *str, size_t n); -// Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > -// src2 respectively, case insensitive. Checking at most n bytes of each utf8 -// string. +/* Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > + * src2 respectively, case insensitive. Checking at most n bytes of each utf8 + * string. */ utf8_constexpr14 utf8_nonnull utf8_pure int utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); -// Append the utf8 string src onto the utf8 string dst, -// writing at most n+1 bytes. Can produce an invalid utf8 -// string if n falls partway through a utf8 codepoint. +/* Append the utf8 string src onto the utf8 string dst, + * writing at most n+1 bytes. Can produce an invalid utf8 + * string if n falls partway through a utf8 codepoint. */ utf8_nonnull utf8_weak utf8_int8_t * -utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, - size_t n); + utf8ncat(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, +size_t n); -// Return less than 0, 0, greater than 0 if src1 < src2, -// src1 == src2, src1 > src2 respectively. Checking at most n -// bytes of each utf8 string. +/* Return less than 0, 0, greater than 0 if src1 < src2, + * src1 == src2, src1 > src2 respectively. Checking at most n + * bytes of each utf8 string. */ utf8_constexpr14 utf8_nonnull utf8_pure int utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n); -// Copy the utf8 string src onto the memory allocated in dst. -// Copies at most n bytes. If n falls partway through a utf8 -// codepoint, or if dst doesn't have enough room for a null -// terminator, the final string will be cut short to preserve -// utf8 validity. +/* Copy the utf8 string src onto the memory allocated in dst. + * Copies at most n bytes. If n falls partway through a utf8 + * codepoint, or if dst doesn't have enough room for a null + * terminator, the final string will be cut short to preserve + * utf8 validity. */ utf8_nonnull utf8_weak utf8_int8_t * -utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, - size_t n); + utf8ncpy(utf8_int8_t *utf8_restrict dst, const utf8_int8_t *utf8_restrict src, +size_t n); -// Similar to utf8dup, except that at most n bytes of src are copied. If src is -// longer than n, only n bytes are copied and a null byte is added. -// -// Returns a new string if successful, 0 otherwise +/* Similar to utf8dup, except that at most n bytes of src are copied. If src is + * longer than n, only n bytes are copied and a null byte is added. + * + * Returns a new string if successful, 0 otherwise */ utf8_weak utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n); -// Locates the first occurrence in the utf8 string str of any byte in the -// utf8 string accept, or 0 if no match was found. +/* Locates the first occurrence in the utf8 string str of any byte in the + * utf8 string accept, or 0 if no match was found. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept); -// Find the last match of the utf8 codepoint chr in the utf8 string src. +/* Find the last match of the utf8 codepoint chr in the utf8 string src. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8rchr(const utf8_int8_t *src, int chr); -// Number of bytes in the utf8 string str, -// including the null terminating byte. +/* Number of bytes in the utf8 string str, + * including the null terminating byte. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size(const utf8_int8_t *str); -// Similar to utf8size, except that the null terminating byte is excluded. +/* Similar to utf8size, except that the null terminating byte is excluded. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8size_lazy(const utf8_int8_t *str); -// Similar to utf8size, except that only at most n bytes of src are looked and -// the null terminating byte is excluded. +/* Similar to utf8size, except that only at most n bytes of src are looked and + * the null terminating byte is excluded. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n); -// Number of utf8 codepoints in the utf8 string src that consists entirely -// of utf8 codepoints from the utf8 string accept. +/* Number of utf8 codepoints in the utf8 string src that consists entirely + * of utf8 codepoints from the utf8 string accept. */ utf8_constexpr14 utf8_nonnull utf8_pure size_t utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept); -// The position of the utf8 string needle in the utf8 string haystack. +/* The position of the utf8 string needle in the utf8 string haystack. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle); -// The position of the utf8 string needle in the utf8 string haystack, case -// insensitive. +/* The position of the utf8 string needle in the utf8 string haystack, case + * insensitive. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle); -// Return 0 on success, or the position of the invalid -// utf8 codepoint on failure. +/* Return 0 on success, or the position of the invalid + * utf8 codepoint on failure. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8valid(const utf8_int8_t *str); -// Similar to utf8valid, except that only at most n bytes of src are looked. +/* Similar to utf8valid, except that only at most n bytes of src are looked. */ utf8_constexpr14 utf8_nonnull utf8_pure utf8_int8_t * utf8nvalid(const utf8_int8_t *str, size_t n); -// Given a null-terminated string, makes the string valid by replacing invalid -// codepoints with a 1-byte replacement. Returns 0 on success. +/* Given a null-terminated string, makes the string valid by replacing invalid + * codepoints with a 1-byte replacement. Returns 0 on success. */ utf8_nonnull utf8_weak int utf8makevalid(utf8_int8_t *str, - const utf8_int32_t replacement); +const utf8_int32_t replacement); -// Sets out_codepoint to the current utf8 codepoint in str, and returns the -// address of the next utf8 codepoint after the current one in str. +/* Sets out_codepoint to the current utf8 codepoint in str, and returns the + * address of the next utf8 codepoint after the current one in str. */ utf8_constexpr14 utf8_nonnull utf8_int8_t * utf8codepoint(const utf8_int8_t *utf8_restrict str, utf8_int32_t *utf8_restrict out_codepoint); -// Calculates the size of the next utf8 codepoint in str. +/* Calculates the size of the next utf8 codepoint in str. */ utf8_constexpr14 utf8_nonnull size_t utf8codepointcalcsize(const utf8_int8_t *str); -// Returns the size of the given codepoint in bytes. +/* Returns the size of the given codepoint in bytes. */ utf8_constexpr14 size_t utf8codepointsize(utf8_int32_t chr); -// Write a codepoint to the given string, and return the address to the next -// place after the written codepoint. Pass how many bytes left in the buffer to -// n. If there is not enough space for the codepoint, this function returns -// null. +/* Write a codepoint to the given string, and return the address to the next + * place after the written codepoint. Pass how many bytes left in the buffer to + * n. If there is not enough space for the codepoint, this function returns + * null. */ utf8_nonnull utf8_weak utf8_int8_t * -utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n); + utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n); -// Returns 1 if the given character is lowercase, or 0 if it is not. +/* Returns 1 if the given character is lowercase, or 0 if it is not. */ utf8_constexpr14 int utf8islower(utf8_int32_t chr); -// Returns 1 if the given character is uppercase, or 0 if it is not. +/* Returns 1 if the given character is uppercase, or 0 if it is not. */ utf8_constexpr14 int utf8isupper(utf8_int32_t chr); -// Transform the given string into all lowercase codepoints. +/* Transform the given string into all lowercase codepoints. */ utf8_nonnull utf8_weak void utf8lwr(utf8_int8_t *utf8_restrict str); -// Transform the given string into all uppercase codepoints. +/* Transform the given string into all uppercase codepoints. */ utf8_nonnull utf8_weak void utf8upr(utf8_int8_t *utf8_restrict str); -// Make a codepoint lower case if possible. +/* Make a codepoint lower case if possible. */ utf8_constexpr14 utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp); -// Make a codepoint upper case if possible. +/* Make a codepoint upper case if possible. */ utf8_constexpr14 utf8_int32_t utf8uprcodepoint(utf8_int32_t cp); -// Sets out_codepoint to the current utf8 codepoint in str, and returns the -// address of the previous utf8 codepoint before the current one in str. +/* Sets out_codepoint to the current utf8 codepoint in str, and returns the + * address of the previous utf8 codepoint before the current one in str. */ utf8_constexpr14 utf8_nonnull utf8_int8_t * utf8rcodepoint(const utf8_int8_t *utf8_restrict str, utf8_int32_t *utf8_restrict out_codepoint); -// Duplicate the utf8 string src by getting its size, calling alloc_func_ptr to -// copy over data to a new buffer, and returning that. Or 0 if alloc_func_ptr -// returned null. +/* Duplicate the utf8 string src by getting its size, calling alloc_func_ptr to + * copy over data to a new buffer, and returning that. Or 0 if alloc_func_ptr + * returned null. */ utf8_weak utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); + size_t), + utf8_int8_t *user_data); -// Similar to utf8dup, except that at most n bytes of src are copied. If src is -// longer than n, only n bytes are copied and a null byte is added. -// -// Returns a new string if successful, 0 otherwise. +/* Similar to utf8dup, except that at most n bytes of src are copied. If src is + * longer than n, only n bytes are copied and a null byte is added. + * + * Returns a new string if successful, 0 otherwise. */ utf8_weak utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, - size_t), - utf8_int8_t *user_data); + size_t), + utf8_int8_t *user_data); #undef utf8_weak #undef utf8_pure @@ -293,1375 +293,1378 @@ utf8_weak utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, utf8_constexpr14_impl int utf8casecmp(const utf8_int8_t *src1, const utf8_int8_t *src2) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; - - for (;;) { - src1 = utf8codepoint(src1, &src1_orig_cp); - src2 = utf8codepoint(src2, &src2_orig_cp); - - // lower the srcs if required - src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); - src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); - - // lower the srcs if required - src1_upr_cp = utf8uprcodepoint(src1_orig_cp); - src2_upr_cp = utf8uprcodepoint(src2_orig_cp); - - // check if the lowered codepoints match - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { - continue; - } + utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, + src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; + + for (;;) { + src1 = utf8codepoint(src1, &src1_orig_cp); + src2 = utf8codepoint(src2, &src2_orig_cp); + + /* lower the srcs if required */ + src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); + src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); + + /* lower the srcs if required */ + src1_upr_cp = utf8uprcodepoint(src1_orig_cp); + src2_upr_cp = utf8uprcodepoint(src2_orig_cp); + + /* check if the lowered codepoints match */ + if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { + return 0; + } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { + continue; + } - // if they don't match, then we return the difference between the characters - return src1_lwr_cp - src2_lwr_cp; - } + /* if they don't match, then we return the difference between the characters + */ + return src1_lwr_cp - src2_lwr_cp; + } } utf8_int8_t *utf8cat(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src) { - utf8_int8_t *d = dst; - // find the null terminating byte in dst - while ('\0' != *d) { - d++; - } +const utf8_int8_t *utf8_restrict src) { +utf8_int8_t *d = dst; +/* find the null terminating byte in dst */ +while ('\0' != *d) { +d++; +} - // overwriting the null terminating byte in dst, append src byte-by-byte - while ('\0' != *src) { - *d++ = *src++; - } +/* overwriting the null terminating byte in dst, append src byte-by-byte */ +while ('\0' != *src) { +*d++ = *src++; +} - // write out a new null terminating byte into dst - *d = '\0'; +/* write out a new null terminating byte into dst */ +*d = '\0'; - return dst; +return dst; } utf8_constexpr14_impl utf8_int8_t *utf8chr(const utf8_int8_t *src, utf8_int32_t chr) { - utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; + utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; - if (0 == chr) { - // being asked to return position of null terminating byte, so - // just run s to the end, and return! - while ('\0' != *src) { - src++; + if (0 == chr) { + /* being asked to return position of null terminating byte, so + * just run s to the end, and return! */ + while ('\0' != *src) { + src++; + } + return (utf8_int8_t *)src; + } else if (0 == ((utf8_int32_t)0xffffff80 & chr)) { + /* 1-byte/7-bit ascii + * (0b0xxxxxxx) */ + c[0] = (utf8_int8_t)chr; + } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { + /* 2-byte/11-bit utf8 code point + * (0b110xxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { + /* 3-byte/16-bit utf8 code point + * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + } else { /* if (0 == ((int)0xffe00000 & chr)) { */ + /* 4-byte/21-bit utf8 code point + * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); + c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); } - return (utf8_int8_t *)src; - } else if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - c[0] = (utf8_int8_t)chr; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } - - // we've made c into a 2 utf8 codepoint string, one for the chr we are - // seeking, another for the null terminating byte. Now use utf8str to - // search - return utf8str(src, c); + + /* we've made c into a 2 utf8 codepoint string, one for the chr we are + * seeking, another for the null terminating byte. Now use utf8str to + * search */ + return utf8str(src, c); } utf8_constexpr14_impl int utf8cmp(const utf8_int8_t *src1, const utf8_int8_t *src2) { - while (('\0' != *src1) || ('\0' != *src2)) { - if (*src1 < *src2) { - return -1; - } else if (*src1 > *src2) { - return 1; - } + while (('\0' != *src1) || ('\0' != *src2)) { + if (*src1 < *src2) { + return -1; + } else if (*src1 > *src2) { + return 1; + } - src1++; - src2++; - } + src1++; + src2++; + } - // both utf8 strings matched - return 0; + /* both utf8 strings matched */ + return 0; } utf8_constexpr14_impl int utf8coll(const utf8_int8_t *src1, const utf8_int8_t *src2); utf8_int8_t *utf8cpy(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src) { - utf8_int8_t *d = dst; +const utf8_int8_t *utf8_restrict src) { +utf8_int8_t *d = dst; - // overwriting anything previously in dst, write byte-by-byte - // from src - while ('\0' != *src) { - *d++ = *src++; - } +/* overwriting anything previously in dst, write byte-by-byte + * from src */ +while ('\0' != *src) { +*d++ = *src++; +} - // append null terminating byte - *d = '\0'; +/* append null terminating byte */ +*d = '\0'; - return dst; +return dst; } utf8_constexpr14_impl size_t utf8cspn(const utf8_int8_t *src, const utf8_int8_t *reject) { - size_t chars = 0; - - while ('\0' != *src) { - const utf8_int8_t *r = reject; - size_t offset = 0; - - while ('\0' != *r) { - // checking that if *r is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *r)) && (0 < offset)) { - return chars; - } else { - if (*r == src[offset]) { - // part of a utf8 codepoint matched, so move our checking - // onwards to the next byte - offset++; - r++; - } else { - // r could be in the middle of an unmatching utf8 code point, - // so we need to march it on to the next character beginning, + size_t chars = 0; - do { - r++; - } while (0x80 == (0xc0 & *r)); + while ('\0' != *src) { + const utf8_int8_t *r = reject; + size_t offset = 0; + + while ('\0' != *r) { + /* checking that if *r is the start of a utf8 codepoint + * (it is not 0b10xxxxxx) and we have successfully matched + * a previous character (0 < offset) - we found a match */ + if ((0x80 != (0xc0 & *r)) && (0 < offset)) { + return chars; + } else { + if (*r == src[offset]) { + /* part of a utf8 codepoint matched, so move our checking + * onwards to the next byte */ + offset++; + r++; + } else { + /* r could be in the middle of an unmatching utf8 code point, + * so we need to march it on to the next character beginning, */ + + do { + r++; + } while (0x80 == (0xc0 & *r)); + + /* reset offset too as we found a mismatch */ + offset = 0; + } + } + } - // reset offset too as we found a mismatch - offset = 0; + /* found a match at the end of *r, so didn't get a chance to test it */ + if (0 < offset) { + return chars; } - } - } - // found a match at the end of *r, so didn't get a chance to test it - if (0 < offset) { - return chars; + /* the current utf8 codepoint in src did not match reject, but src + * could have been partway through a utf8 codepoint, so we need to + * march it onto the next utf8 codepoint starting byte */ + do { + src++; + } while ((0x80 == (0xc0 & *src))); + chars++; } - // the current utf8 codepoint in src did not match reject, but src - // could have been partway through a utf8 codepoint, so we need to - // march it onto the next utf8 codepoint starting byte - do { - src++; - } while ((0x80 == (0xc0 & *src))); - chars++; - } - - return chars; + return chars; } utf8_int8_t *utf8dup(const utf8_int8_t *src) { - return utf8dup_ex(src, utf8_null, utf8_null); + return utf8dup_ex(src, utf8_null, utf8_null); } utf8_int8_t *utf8dup_ex(const utf8_int8_t *src, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { - utf8_int8_t *n = utf8_null; + utf8_int8_t *user_data) { +utf8_int8_t *n = utf8_null; - // figure out how many bytes (including the terminator) we need to copy first - size_t bytes = utf8size(src); +/* figure out how many bytes (including the terminator) we need to copy first + */ +size_t bytes = utf8size(src); - if (alloc_func_ptr) { - n = alloc_func_ptr(user_data, bytes); - } else { - n = (utf8_int8_t *)malloc(bytes); - } +if (alloc_func_ptr) { +n = alloc_func_ptr(user_data, bytes); +} else { +n = (utf8_int8_t *)malloc(bytes); +} - if (utf8_null == n) { - // out of memory so we bail - return utf8_null; - } else { - bytes = 0; +if (utf8_null == n) { +/* out of memory so we bail */ +return utf8_null; +} else { +bytes = 0; - // copy src byte-by-byte into our new utf8 string - while ('\0' != src[bytes]) { - n[bytes] = src[bytes]; - bytes++; - } +/* copy src byte-by-byte into our new utf8 string */ +while ('\0' != src[bytes]) { +n[bytes] = src[bytes]; +bytes++; +} - // append null terminating byte - n[bytes] = '\0'; - return n; - } +/* append null terminating byte */ +n[bytes] = '\0'; +return n; +} } utf8_constexpr14_impl utf8_int8_t *utf8fry(const utf8_int8_t *str); utf8_constexpr14_impl size_t utf8len(const utf8_int8_t *str) { - return utf8nlen(str, SIZE_MAX); + return utf8nlen(str, SIZE_MAX); } utf8_constexpr14_impl size_t utf8nlen(const utf8_int8_t *str, size_t n) { - const utf8_int8_t *t = str; - size_t length = 0; - - while ((size_t)(str - t) < n && '\0' != *str) { - if (0xf0 == (0xf8 & *str)) { - // 4-byte utf8 code point (began with 0b11110xxx) - str += 4; - } else if (0xe0 == (0xf0 & *str)) { - // 3-byte utf8 code point (began with 0b1110xxxx) - str += 3; - } else if (0xc0 == (0xe0 & *str)) { - // 2-byte utf8 code point (began with 0b110xxxxx) - str += 2; - } else { // if (0x00 == (0x80 & *s)) { - // 1-byte ascii (began with 0b0xxxxxxx) - str += 1; - } + const utf8_int8_t *t = str; + size_t length = 0; + + while ((size_t)(str - t) < n && '\0' != *str) { + if (0xf0 == (0xf8 & *str)) { + /* 4-byte utf8 code point (began with 0b11110xxx) */ + str += 4; + } else if (0xe0 == (0xf0 & *str)) { + /* 3-byte utf8 code point (began with 0b1110xxxx) */ + str += 3; + } else if (0xc0 == (0xe0 & *str)) { + /* 2-byte utf8 code point (began with 0b110xxxxx) */ + str += 2; + } else { /* if (0x00 == (0x80 & *s)) { */ + /* 1-byte ascii (began with 0b0xxxxxxx) */ + str += 1; + } - // no matter the bytes we marched s forward by, it was - // only 1 utf8 codepoint - length++; - } + /* no matter the bytes we marched s forward by, it was + * only 1 utf8 codepoint */ + length++; + } - if ((size_t)(str - t) > n) { - length--; - } - return length; + if ((size_t)(str - t) > n) { + length--; + } + return length; } utf8_constexpr14_impl int utf8ncasecmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n) { - utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, - src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; + utf8_int32_t src1_lwr_cp = 0, src2_lwr_cp = 0, src1_upr_cp = 0, + src2_upr_cp = 0, src1_orig_cp = 0, src2_orig_cp = 0; - do { - const utf8_int8_t *const s1 = src1; - const utf8_int8_t *const s2 = src2; + do { + const utf8_int8_t *const s1 = src1; + const utf8_int8_t *const s2 = src2; - // first check that we have enough bytes left in n to contain an entire - // codepoint - if (0 == n) { - return 0; - } + /* first check that we have enough bytes left in n to contain an entire + * codepoint */ + if (0 == n) { + return 0; + } - if ((1 == n) && ((0xc0 == (0xe0 & *s1)) || (0xc0 == (0xe0 & *s2)))) { - const utf8_int32_t c1 = (0xe0 & *s1); - const utf8_int32_t c2 = (0xe0 & *s2); + if ((1 == n) && ((0xc0 == (0xe0 & *s1)) || (0xc0 == (0xe0 & *s2)))) { + const utf8_int32_t c1 = (0xe0 & *s1); + const utf8_int32_t c2 = (0xe0 & *s2); - if (c1 < c2) { - return c1 - c2; - } else { - return 0; - } - } + if (c1 < c2) { + return c1 - c2; + } else { + return 0; + } + } - if ((2 >= n) && ((0xe0 == (0xf0 & *s1)) || (0xe0 == (0xf0 & *s2)))) { - const utf8_int32_t c1 = (0xf0 & *s1); - const utf8_int32_t c2 = (0xf0 & *s2); + if ((2 >= n) && ((0xe0 == (0xf0 & *s1)) || (0xe0 == (0xf0 & *s2)))) { + const utf8_int32_t c1 = (0xf0 & *s1); + const utf8_int32_t c2 = (0xf0 & *s2); - if (c1 < c2) { - return c1 - c2; - } else { - return 0; - } - } + if (c1 < c2) { + return c1 - c2; + } else { + return 0; + } + } - if ((3 >= n) && ((0xf0 == (0xf8 & *s1)) || (0xf0 == (0xf8 & *s2)))) { - const utf8_int32_t c1 = (0xf8 & *s1); - const utf8_int32_t c2 = (0xf8 & *s2); + if ((3 >= n) && ((0xf0 == (0xf8 & *s1)) || (0xf0 == (0xf8 & *s2)))) { + const utf8_int32_t c1 = (0xf8 & *s1); + const utf8_int32_t c2 = (0xf8 & *s2); - if (c1 < c2) { - return c1 - c2; - } else { - return 0; - } - } + if (c1 < c2) { + return c1 - c2; + } else { + return 0; + } + } - src1 = utf8codepoint(src1, &src1_orig_cp); - src2 = utf8codepoint(src2, &src2_orig_cp); - n -= utf8codepointsize(src1_orig_cp); + src1 = utf8codepoint(src1, &src1_orig_cp); + src2 = utf8codepoint(src2, &src2_orig_cp); + n -= utf8codepointsize(src1_orig_cp); - src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); - src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); + src1_lwr_cp = utf8lwrcodepoint(src1_orig_cp); + src2_lwr_cp = utf8lwrcodepoint(src2_orig_cp); - src1_upr_cp = utf8uprcodepoint(src1_orig_cp); - src2_upr_cp = utf8uprcodepoint(src2_orig_cp); + src1_upr_cp = utf8uprcodepoint(src1_orig_cp); + src2_upr_cp = utf8uprcodepoint(src2_orig_cp); - // check if the lowered codepoints match - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { - continue; - } + /* check if the lowered codepoints match */ + if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { + return 0; + } else if ((src1_lwr_cp == src2_lwr_cp) || (src1_upr_cp == src2_upr_cp)) { + continue; + } - // if they don't match, then we return the difference between the characters - return src1_lwr_cp - src2_lwr_cp; - } while (0 < n); + /* if they don't match, then we return the difference between the characters + */ + return src1_lwr_cp - src2_lwr_cp; + } while (0 < n); - // both utf8 strings matched - return 0; + /* both utf8 strings matched */ + return 0; } utf8_int8_t *utf8ncat(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src, size_t n) { - utf8_int8_t *d = dst; +const utf8_int8_t *utf8_restrict src, size_t n) { +utf8_int8_t *d = dst; - // find the null terminating byte in dst - while ('\0' != *d) { - d++; - } +/* find the null terminating byte in dst */ +while ('\0' != *d) { +d++; +} - // overwriting the null terminating byte in dst, append src byte-by-byte - // stopping if we run out of space - do { - *d++ = *src++; - } while (('\0' != *src) && (0 != --n)); +/* overwriting the null terminating byte in dst, append src byte-by-byte + * stopping if we run out of space */ +do { +*d++ = *src++; +} while (('\0' != *src) && (0 != --n)); - // write out a new null terminating byte into dst - *d = '\0'; +/* write out a new null terminating byte into dst */ +*d = '\0'; - return dst; +return dst; } utf8_constexpr14_impl int utf8ncmp(const utf8_int8_t *src1, const utf8_int8_t *src2, size_t n) { - while ((0 != n--) && (('\0' != *src1) || ('\0' != *src2))) { - if (*src1 < *src2) { - return -1; - } else if (*src1 > *src2) { - return 1; - } + while ((0 != n--) && (('\0' != *src1) || ('\0' != *src2))) { + if (*src1 < *src2) { + return -1; + } else if (*src1 > *src2) { + return 1; + } - src1++; - src2++; - } + src1++; + src2++; + } - // both utf8 strings matched - return 0; + /* both utf8 strings matched */ + return 0; } utf8_int8_t *utf8ncpy(utf8_int8_t *utf8_restrict dst, - const utf8_int8_t *utf8_restrict src, size_t n) { - utf8_int8_t *d = dst; - size_t index = 0, check_index = 0; - - if (n == 0) { - return dst; - } - - // overwriting anything previously in dst, write byte-by-byte - // from src - for (index = 0; index < n; index++) { - d[index] = src[index]; - if ('\0' == src[index]) { - break; - } - } +const utf8_int8_t *utf8_restrict src, size_t n) { +utf8_int8_t *d = dst; +size_t index = 0, check_index = 0; + +if (n == 0) { +return dst; +} + +/* overwriting anything previously in dst, write byte-by-byte + * from src */ +for (index = 0; index < n; index++) { +d[index] = src[index]; +if ('\0' == src[index]) { +break; +} +} - for (check_index = index - 1; - check_index > 0 && 0x80 == (0xc0 & d[check_index]); check_index--) { - // just moving the index - } +for (check_index = index - 1; +check_index > 0 && 0x80 == (0xc0 & d[check_index]); check_index--) { +/* just moving the index */ +} - if (check_index < index && - (index - check_index) < utf8codepointsize(d[check_index])) { - index = check_index; - } +if (check_index < index && +(index - check_index) < utf8codepointsize(d[check_index])) { +index = check_index; +} - // append null terminating byte - for (; index < n; index++) { - d[index] = 0; - } +/* append null terminating byte */ +for (; index < n; index++) { +d[index] = 0; +} - return dst; +return dst; } utf8_int8_t *utf8ndup(const utf8_int8_t *src, size_t n) { - return utf8ndup_ex(src, n, utf8_null, utf8_null); + return utf8ndup_ex(src, n, utf8_null, utf8_null); } utf8_int8_t *utf8ndup_ex(const utf8_int8_t *src, size_t n, utf8_int8_t *(*alloc_func_ptr)(utf8_int8_t *, size_t), - utf8_int8_t *user_data) { - utf8_int8_t *c = utf8_null; - size_t bytes = 0; - - // Find the end of the string or stop when n is reached - while ('\0' != src[bytes] && bytes < n) { - bytes++; - } - - // In case bytes is actually less than n, we need to set it - // to be used later in the copy byte by byte. - n = bytes; - - if (alloc_func_ptr) { - c = alloc_func_ptr(user_data, bytes + 1); - } else { - c = (utf8_int8_t *)malloc(bytes + 1); - } - - if (utf8_null == c) { - // out of memory so we bail - return utf8_null; - } + utf8_int8_t *user_data) { +utf8_int8_t *c = utf8_null; +size_t bytes = 0; - bytes = 0; +/* Find the end of the string or stop when n is reached */ +while ('\0' != src[bytes] && bytes < n) { +bytes++; +} + +/* In case bytes is actually less than n, we need to set it + * to be used later in the copy byte by byte. */ +n = bytes; - // copy src byte-by-byte into our new utf8 string - while ('\0' != src[bytes] && bytes < n) { - c[bytes] = src[bytes]; - bytes++; - } +if (alloc_func_ptr) { +c = alloc_func_ptr(user_data, bytes + 1); +} else { +c = (utf8_int8_t *)malloc(bytes + 1); +} - // append null terminating byte - c[bytes] = '\0'; - return c; +if (utf8_null == c) { +/* out of memory so we bail */ +return utf8_null; +} + +bytes = 0; + +/* copy src byte-by-byte into our new utf8 string */ +while ('\0' != src[bytes] && bytes < n) { +c[bytes] = src[bytes]; +bytes++; +} + +/* append null terminating byte */ +c[bytes] = '\0'; +return c; } utf8_constexpr14_impl utf8_int8_t *utf8rchr(const utf8_int8_t *src, int chr) { - utf8_int8_t *match = utf8_null; - utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; + utf8_int8_t *match = utf8_null; + utf8_int8_t c[5] = {'\0', '\0', '\0', '\0', '\0'}; - if (0 == chr) { - // being asked to return position of null terminating byte, so - // just run s to the end, and return! - while ('\0' != *src) { - src++; - } - return (utf8_int8_t *)src; - } else if (0 == ((int)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - c[0] = (utf8_int8_t)chr; - } else if (0 == ((int)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else if (0 == ((int)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); - c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - } - - // we've created a 2 utf8 codepoint string in c that is - // the utf8 character asked for by chr, and a null - // terminating byte - - while ('\0' != *src) { - size_t offset = 0; - - while (src[offset] == c[offset]) { - offset++; + if (0 == chr) { + /* being asked to return position of null terminating byte, so + * just run s to the end, and return! */ + while ('\0' != *src) { + src++; + } + return (utf8_int8_t *)src; + } else if (0 == ((int)0xffffff80 & chr)) { + /* 1-byte/7-bit ascii + * (0b0xxxxxxx) */ + c[0] = (utf8_int8_t)chr; + } else if (0 == ((int)0xfffff800 & chr)) { + /* 2-byte/11-bit utf8 code point + * (0b110xxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)(chr >> 6)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + } else if (0 == ((int)0xffff0000 & chr)) { + /* 3-byte/16-bit utf8 code point + * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)(chr >> 12)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); + } else { /* if (0 == ((int)0xffe00000 & chr)) { */ + /* 4-byte/21-bit utf8 code point + * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ + c[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)(chr >> 18)); + c[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); + c[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); + c[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); } - if ('\0' == c[offset]) { - // we found a matching utf8 code point - match = (utf8_int8_t *)src; - src += offset; - } else { - src += offset; + /* we've created a 2 utf8 codepoint string in c that is + * the utf8 character asked for by chr, and a null + * terminating byte */ - // need to march s along to next utf8 codepoint start - // (the next byte that doesn't match 0b10xxxxxx) - if ('\0' != *src) { - do { - src++; - } while (0x80 == (0xc0 & *src)); - } + while ('\0' != *src) { + size_t offset = 0; + + while (src[offset] == c[offset]) { + offset++; + } + + if ('\0' == c[offset]) { + /* we found a matching utf8 code point */ + match = (utf8_int8_t *)src; + src += offset; + } else { + src += offset; + + /* need to march s along to next utf8 codepoint start + * (the next byte that doesn't match 0b10xxxxxx) */ + if ('\0' != *src) { + do { + src++; + } while (0x80 == (0xc0 & *src)); + } + } } - } - // return the last match we found (or 0 if no match was found) - return match; + /* return the last match we found (or 0 if no match was found) */ + return match; } utf8_constexpr14_impl utf8_int8_t *utf8pbrk(const utf8_int8_t *str, const utf8_int8_t *accept) { - while ('\0' != *str) { - const utf8_int8_t *a = accept; - size_t offset = 0; - - while ('\0' != *a) { - // checking that if *a is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - return (utf8_int8_t *)str; - } else { - if (*a == str[offset]) { - // part of a utf8 codepoint matched, so move our checking - // onwards to the next byte - offset++; - a++; - } else { - // r could be in the middle of an unmatching utf8 code point, - // so we need to march it on to the next character beginning, - - do { - a++; - } while (0x80 == (0xc0 & *a)); + while ('\0' != *str) { + const utf8_int8_t *a = accept; + size_t offset = 0; + + while ('\0' != *a) { + /* checking that if *a is the start of a utf8 codepoint + * (it is not 0b10xxxxxx) and we have successfully matched + * a previous character (0 < offset) - we found a match */ + if ((0x80 != (0xc0 & *a)) && (0 < offset)) { + return (utf8_int8_t *)str; + } else { + if (*a == str[offset]) { + /* part of a utf8 codepoint matched, so move our checking + * onwards to the next byte */ + offset++; + a++; + } else { + /* r could be in the middle of an unmatching utf8 code point, + * so we need to march it on to the next character beginning, */ + + do { + a++; + } while (0x80 == (0xc0 & *a)); + + /* reset offset too as we found a mismatch */ + offset = 0; + } + } + } - // reset offset too as we found a mismatch - offset = 0; + /* we found a match on the last utf8 codepoint */ + if (0 < offset) { + return (utf8_int8_t *)str; } - } - } - // we found a match on the last utf8 codepoint - if (0 < offset) { - return (utf8_int8_t *)str; + /* the current utf8 codepoint in src did not match accept, but src + * could have been partway through a utf8 codepoint, so we need to + * march it onto the next utf8 codepoint starting byte */ + do { + str++; + } while ((0x80 == (0xc0 & *str))); } - // the current utf8 codepoint in src did not match accept, but src - // could have been partway through a utf8 codepoint, so we need to - // march it onto the next utf8 codepoint starting byte - do { - str++; - } while ((0x80 == (0xc0 & *str))); - } - - return utf8_null; + return utf8_null; } utf8_constexpr14_impl size_t utf8size(const utf8_int8_t *str) { - return utf8size_lazy(str) + 1; + return utf8size_lazy(str) + 1; } utf8_constexpr14_impl size_t utf8size_lazy(const utf8_int8_t *str) { - return utf8nsize_lazy(str, SIZE_MAX); + return utf8nsize_lazy(str, SIZE_MAX); } utf8_constexpr14_impl size_t utf8nsize_lazy(const utf8_int8_t *str, size_t n) { - size_t size = 0; - while (size < n && '\0' != str[size]) { - size++; - } - return size; + size_t size = 0; + while (size < n && '\0' != str[size]) { + size++; + } + return size; } utf8_constexpr14_impl size_t utf8spn(const utf8_int8_t *src, const utf8_int8_t *accept) { - size_t chars = 0; - - while ('\0' != *src) { - const utf8_int8_t *a = accept; - size_t offset = 0; - - while ('\0' != *a) { - // checking that if *r is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - // found a match, so increment the number of utf8 codepoints - // that have matched and stop checking whether any other utf8 - // codepoints in a match - chars++; - src += offset; - offset = 0; - break; - } else { - if (*a == src[offset]) { - offset++; - a++; - } else { - // a could be in the middle of an unmatching utf8 codepoint, - // so we need to march it on to the next character beginning, - do { - a++; - } while (0x80 == (0xc0 & *a)); - - // reset offset too as we found a mismatch - offset = 0; + size_t chars = 0; + + while ('\0' != *src) { + const utf8_int8_t *a = accept; + size_t offset = 0; + + while ('\0' != *a) { + /* checking that if *r is the start of a utf8 codepoint + * (it is not 0b10xxxxxx) and we have successfully matched + * a previous character (0 < offset) - we found a match */ + if ((0x80 != (0xc0 & *a)) && (0 < offset)) { + /* found a match, so increment the number of utf8 codepoints + * that have matched and stop checking whether any other utf8 + * codepoints in a match */ + chars++; + src += offset; + offset = 0; + break; + } else { + if (*a == src[offset]) { + offset++; + a++; + } else { + /* a could be in the middle of an unmatching utf8 codepoint, + * so we need to march it on to the next character beginning, */ + do { + a++; + } while (0x80 == (0xc0 & *a)); + + /* reset offset too as we found a mismatch */ + offset = 0; + } + } } - } - } - // found a match at the end of *a, so didn't get a chance to test it - if (0 < offset) { - chars++; - src += offset; - continue; - } + /* found a match at the end of *a, so didn't get a chance to test it */ + if (0 < offset) { + chars++; + src += offset; + continue; + } - // if a got to its terminating null byte, then we didn't find a match. - // Return the current number of matched utf8 codepoints - if ('\0' == *a) { - return chars; + /* if a got to its terminating null byte, then we didn't find a match. + * Return the current number of matched utf8 codepoints */ + if ('\0' == *a) { + return chars; + } } - } - return chars; + return chars; } utf8_constexpr14_impl utf8_int8_t *utf8str(const utf8_int8_t *haystack, const utf8_int8_t *needle) { - utf8_int32_t throwaway_codepoint = 0; + utf8_int32_t throwaway_codepoint = 0; - // if needle has no utf8 codepoints before the null terminating - // byte then return haystack - if ('\0' == *needle) { - return (utf8_int8_t *)haystack; - } + /* if needle has no utf8 codepoints before the null terminating + * byte then return haystack */ + if ('\0' == *needle) { + return (utf8_int8_t *)haystack; + } - while ('\0' != *haystack) { - const utf8_int8_t *maybeMatch = haystack; - const utf8_int8_t *n = needle; + while ('\0' != *haystack) { + const utf8_int8_t *maybeMatch = haystack; + const utf8_int8_t *n = needle; - while (*haystack == *n && (*haystack != '\0' && *n != '\0')) { - n++; - haystack++; - } + while (*haystack == *n && (*haystack != '\0' && *n != '\0')) { + n++; + haystack++; + } - if ('\0' == *n) { - // we found the whole utf8 string for needle in haystack at - // maybeMatch, so return it - return (utf8_int8_t *)maybeMatch; - } else { - // h could be in the middle of an unmatching utf8 codepoint, - // so we need to march it on to the next character beginning - // starting from the current character - haystack = utf8codepoint(maybeMatch, &throwaway_codepoint); + if ('\0' == *n) { + /* we found the whole utf8 string for needle in haystack at + * maybeMatch, so return it */ + return (utf8_int8_t *)maybeMatch; + } else { + /* h could be in the middle of an unmatching utf8 codepoint, + * so we need to march it on to the next character beginning + * starting from the current character */ + haystack = utf8codepoint(maybeMatch, &throwaway_codepoint); + } } - } - // no match - return utf8_null; + /* no match */ + return utf8_null; } utf8_constexpr14_impl utf8_int8_t *utf8casestr(const utf8_int8_t *haystack, const utf8_int8_t *needle) { - // if needle has no utf8 codepoints before the null terminating - // byte then return haystack - if ('\0' == *needle) { - return (utf8_int8_t *)haystack; - } - - for (;;) { - const utf8_int8_t *maybeMatch = haystack; - const utf8_int8_t *n = needle; - utf8_int32_t h_cp = 0, n_cp = 0; - - // Get the next code point and track it - const utf8_int8_t *nextH = haystack = utf8codepoint(haystack, &h_cp); - n = utf8codepoint(n, &n_cp); - - while ((0 != h_cp) && (0 != n_cp)) { - h_cp = utf8lwrcodepoint(h_cp); - n_cp = utf8lwrcodepoint(n_cp); - - // if we find a mismatch, bail out! - if (h_cp != n_cp) { - break; - } - - haystack = utf8codepoint(haystack, &h_cp); - n = utf8codepoint(n, &n_cp); + /* if needle has no utf8 codepoints before the null terminating + * byte then return haystack */ + if ('\0' == *needle) { + return (utf8_int8_t *)haystack; } - if (0 == n_cp) { - // we found the whole utf8 string for needle in haystack at - // maybeMatch, so return it - return (utf8_int8_t *)maybeMatch; - } + for (;;) { + const utf8_int8_t *maybeMatch = haystack; + const utf8_int8_t *n = needle; + utf8_int32_t h_cp = 0, n_cp = 0; - if (0 == h_cp) { - // no match - return utf8_null; - } + /* Get the next code point and track it */ + const utf8_int8_t *nextH = haystack = utf8codepoint(haystack, &h_cp); + n = utf8codepoint(n, &n_cp); + + while ((0 != h_cp) && (0 != n_cp)) { + h_cp = utf8lwrcodepoint(h_cp); + n_cp = utf8lwrcodepoint(n_cp); + + /* if we find a mismatch, bail out! */ + if (h_cp != n_cp) { + break; + } + + haystack = utf8codepoint(haystack, &h_cp); + n = utf8codepoint(n, &n_cp); + } - // Roll back to the next code point in the haystack to test - haystack = nextH; - } + if (0 == n_cp) { + /* we found the whole utf8 string for needle in haystack at + * maybeMatch, so return it */ + return (utf8_int8_t *)maybeMatch; + } + + if (0 == h_cp) { + /* no match */ + return utf8_null; + } + + /* Roll back to the next code point in the haystack to test */ + haystack = nextH; + } } utf8_constexpr14_impl utf8_int8_t *utf8valid(const utf8_int8_t *str) { - return utf8nvalid(str, SIZE_MAX); + return utf8nvalid(str, SIZE_MAX); } utf8_constexpr14_impl utf8_int8_t *utf8nvalid(const utf8_int8_t *str, size_t n) { - const utf8_int8_t *t = str; - size_t consumed = 0, remained = 0; - - while ((void)(consumed = (size_t)(str - t)), consumed < n && '\0' != *str) { - remained = n - consumed; - - if (0xf0 == (0xf8 & *str)) { - // ensure that there's 4 bytes or more remained - if (remained < 4) { - return (utf8_int8_t *)str; - } - - // ensure each of the 3 following bytes in this 4-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2])) || - (0x80 != (0xc0 & str[3]))) { - return (utf8_int8_t *)str; - } - - // ensure that our utf8 codepoint ended after 4 bytes - if (0x80 == (0xc0 & str[4])) { - return (utf8_int8_t *)str; - } - - // ensure that the top 5 bits of this 4-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if ((0 == (0x07 & str[0])) && (0 == (0x30 & str[1]))) { - return (utf8_int8_t *)str; - } - - // 4-byte utf8 code point (began with 0b11110xxx) - str += 4; - } else if (0xe0 == (0xf0 & *str)) { - // ensure that there's 3 bytes or more remained - if (remained < 3) { - return (utf8_int8_t *)str; - } - - // ensure each of the 2 following bytes in this 3-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2]))) { - return (utf8_int8_t *)str; - } - - // ensure that our utf8 codepoint ended after 3 bytes - if (0x80 == (0xc0 & str[3])) { - return (utf8_int8_t *)str; - } - - // ensure that the top 5 bits of this 3-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if ((0 == (0x0f & str[0])) && (0 == (0x20 & str[1]))) { - return (utf8_int8_t *)str; - } - - // 3-byte utf8 code point (began with 0b1110xxxx) - str += 3; - } else if (0xc0 == (0xe0 & *str)) { - // ensure that there's 2 bytes or more remained - if (remained < 2) { - return (utf8_int8_t *)str; - } - - // ensure the 1 following byte in this 2-byte - // utf8 codepoint began with 0b10xxxxxx - if (0x80 != (0xc0 & str[1])) { - return (utf8_int8_t *)str; - } - - // ensure that our utf8 codepoint ended after 2 bytes - if (0x80 == (0xc0 & str[2])) { - return (utf8_int8_t *)str; - } - - // ensure that the top 4 bits of this 2-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if (0 == (0x1e & str[0])) { - return (utf8_int8_t *)str; - } - - // 2-byte utf8 code point (began with 0b110xxxxx) - str += 2; - } else if (0x00 == (0x80 & *str)) { - // 1-byte ascii (began with 0b0xxxxxxx) - str += 1; - } else { - // we have an invalid 0b1xxxxxxx utf8 code point entry - return (utf8_int8_t *)str; + const utf8_int8_t *t = str; + size_t consumed = 0, remained = 0; + + while ((void)(consumed = (size_t)(str - t)), consumed < n && '\0' != *str) { + remained = n - consumed; + + if (0xf0 == (0xf8 & *str)) { + /* ensure that there's 4 bytes or more remained */ + if (remained < 4) { + return (utf8_int8_t *)str; + } + + /* ensure each of the 3 following bytes in this 4-byte + * utf8 codepoint began with 0b10xxxxxx */ + if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2])) || + (0x80 != (0xc0 & str[3]))) { + return (utf8_int8_t *)str; + } + + /* ensure that our utf8 codepoint ended after 4 bytes */ + if (0x80 == (0xc0 & str[4])) { + return (utf8_int8_t *)str; + } + + /* ensure that the top 5 bits of this 4-byte utf8 + * codepoint were not 0, as then we could have used + * one of the smaller encodings */ + if ((0 == (0x07 & str[0])) && (0 == (0x30 & str[1]))) { + return (utf8_int8_t *)str; + } + + /* 4-byte utf8 code point (began with 0b11110xxx) */ + str += 4; + } else if (0xe0 == (0xf0 & *str)) { + /* ensure that there's 3 bytes or more remained */ + if (remained < 3) { + return (utf8_int8_t *)str; + } + + /* ensure each of the 2 following bytes in this 3-byte + * utf8 codepoint began with 0b10xxxxxx */ + if ((0x80 != (0xc0 & str[1])) || (0x80 != (0xc0 & str[2]))) { + return (utf8_int8_t *)str; + } + + /* ensure that our utf8 codepoint ended after 3 bytes */ + if (0x80 == (0xc0 & str[3])) { + return (utf8_int8_t *)str; + } + + /* ensure that the top 5 bits of this 3-byte utf8 + * codepoint were not 0, as then we could have used + * one of the smaller encodings */ + if ((0 == (0x0f & str[0])) && (0 == (0x20 & str[1]))) { + return (utf8_int8_t *)str; + } + + /* 3-byte utf8 code point (began with 0b1110xxxx) */ + str += 3; + } else if (0xc0 == (0xe0 & *str)) { + /* ensure that there's 2 bytes or more remained */ + if (remained < 2) { + return (utf8_int8_t *)str; + } + + /* ensure the 1 following byte in this 2-byte + * utf8 codepoint began with 0b10xxxxxx */ + if (0x80 != (0xc0 & str[1])) { + return (utf8_int8_t *)str; + } + + /* ensure that our utf8 codepoint ended after 2 bytes */ + if (0x80 == (0xc0 & str[2])) { + return (utf8_int8_t *)str; + } + + /* ensure that the top 4 bits of this 2-byte utf8 + * codepoint were not 0, as then we could have used + * one of the smaller encodings */ + if (0 == (0x1e & str[0])) { + return (utf8_int8_t *)str; + } + + /* 2-byte utf8 code point (began with 0b110xxxxx) */ + str += 2; + } else if (0x00 == (0x80 & *str)) { + /* 1-byte ascii (began with 0b0xxxxxxx) */ + str += 1; + } else { + /* we have an invalid 0b1xxxxxxx utf8 code point entry */ + return (utf8_int8_t *)str; + } } - } - return utf8_null; + return utf8_null; } int utf8makevalid(utf8_int8_t *str, const utf8_int32_t replacement) { - utf8_int8_t *read = str; - utf8_int8_t *write = read; - const utf8_int8_t r = (utf8_int8_t)replacement; - utf8_int32_t codepoint = 0; - - if (replacement > 0x7f) { - return -1; - } - - while ('\0' != *read) { - if (0xf0 == (0xf8 & *read)) { - // ensure each of the 3 following bytes in this 4-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2])) || - (0x80 != (0xc0 & read[3]))) { - *write++ = r; - read++; - continue; - } - - // 4-byte utf8 code point (began with 0b11110xxx) - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 4); - } else if (0xe0 == (0xf0 & *read)) { - // ensure each of the 2 following bytes in this 3-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2]))) { - *write++ = r; - read++; - continue; - } - - // 3-byte utf8 code point (began with 0b1110xxxx) - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 3); - } else if (0xc0 == (0xe0 & *read)) { - // ensure the 1 following byte in this 2-byte - // utf8 codepoint began with 0b10xxxxxx - if (0x80 != (0xc0 & read[1])) { - *write++ = r; - read++; - continue; - } - - // 2-byte utf8 code point (began with 0b110xxxxx) - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 2); - } else if (0x00 == (0x80 & *read)) { - // 1-byte ascii (began with 0b0xxxxxxx) - read = utf8codepoint(read, &codepoint); - write = utf8catcodepoint(write, codepoint, 1); - } else { - // if we got here then we've got a dangling continuation (0b10xxxxxx) - *write++ = r; - read++; - continue; - } - } +utf8_int8_t *read = str; +utf8_int8_t *write = read; +const utf8_int8_t r = (utf8_int8_t)replacement; +utf8_int32_t codepoint = 0; + +if (replacement > 0x7f) { +return -1; +} + +while ('\0' != *read) { +if (0xf0 == (0xf8 & *read)) { +/* ensure each of the 3 following bytes in this 4-byte + * utf8 codepoint began with 0b10xxxxxx */ +if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2])) || +(0x80 != (0xc0 & read[3]))) { +*write++ = r; +read++; +continue; +} + +/* 4-byte utf8 code point (began with 0b11110xxx) */ +read = utf8codepoint(read, &codepoint); +write = utf8catcodepoint(write, codepoint, 4); +} else if (0xe0 == (0xf0 & *read)) { +/* ensure each of the 2 following bytes in this 3-byte + * utf8 codepoint began with 0b10xxxxxx */ +if ((0x80 != (0xc0 & read[1])) || (0x80 != (0xc0 & read[2]))) { +*write++ = r; +read++; +continue; +} + +/* 3-byte utf8 code point (began with 0b1110xxxx) */ +read = utf8codepoint(read, &codepoint); +write = utf8catcodepoint(write, codepoint, 3); +} else if (0xc0 == (0xe0 & *read)) { +/* ensure the 1 following byte in this 2-byte + * utf8 codepoint began with 0b10xxxxxx */ +if (0x80 != (0xc0 & read[1])) { +*write++ = r; +read++; +continue; +} - *write = '\0'; +/* 2-byte utf8 code point (began with 0b110xxxxx) */ +read = utf8codepoint(read, &codepoint); +write = utf8catcodepoint(write, codepoint, 2); +} else if (0x00 == (0x80 & *read)) { +/* 1-byte ascii (began with 0b0xxxxxxx) */ +read = utf8codepoint(read, &codepoint); +write = utf8catcodepoint(write, codepoint, 1); +} else { +/* if we got here then we've got a dangling continuation (0b10xxxxxx) */ +*write++ = r; +read++; +continue; +} +} + +*write = '\0'; - return 0; +return 0; } utf8_constexpr14_impl utf8_int8_t * utf8codepoint(const utf8_int8_t *utf8_restrict str, utf8_int32_t *utf8_restrict out_codepoint) { - if (0xf0 == (0xf8 & str[0])) { - // 4 byte utf8 codepoint - *out_codepoint = ((0x07 & str[0]) << 18) | ((0x3f & str[1]) << 12) | - ((0x3f & str[2]) << 6) | (0x3f & str[3]); - str += 4; - } else if (0xe0 == (0xf0 & str[0])) { - // 3 byte utf8 codepoint - *out_codepoint = - ((0x0f & str[0]) << 12) | ((0x3f & str[1]) << 6) | (0x3f & str[2]); - str += 3; - } else if (0xc0 == (0xe0 & str[0])) { - // 2 byte utf8 codepoint - *out_codepoint = ((0x1f & str[0]) << 6) | (0x3f & str[1]); - str += 2; - } else { - // 1 byte utf8 codepoint otherwise - *out_codepoint = str[0]; - str += 1; - } - - return (utf8_int8_t *)str; + if (0xf0 == (0xf8 & str[0])) { + /* 4 byte utf8 codepoint */ + *out_codepoint = ((0x07 & str[0]) << 18) | ((0x3f & str[1]) << 12) | + ((0x3f & str[2]) << 6) | (0x3f & str[3]); + str += 4; + } else if (0xe0 == (0xf0 & str[0])) { + /* 3 byte utf8 codepoint */ + *out_codepoint = + ((0x0f & str[0]) << 12) | ((0x3f & str[1]) << 6) | (0x3f & str[2]); + str += 3; + } else if (0xc0 == (0xe0 & str[0])) { + /* 2 byte utf8 codepoint */ + *out_codepoint = ((0x1f & str[0]) << 6) | (0x3f & str[1]); + str += 2; + } else { + /* 1 byte utf8 codepoint otherwise */ + *out_codepoint = str[0]; + str += 1; + } + + return (utf8_int8_t *)str; } utf8_constexpr14_impl size_t utf8codepointcalcsize(const utf8_int8_t *str) { - if (0xf0 == (0xf8 & str[0])) { - // 4 byte utf8 codepoint - return 4; - } else if (0xe0 == (0xf0 & str[0])) { - // 3 byte utf8 codepoint - return 3; - } else if (0xc0 == (0xe0 & str[0])) { - // 2 byte utf8 codepoint - return 2; - } + if (0xf0 == (0xf8 & str[0])) { + /* 4 byte utf8 codepoint */ + return 4; + } else if (0xe0 == (0xf0 & str[0])) { + /* 3 byte utf8 codepoint */ + return 3; + } else if (0xc0 == (0xe0 & str[0])) { + /* 2 byte utf8 codepoint */ + return 2; + } - // 1 byte utf8 codepoint otherwise - return 1; + /* 1 byte utf8 codepoint otherwise */ + return 1; } utf8_constexpr14_impl size_t utf8codepointsize(utf8_int32_t chr) { - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - return 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - return 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - return 3; - } else { // if (0 == ((int)0xffe00000 & chr)) { - return 4; - } + if (0 == ((utf8_int32_t)0xffffff80 & chr)) { + return 1; + } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { + return 2; + } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { + return 3; + } else { /* if (0 == ((int)0xffe00000 & chr)) { */ + return 4; + } } utf8_int8_t *utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n) { - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - if (n < 1) { - return utf8_null; - } - str[0] = (utf8_int8_t)chr; - str += 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - if (n < 2) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - if (n < 3) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 3; - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - if (n < 4) { - return utf8_null; - } - str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); - str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); - str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); - str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); - str += 4; - } +if (0 == ((utf8_int32_t)0xffffff80 & chr)) { +/* 1-byte/7-bit ascii + * (0b0xxxxxxx) */ +if (n < 1) { +return utf8_null; +} +str[0] = (utf8_int8_t)chr; +str += 1; +} else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { +/* 2-byte/11-bit utf8 code point + * (0b110xxxxx 0b10xxxxxx) */ +if (n < 2) { +return utf8_null; +} +str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); +str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); +str += 2; +} else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { +/* 3-byte/16-bit utf8 code point + * (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) */ +if (n < 3) { +return utf8_null; +} +str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); +str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); +str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); +str += 3; +} else { /* if (0 == ((int)0xffe00000 & chr)) { */ +/* 4-byte/21-bit utf8 code point + * (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) */ +if (n < 4) { +return utf8_null; +} +str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); +str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); +str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); +str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); +str += 4; +} - return str; +return str; } utf8_constexpr14_impl int utf8islower(utf8_int32_t chr) { - return chr != utf8uprcodepoint(chr); + return chr != utf8uprcodepoint(chr); } utf8_constexpr14_impl int utf8isupper(utf8_int32_t chr) { - return chr != utf8lwrcodepoint(chr); + return chr != utf8lwrcodepoint(chr); } void utf8lwr(utf8_int8_t *utf8_restrict str) { - utf8_int32_t cp = 0; - utf8_int8_t *pn = utf8codepoint(str, &cp); +utf8_int32_t cp = 0; +utf8_int8_t *pn = utf8codepoint(str, &cp); - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); +while (cp != 0) { +const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); +const size_t size = utf8codepointsize(lwr_cp); - if (lwr_cp != cp) { - utf8catcodepoint(str, lwr_cp, size); - } +if (lwr_cp != cp) { +utf8catcodepoint(str, lwr_cp, size); +} - str = pn; - pn = utf8codepoint(str, &cp); - } +str = pn; +pn = utf8codepoint(str, &cp); +} } void utf8upr(utf8_int8_t *utf8_restrict str) { - utf8_int32_t cp = 0; - utf8_int8_t *pn = utf8codepoint(str, &cp); +utf8_int32_t cp = 0; +utf8_int8_t *pn = utf8codepoint(str, &cp); - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); +while (cp != 0) { +const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); +const size_t size = utf8codepointsize(lwr_cp); - if (lwr_cp != cp) { - utf8catcodepoint(str, lwr_cp, size); - } +if (lwr_cp != cp) { +utf8catcodepoint(str, lwr_cp, size); +} - str = pn; - pn = utf8codepoint(str, &cp); - } +str = pn; +pn = utf8codepoint(str, &cp); +} } utf8_constexpr14_impl utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp) { - if (((0x0041 <= cp) && (0x005a >= cp)) || - ((0x00c0 <= cp) && (0x00d6 >= cp)) || - ((0x00d8 <= cp) && (0x00de >= cp)) || - ((0x0391 <= cp) && (0x03a1 >= cp)) || - ((0x03a3 <= cp) && (0x03ab >= cp)) || - ((0x0410 <= cp) && (0x042f >= cp))) { - cp += 32; - } else if ((0x0400 <= cp) && (0x040f >= cp)) { - cp += 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { - cp |= 0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp += 1; - cp &= ~0x1; - } else { - switch (cp) { - default: - break; - case 0x0178: - cp = 0x00ff; - break; - case 0x0243: - cp = 0x0180; - break; - case 0x018e: - cp = 0x01dd; - break; - case 0x023d: - cp = 0x019a; - break; - case 0x0220: - cp = 0x019e; - break; - case 0x01b7: - cp = 0x0292; - break; - case 0x01c4: - cp = 0x01c6; - break; - case 0x01c7: - cp = 0x01c9; - break; - case 0x01ca: - cp = 0x01cc; - break; - case 0x01f1: - cp = 0x01f3; - break; - case 0x01f7: - cp = 0x01bf; - break; - case 0x0187: - cp = 0x0188; - break; - case 0x018b: - cp = 0x018c; - break; - case 0x0191: - cp = 0x0192; - break; - case 0x0198: - cp = 0x0199; - break; - case 0x01a7: - cp = 0x01a8; - break; - case 0x01ac: - cp = 0x01ad; - break; - case 0x01af: - cp = 0x01b0; - break; - case 0x01b8: - cp = 0x01b9; - break; - case 0x01bc: - cp = 0x01bd; - break; - case 0x01f4: - cp = 0x01f5; - break; - case 0x023b: - cp = 0x023c; - break; - case 0x0241: - cp = 0x0242; - break; - case 0x03fd: - cp = 0x037b; - break; - case 0x03fe: - cp = 0x037c; - break; - case 0x03ff: - cp = 0x037d; - break; - case 0x037f: - cp = 0x03f3; - break; - case 0x0386: - cp = 0x03ac; - break; - case 0x0388: - cp = 0x03ad; - break; - case 0x0389: - cp = 0x03ae; - break; - case 0x038a: - cp = 0x03af; - break; - case 0x038c: - cp = 0x03cc; - break; - case 0x038e: - cp = 0x03cd; - break; - case 0x038f: - cp = 0x03ce; - break; - case 0x0370: - cp = 0x0371; - break; - case 0x0372: - cp = 0x0373; - break; - case 0x0376: - cp = 0x0377; - break; - case 0x03f4: - cp = 0x03b8; - break; - case 0x03cf: - cp = 0x03d7; - break; - case 0x03f9: - cp = 0x03f2; - break; - case 0x03f7: - cp = 0x03f8; - break; - case 0x03fa: - cp = 0x03fb; - break; + if (((0x0041 <= cp) && (0x005a >= cp)) || + ((0x00c0 <= cp) && (0x00d6 >= cp)) || + ((0x00d8 <= cp) && (0x00de >= cp)) || + ((0x0391 <= cp) && (0x03a1 >= cp)) || + ((0x03a3 <= cp) && (0x03ab >= cp)) || + ((0x0410 <= cp) && (0x042f >= cp))) { + cp += 32; + } else if ((0x0400 <= cp) && (0x040f >= cp)) { + cp += 80; + } else if (((0x0100 <= cp) && (0x012f >= cp)) || + ((0x0132 <= cp) && (0x0137 >= cp)) || + ((0x014a <= cp) && (0x0177 >= cp)) || + ((0x0182 <= cp) && (0x0185 >= cp)) || + ((0x01a0 <= cp) && (0x01a5 >= cp)) || + ((0x01de <= cp) && (0x01ef >= cp)) || + ((0x01f8 <= cp) && (0x021f >= cp)) || + ((0x0222 <= cp) && (0x0233 >= cp)) || + ((0x0246 <= cp) && (0x024f >= cp)) || + ((0x03d8 <= cp) && (0x03ef >= cp)) || + ((0x0460 <= cp) && (0x0481 >= cp)) || + ((0x048a <= cp) && (0x04ff >= cp))) { + cp |= 0x1; + } else if (((0x0139 <= cp) && (0x0148 >= cp)) || + ((0x0179 <= cp) && (0x017e >= cp)) || + ((0x01af <= cp) && (0x01b0 >= cp)) || + ((0x01b3 <= cp) && (0x01b6 >= cp)) || + ((0x01cd <= cp) && (0x01dc >= cp))) { + cp += 1; + cp &= ~0x1; + } else { + switch (cp) { + default: + break; + case 0x0178: + cp = 0x00ff; + break; + case 0x0243: + cp = 0x0180; + break; + case 0x018e: + cp = 0x01dd; + break; + case 0x023d: + cp = 0x019a; + break; + case 0x0220: + cp = 0x019e; + break; + case 0x01b7: + cp = 0x0292; + break; + case 0x01c4: + cp = 0x01c6; + break; + case 0x01c7: + cp = 0x01c9; + break; + case 0x01ca: + cp = 0x01cc; + break; + case 0x01f1: + cp = 0x01f3; + break; + case 0x01f7: + cp = 0x01bf; + break; + case 0x0187: + cp = 0x0188; + break; + case 0x018b: + cp = 0x018c; + break; + case 0x0191: + cp = 0x0192; + break; + case 0x0198: + cp = 0x0199; + break; + case 0x01a7: + cp = 0x01a8; + break; + case 0x01ac: + cp = 0x01ad; + break; + case 0x01af: + cp = 0x01b0; + break; + case 0x01b8: + cp = 0x01b9; + break; + case 0x01bc: + cp = 0x01bd; + break; + case 0x01f4: + cp = 0x01f5; + break; + case 0x023b: + cp = 0x023c; + break; + case 0x0241: + cp = 0x0242; + break; + case 0x03fd: + cp = 0x037b; + break; + case 0x03fe: + cp = 0x037c; + break; + case 0x03ff: + cp = 0x037d; + break; + case 0x037f: + cp = 0x03f3; + break; + case 0x0386: + cp = 0x03ac; + break; + case 0x0388: + cp = 0x03ad; + break; + case 0x0389: + cp = 0x03ae; + break; + case 0x038a: + cp = 0x03af; + break; + case 0x038c: + cp = 0x03cc; + break; + case 0x038e: + cp = 0x03cd; + break; + case 0x038f: + cp = 0x03ce; + break; + case 0x0370: + cp = 0x0371; + break; + case 0x0372: + cp = 0x0373; + break; + case 0x0376: + cp = 0x0377; + break; + case 0x03f4: + cp = 0x03b8; + break; + case 0x03cf: + cp = 0x03d7; + break; + case 0x03f9: + cp = 0x03f2; + break; + case 0x03f7: + cp = 0x03f8; + break; + case 0x03fa: + cp = 0x03fb; + break; + } } - } - return cp; + return cp; } utf8_constexpr14_impl utf8_int32_t utf8uprcodepoint(utf8_int32_t cp) { - if (((0x0061 <= cp) && (0x007a >= cp)) || - ((0x00e0 <= cp) && (0x00f6 >= cp)) || - ((0x00f8 <= cp) && (0x00fe >= cp)) || - ((0x03b1 <= cp) && (0x03c1 >= cp)) || - ((0x03c3 <= cp) && (0x03cb >= cp)) || - ((0x0430 <= cp) && (0x044f >= cp))) { - cp -= 32; - } else if ((0x0450 <= cp) && (0x045f >= cp)) { - cp -= 80; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp)) || - ((0x0460 <= cp) && (0x0481 >= cp)) || - ((0x048a <= cp) && (0x04ff >= cp))) { - cp &= ~0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp -= 1; - cp |= 0x1; - } else { - switch (cp) { - default: - break; - case 0x00ff: - cp = 0x0178; - break; - case 0x0180: - cp = 0x0243; - break; - case 0x01dd: - cp = 0x018e; - break; - case 0x019a: - cp = 0x023d; - break; - case 0x019e: - cp = 0x0220; - break; - case 0x0292: - cp = 0x01b7; - break; - case 0x01c6: - cp = 0x01c4; - break; - case 0x01c9: - cp = 0x01c7; - break; - case 0x01cc: - cp = 0x01ca; - break; - case 0x01f3: - cp = 0x01f1; - break; - case 0x01bf: - cp = 0x01f7; - break; - case 0x0188: - cp = 0x0187; - break; - case 0x018c: - cp = 0x018b; - break; - case 0x0192: - cp = 0x0191; - break; - case 0x0199: - cp = 0x0198; - break; - case 0x01a8: - cp = 0x01a7; - break; - case 0x01ad: - cp = 0x01ac; - break; - case 0x01b0: - cp = 0x01af; - break; - case 0x01b9: - cp = 0x01b8; - break; - case 0x01bd: - cp = 0x01bc; - break; - case 0x01f5: - cp = 0x01f4; - break; - case 0x023c: - cp = 0x023b; - break; - case 0x0242: - cp = 0x0241; - break; - case 0x037b: - cp = 0x03fd; - break; - case 0x037c: - cp = 0x03fe; - break; - case 0x037d: - cp = 0x03ff; - break; - case 0x03f3: - cp = 0x037f; - break; - case 0x03ac: - cp = 0x0386; - break; - case 0x03ad: - cp = 0x0388; - break; - case 0x03ae: - cp = 0x0389; - break; - case 0x03af: - cp = 0x038a; - break; - case 0x03cc: - cp = 0x038c; - break; - case 0x03cd: - cp = 0x038e; - break; - case 0x03ce: - cp = 0x038f; - break; - case 0x0371: - cp = 0x0370; - break; - case 0x0373: - cp = 0x0372; - break; - case 0x0377: - cp = 0x0376; - break; - case 0x03d1: - cp = 0x0398; - break; - case 0x03d7: - cp = 0x03cf; - break; - case 0x03f2: - cp = 0x03f9; - break; - case 0x03f8: - cp = 0x03f7; - break; - case 0x03fb: - cp = 0x03fa; - break; + if (((0x0061 <= cp) && (0x007a >= cp)) || + ((0x00e0 <= cp) && (0x00f6 >= cp)) || + ((0x00f8 <= cp) && (0x00fe >= cp)) || + ((0x03b1 <= cp) && (0x03c1 >= cp)) || + ((0x03c3 <= cp) && (0x03cb >= cp)) || + ((0x0430 <= cp) && (0x044f >= cp))) { + cp -= 32; + } else if ((0x0450 <= cp) && (0x045f >= cp)) { + cp -= 80; + } else if (((0x0100 <= cp) && (0x012f >= cp)) || + ((0x0132 <= cp) && (0x0137 >= cp)) || + ((0x014a <= cp) && (0x0177 >= cp)) || + ((0x0182 <= cp) && (0x0185 >= cp)) || + ((0x01a0 <= cp) && (0x01a5 >= cp)) || + ((0x01de <= cp) && (0x01ef >= cp)) || + ((0x01f8 <= cp) && (0x021f >= cp)) || + ((0x0222 <= cp) && (0x0233 >= cp)) || + ((0x0246 <= cp) && (0x024f >= cp)) || + ((0x03d8 <= cp) && (0x03ef >= cp)) || + ((0x0460 <= cp) && (0x0481 >= cp)) || + ((0x048a <= cp) && (0x04ff >= cp))) { + cp &= ~0x1; + } else if (((0x0139 <= cp) && (0x0148 >= cp)) || + ((0x0179 <= cp) && (0x017e >= cp)) || + ((0x01af <= cp) && (0x01b0 >= cp)) || + ((0x01b3 <= cp) && (0x01b6 >= cp)) || + ((0x01cd <= cp) && (0x01dc >= cp))) { + cp -= 1; + cp |= 0x1; + } else { + switch (cp) { + default: + break; + case 0x00ff: + cp = 0x0178; + break; + case 0x0180: + cp = 0x0243; + break; + case 0x01dd: + cp = 0x018e; + break; + case 0x019a: + cp = 0x023d; + break; + case 0x019e: + cp = 0x0220; + break; + case 0x0292: + cp = 0x01b7; + break; + case 0x01c6: + cp = 0x01c4; + break; + case 0x01c9: + cp = 0x01c7; + break; + case 0x01cc: + cp = 0x01ca; + break; + case 0x01f3: + cp = 0x01f1; + break; + case 0x01bf: + cp = 0x01f7; + break; + case 0x0188: + cp = 0x0187; + break; + case 0x018c: + cp = 0x018b; + break; + case 0x0192: + cp = 0x0191; + break; + case 0x0199: + cp = 0x0198; + break; + case 0x01a8: + cp = 0x01a7; + break; + case 0x01ad: + cp = 0x01ac; + break; + case 0x01b0: + cp = 0x01af; + break; + case 0x01b9: + cp = 0x01b8; + break; + case 0x01bd: + cp = 0x01bc; + break; + case 0x01f5: + cp = 0x01f4; + break; + case 0x023c: + cp = 0x023b; + break; + case 0x0242: + cp = 0x0241; + break; + case 0x037b: + cp = 0x03fd; + break; + case 0x037c: + cp = 0x03fe; + break; + case 0x037d: + cp = 0x03ff; + break; + case 0x03f3: + cp = 0x037f; + break; + case 0x03ac: + cp = 0x0386; + break; + case 0x03ad: + cp = 0x0388; + break; + case 0x03ae: + cp = 0x0389; + break; + case 0x03af: + cp = 0x038a; + break; + case 0x03cc: + cp = 0x038c; + break; + case 0x03cd: + cp = 0x038e; + break; + case 0x03ce: + cp = 0x038f; + break; + case 0x0371: + cp = 0x0370; + break; + case 0x0373: + cp = 0x0372; + break; + case 0x0377: + cp = 0x0376; + break; + case 0x03d1: + cp = 0x0398; + break; + case 0x03d7: + cp = 0x03cf; + break; + case 0x03f2: + cp = 0x03f9; + break; + case 0x03f8: + cp = 0x03f7; + break; + case 0x03fb: + cp = 0x03fa; + break; + } } - } - return cp; + return cp; } utf8_constexpr14_impl utf8_int8_t * utf8rcodepoint(const utf8_int8_t *utf8_restrict str, utf8_int32_t *utf8_restrict out_codepoint) { - const utf8_int8_t *s = (const utf8_int8_t *)str; - - if (0xf0 == (0xf8 & s[0])) { - // 4 byte utf8 codepoint - *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | - ((0x3f & s[2]) << 6) | (0x3f & s[3]); - } else if (0xe0 == (0xf0 & s[0])) { - // 3 byte utf8 codepoint - *out_codepoint = - ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); - } else if (0xc0 == (0xe0 & s[0])) { - // 2 byte utf8 codepoint - *out_codepoint = ((0x1f & s[0]) << 6) | (0x3f & s[1]); - } else { - // 1 byte utf8 codepoint otherwise - *out_codepoint = s[0]; - } - - do { - s--; - } while ((0 != (0x80 & s[0])) && (0x80 == (0xc0 & s[0]))); - - return (utf8_int8_t *)s; + const utf8_int8_t *s = (const utf8_int8_t *)str; + + if (0xf0 == (0xf8 & s[0])) { + /* 4 byte utf8 codepoint */ + *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | + ((0x3f & s[2]) << 6) | (0x3f & s[3]); + } else if (0xe0 == (0xf0 & s[0])) { + /* 3 byte utf8 codepoint */ + *out_codepoint = + ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); + } else if (0xc0 == (0xe0 & s[0])) { + /* 2 byte utf8 codepoint */ + *out_codepoint = ((0x1f & s[0]) << 6) | (0x3f & s[1]); + } else { + /* 1 byte utf8 codepoint otherwise */ + *out_codepoint = s[0]; + } + + do { + s--; + } while ((0 != (0x80 & s[0])) && (0x80 == (0xc0 & s[0]))); + + return (utf8_int8_t *)s; } #undef utf8_restrict @@ -1669,11 +1672,11 @@ utf8rcodepoint(const utf8_int8_t *utf8_restrict str, #undef utf8_null #ifdef __cplusplus -} // extern "C" +} /* extern "C" */ #endif #if defined(__clang__) #pragma clang diagnostic pop #endif -#endif // SHEREDOM_UTF8_H_INCLUDED +#endif /* SHEREDOM_UTF8_H_INCLUDED */ diff --git a/deps/ledger-zxlib/include/view_templates.h b/deps/ledger-zxlib/include/view_templates.h index e653b03..a301b60 100644 --- a/deps/ledger-zxlib/include/view_templates.h +++ b/deps/ledger-zxlib/include/view_templates.h @@ -91,7 +91,7 @@ text, /* text */ \ } -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) #define UI_SCREEN_WIDTH 128 #define UI_SCREEN_HEIGHT 64 diff --git a/deps/ledger-zxlib/include/zxmacros.h b/deps/ledger-zxlib/include/zxmacros.h index 3fd42b1..b5bf7e8 100644 --- a/deps/ledger-zxlib/include/zxmacros.h +++ b/deps/ledger-zxlib/include/zxmacros.h @@ -44,7 +44,7 @@ extern void explicit_bzero(void *s, size_t n) __THROW __nonnull ((1)); #include "bolos_target.h" #endif -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) +#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) #include "zxmacros_ledger.h" #else @@ -84,7 +84,7 @@ void handle_stack_overflow(); void zemu_log_stack(const char *ctx); -#if (defined (TARGET_NANOS) || defined(TARGET_NANOX)) +#if (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)) #if defined(ZEMU_LOGGING) __Z_INLINE void zemu_log(const char *buf) { @@ -104,7 +104,11 @@ __Z_INLINE void zemu_log(__Z_UNUSED const char *msg) { } #endif +#if APP_TESTING #define ZEMU_LOGF(SIZE, ...) { char tmp[(SIZE)]; snprintf(tmp, (SIZE), __VA_ARGS__); zemu_log(tmp); } +#else +#define ZEMU_LOGF(SIZE, ...) {} +#endif #ifdef __cplusplus } diff --git a/deps/ledger-zxlib/include/zxmacros_ledger.h b/deps/ledger-zxlib/include/zxmacros_ledger.h index a48802f..7604b82 100644 --- a/deps/ledger-zxlib/include/zxmacros_ledger.h +++ b/deps/ledger-zxlib/include/zxmacros_ledger.h @@ -15,7 +15,7 @@ ********************************************************************************/ #pragma once -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) +#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) #include "os.h" #include "cx.h" @@ -30,7 +30,7 @@ #define MEMCMP memcmp #define MEMZERO explicit_bzero -#if defined(TARGET_NANOX) +#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) #include "ux.h" #define NV_CONST const #define NV_VOLATILE volatile diff --git a/deps/ledger-zxlib/include/zxmacros_x64.h b/deps/ledger-zxlib/include/zxmacros_x64.h index eea387a..22d27dc 100644 --- a/deps/ledger-zxlib/include/zxmacros_x64.h +++ b/deps/ledger-zxlib/include/zxmacros_x64.h @@ -15,7 +15,7 @@ ********************************************************************************/ #pragma once -#if !defined (TARGET_NANOS) && !defined(TARGET_NANOX) +#if !defined (TARGET_NANOS) && !defined(TARGET_NANOX) && !defined(TARGET_NANOS2) // This macros are kept for backwards compatibility // the most recent SDK has unified implementations and deprecated the original os_*** diff --git a/deps/ledger-zxlib/include/zxversion.h b/deps/ledger-zxlib/include/zxversion.h index 42939db..d3db356 100644 --- a/deps/ledger-zxlib/include/zxversion.h +++ b/deps/ledger-zxlib/include/zxversion.h @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH +* (c) 2018 - 2022 Zondax GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,6 @@ ********************************************************************************/ #pragma once -#define ZXLIB_MAJOR 10 -#define ZXLIB_MINOR 4 -#define ZXLIB_PATCH 3 +#define ZXLIB_MAJOR 12 +#define ZXLIB_MINOR 0 +#define ZXLIB_PATCH 1 diff --git a/deps/ledger-zxlib/src/app_mode.c b/deps/ledger-zxlib/src/app_mode.c index 1f1834b..9d80d02 100644 --- a/deps/ledger-zxlib/src/app_mode.c +++ b/deps/ledger-zxlib/src/app_mode.c @@ -26,7 +26,7 @@ typedef struct { app_mode_temporary_t app_mode_temporary; -#if defined(TARGET_NANOS) || defined(TARGET_NANOX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// diff --git a/deps/ledger-zxlib/src/bignum.c b/deps/ledger-zxlib/src/bignum.c index ec82f4b..442ef70 100644 --- a/deps/ledger-zxlib/src/bignum.c +++ b/deps/ledger-zxlib/src/bignum.c @@ -54,7 +54,7 @@ void bignumLittleEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, const uint8_t *binValue, uint16_t binValueLen) { MEMZERO(bcdOut, bcdOutLen); - uint8_t carry; + uint8_t carry = 0; for (uint16_t bitIdx = 0; bitIdx < binValueLen * 8; bitIdx++) { // Fix bcd for (uint16_t j = 0; j < bcdOutLen; j++) { @@ -120,7 +120,7 @@ void bignumBigEndian_to_bcd(uint8_t *bcdOut, uint16_t bcdOutLen, const uint8_t *binValue, uint16_t binValueLen) { MEMZERO(bcdOut, bcdOutLen); - uint8_t carry; + uint8_t carry = 0; for (uint16_t bitIdx = 0; bitIdx < binValueLen * 8; bitIdx++) { // Fix bcd for (uint16_t j = 0; j < bcdOutLen; j++) { diff --git a/deps/ledger-zxlib/src/zxformat.c b/deps/ledger-zxlib/src/zxformat.c index 6047ab8..ee6d5ce 100644 --- a/deps/ledger-zxlib/src/zxformat.c +++ b/deps/ledger-zxlib/src/zxformat.c @@ -77,7 +77,7 @@ uint8_t intstr_to_fpstr_inplace(char *number, size_t number_max_size, uint8_t de numChars = 1; } else { // Trim leading zeros - MEMCPY(number, number + firstDigit, numChars - firstDigit); + MEMMOVE(number, number + firstDigit, numChars - firstDigit); MEMZERO(number + numChars - firstDigit, firstDigit); } diff --git a/deps/ledger-zxlib/src/zxmacros.c b/deps/ledger-zxlib/src/zxmacros.c index e33475b..5dd172b 100644 --- a/deps/ledger-zxlib/src/zxmacros.c +++ b/deps/ledger-zxlib/src/zxmacros.c @@ -20,7 +20,7 @@ void handle_stack_overflow() { zemu_log("!!!!!!!!!!!!!!!!!!!!!! CANARY TRIGGERED!!! STACK OVERFLOW DETECTED\n"); -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) +#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) io_seproxyhal_se_reset(); #else while (1); @@ -30,12 +30,12 @@ void handle_stack_overflow() { #pragma clang diagnostic pop __Z_UNUSED void check_app_canary() { -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) +#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) if (app_stack_canary != APP_STACK_CANARY_MAGIC) handle_stack_overflow(); #endif } -#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX)) +#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)) void zemu_log_stack(const char *ctx) { #define STACK_SHIFT 20 void* p = NULL; @@ -55,7 +55,7 @@ void zemu_log_stack(__Z_UNUSED const char *ctx) {} #endif -#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX)) +#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)) void zemu_trace(const char *file, uint32_t line) { char buf[200]; snprintf(buf, sizeof(buf), "|TRACE| %s:%d\n", file, line); diff --git a/deps/ledger-zxlib/src/zxutils_ledger.c b/deps/ledger-zxlib/src/zxutils_ledger.c index c57443d..4800665 100644 --- a/deps/ledger-zxlib/src/zxutils_ledger.c +++ b/deps/ledger-zxlib/src/zxutils_ledger.c @@ -1,10 +1,26 @@ +//#******************************************************************************* +//#* (c) 2021 Zondax GmbH +//#* (c) 2020 Ledger SAS +//#* +//#* 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 "zxutils_ledger.h" #ifndef NULL #define NULL ((void *)0) #endif -// We implement a light mecanism in order to be able to retrieve the width of +// We implement a light mechanism in order to be able to retrieve the width of // nano S characters, in the two possible fonts: // - BAGL_FONT_OPEN_SANS_EXTRABOLD_11px, // - BAGL_FONT_OPEN_SANS_REGULAR_11px. @@ -114,7 +130,7 @@ const char nanos_characters_width[96] = { unsigned short zx_compute_line_width_light(const char* text, unsigned char text_length) { char current_char; unsigned short line_width = 0; - + if(text == NULL) { return 0xFFFF; } @@ -135,4 +151,4 @@ unsigned short zx_compute_line_width_light(const char* text, unsigned char text_ text++; } return line_width; -} \ No newline at end of file +} diff --git a/deps/ledger-zxlib/templates/Makefile.root b/deps/ledger-zxlib/templates/Makefile.root index 7c21132..566f607 100644 --- a/deps/ledger-zxlib/templates/Makefile.root +++ b/deps/ledger-zxlib/templates/Makefile.root @@ -14,7 +14,7 @@ #* limitations under the License. #******************************************************************************** -# We use BOLOS_SDK to determine the develoment environment that is being used +# We use BOLOS_SDK to determine the development environment that is being used # BOLOS_SDK IS DEFINED We use the plain Makefile for Ledger # BOLOS_SDK NOT DEFINED We use a containerized build approach diff --git a/deps/ledger-zxlib/tests/doubledabble.cpp b/deps/ledger-zxlib/tests/doubledabble.cpp index c0c3108..4b7b048 100644 --- a/deps/ledger-zxlib/tests/doubledabble.cpp +++ b/deps/ledger-zxlib/tests/doubledabble.cpp @@ -33,7 +33,7 @@ class BignumLittleEndianTests : public ::testing::TestWithParam { }; -INSTANTIATE_TEST_CASE_P +INSTANTIATE_TEST_SUITE_P ( BignumTestCases, BignumLittleEndianTests, testing::Values( @@ -99,7 +99,7 @@ TEST(BignumLittleEndianTests, range) { } } -INSTANTIATE_TEST_CASE_P +INSTANTIATE_TEST_SUITE_P ( BignumTestCases, BignumBigEndianTests, testing::Values( diff --git a/deps/ledger-zxlib/tests/timeutils.cpp b/deps/ledger-zxlib/tests/timeutils.cpp deleted file mode 100644 index 6cf1bfd..0000000 --- a/deps/ledger-zxlib/tests/timeutils.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* -* (c) 2018 Zondax GmbH -* -* 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 -#include -#include - -namespace { - TEST(TIMEUTILS, basic) { - uint64_t t = 1104937465; - char output[50]; - - zxerr_t err = printTime(output, sizeof(output), t); - - EXPECT_EQ(err, zxerr_ok); - EXPECT_STREQ(output, "05Jan2005 15:04:25UTC"); - } - - TEST(TIMEUTILS, yearlookup) { - struct tm t = {0}; // Initalize to all 0's - for (uint64_t year = 70; year < 470; year++) { - t.tm_year = year; // This is year-1900, so 112 = 2012 - t.tm_mon = 0; - t.tm_mday = 1; - t.tm_hour = 0; - t.tm_min = 0; - t.tm_sec = 0; - setenv("TZ", "UTC", 1); - time_t timeSinceEpoch = mktime(&t); - - const uint32_t day = 60*60*24; - uint64_t daysSinceStart = timeSinceEpoch / day; - - std::cout << " " << daysSinceStart << ", " << std::endl; - } - } - - TEST(TIMEUTILS, loop) { - char output[50]; - char expected_output[50]; - - for (uint64_t t = 0; t < 8640000000; t += 1234567) { - zxerr_t err = printTime(output, sizeof(output), t); - EXPECT_EQ(err, zxerr_ok); - time_t tmp = t; - auto expected = gmtime(&tmp); - snprintf(expected_output, sizeof(expected_output), "%02d%s%d %02d:%02d:%02dUTC", - expected->tm_mday, - getMonth(expected->tm_mon + 1), - expected->tm_year + 1900, - expected->tm_hour, - expected->tm_min, - expected->tm_sec - ); - - std::cout << t << " " << output << " " << expected_output << std::endl; - - EXPECT_STREQ(output, expected_output); - } - } - - TEST(TIMEUTILS, zero) { - uint64_t t = 0; - char output[50]; - - zxerr_t err = printTime(output, sizeof(output), t); - - EXPECT_EQ(err, zxerr_ok); - EXPECT_STREQ(output, "01Jan1970 00:00:00UTC"); - } - - TEST(TIMEUTILS, huge) { - uint64_t t = 86400ULL * 365ULL * 5000ULL; - char output[50]; - - zxerr_t err = printTime(output, sizeof(output), t); - - EXPECT_EQ(err, zxerr_out_of_bounds); - } -} diff --git a/deps/nanosplus-secure-sdk b/deps/nanosplus-secure-sdk new file mode 160000 index 0000000..dd4684c --- /dev/null +++ b/deps/nanosplus-secure-sdk @@ -0,0 +1 @@ +Subproject commit dd4684c36592ddbdfc1df78e045d93376beaba96 diff --git a/deps/nanox-secure-sdk b/deps/nanox-secure-sdk index cffd222..ba45af7 160000 --- a/deps/nanox-secure-sdk +++ b/deps/nanox-secure-sdk @@ -1 +1 @@ -Subproject commit cffd222a689da246cb0fab5c954d3afd7f419b4b +Subproject commit ba45af7f4208b6c02ac35fb0d43a914228febd56 diff --git a/tests_zemu/package.json b/tests_zemu/package.json index cc13f72..1d8c0a5 100644 --- a/tests_zemu/package.json +++ b/tests_zemu/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@zondax/ledger-substrate": "^0.24.0", - "@zondax/zemu": "^0.21.1" + "@zondax/zemu": "^0.27.0-rc2" }, "devDependencies": { "@types/jest": "^27.0.1", diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index df66b28..f847b1f 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00004.png and b/tests_zemu/snapshots/s-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00008.png b/tests_zemu/snapshots/s-mainmenu/00008.png index a4fbbac..5037e62 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00008.png and b/tests_zemu/snapshots/s-mainmenu/00008.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00009.png b/tests_zemu/snapshots/s-mainmenu/00009.png index 5037e62..f74c385 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00009.png and b/tests_zemu/snapshots/s-mainmenu/00009.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00010.png b/tests_zemu/snapshots/s-mainmenu/00010.png index f74c385..f847b1f 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00010.png and b/tests_zemu/snapshots/s-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00011.png b/tests_zemu/snapshots/s-mainmenu/00011.png index df66b28..fd230fc 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00011.png and b/tests_zemu/snapshots/s-mainmenu/00011.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00012.png b/tests_zemu/snapshots/s-mainmenu/00012.png index fd230fc..9109821 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00012.png and b/tests_zemu/snapshots/s-mainmenu/00012.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00013.png b/tests_zemu/snapshots/s-mainmenu/00013.png deleted file mode 100644 index 9109821..0000000 Binary files a/tests_zemu/snapshots/s-mainmenu/00013.png and /dev/null differ diff --git a/tests_zemu/snapshots/x-mainmenu/00013.png b/tests_zemu/snapshots/sp-mainmenu/00000.png similarity index 100% rename from tests_zemu/snapshots/x-mainmenu/00013.png rename to tests_zemu/snapshots/sp-mainmenu/00000.png diff --git a/tests_zemu/snapshots/sp-mainmenu/00001.png b/tests_zemu/snapshots/sp-mainmenu/00001.png new file mode 100644 index 0000000..e10e004 Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00001.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00002.png b/tests_zemu/snapshots/sp-mainmenu/00002.png new file mode 100644 index 0000000..7e236da Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00002.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00003.png b/tests_zemu/snapshots/sp-mainmenu/00003.png new file mode 100644 index 0000000..e10e004 Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00003.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00004.png b/tests_zemu/snapshots/sp-mainmenu/00004.png new file mode 100644 index 0000000..38a88fa Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00005.png b/tests_zemu/snapshots/sp-mainmenu/00005.png new file mode 100644 index 0000000..1adff7e Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00005.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00006.png b/tests_zemu/snapshots/sp-mainmenu/00006.png new file mode 100644 index 0000000..86e715d Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00006.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00007.png b/tests_zemu/snapshots/sp-mainmenu/00007.png new file mode 100644 index 0000000..3922fb6 Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00007.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00008.png b/tests_zemu/snapshots/sp-mainmenu/00008.png new file mode 100644 index 0000000..86e715d Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00008.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00009.png b/tests_zemu/snapshots/sp-mainmenu/00009.png new file mode 100644 index 0000000..1adff7e Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00009.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00010.png b/tests_zemu/snapshots/sp-mainmenu/00010.png new file mode 100644 index 0000000..38a88fa Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00011.png b/tests_zemu/snapshots/sp-mainmenu/00011.png new file mode 100644 index 0000000..e10e004 Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00011.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00012.png b/tests_zemu/snapshots/sp-mainmenu/00012.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-mainmenu/00012.png differ diff --git a/tests_zemu/snapshots/sp-show_address/00000.png b/tests_zemu/snapshots/sp-show_address/00000.png new file mode 100644 index 0000000..4e2fadf Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address/00000.png differ diff --git a/tests_zemu/snapshots/sp-show_address/00001.png b/tests_zemu/snapshots/sp-show_address/00001.png new file mode 100644 index 0000000..5513d0a Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address/00001.png differ diff --git a/tests_zemu/snapshots/sp-show_address/00002.png b/tests_zemu/snapshots/sp-show_address/00002.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address/00002.png differ diff --git a/tests_zemu/snapshots/sp-show_address/00003.png b/tests_zemu/snapshots/sp-show_address/00003.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address/00003.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00000.png b/tests_zemu/snapshots/sp-show_address_reject/00000.png new file mode 100644 index 0000000..4e2fadf Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00000.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00001.png b/tests_zemu/snapshots/sp-show_address_reject/00001.png new file mode 100644 index 0000000..5513d0a Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00001.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00002.png b/tests_zemu/snapshots/sp-show_address_reject/00002.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00002.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00003.png b/tests_zemu/snapshots/sp-show_address_reject/00003.png new file mode 100644 index 0000000..d9b5efc Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00003.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00004.png b/tests_zemu/snapshots/sp-show_address_reject/00004.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00004.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00005.png b/tests_zemu/snapshots/sp-show_address_reject/00005.png new file mode 100644 index 0000000..5513d0a Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00005.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00006.png b/tests_zemu/snapshots/sp-show_address_reject/00006.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00006.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00007.png b/tests_zemu/snapshots/sp-show_address_reject/00007.png new file mode 100644 index 0000000..d9b5efc Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00007.png differ diff --git a/tests_zemu/snapshots/sp-show_address_reject/00008.png b/tests_zemu/snapshots/sp-show_address_reject/00008.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-show_address_reject/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00000.png b/tests_zemu/snapshots/sp-sign_basic_expert/00000.png new file mode 100644 index 0000000..4e2fadf Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00001.png b/tests_zemu/snapshots/sp-sign_basic_expert/00001.png new file mode 100644 index 0000000..dd500bf Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00002.png b/tests_zemu/snapshots/sp-sign_basic_expert/00002.png new file mode 100644 index 0000000..4a8bcee Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00003.png b/tests_zemu/snapshots/sp-sign_basic_expert/00003.png new file mode 100644 index 0000000..f719ffd Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00004.png b/tests_zemu/snapshots/sp-sign_basic_expert/00004.png new file mode 100644 index 0000000..6032428 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00005.png b/tests_zemu/snapshots/sp-sign_basic_expert/00005.png new file mode 100644 index 0000000..5863535 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00006.png b/tests_zemu/snapshots/sp-sign_basic_expert/00006.png new file mode 100644 index 0000000..a780e25 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00007.png b/tests_zemu/snapshots/sp-sign_basic_expert/00007.png new file mode 100644 index 0000000..37c45c0 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00008.png b/tests_zemu/snapshots/sp-sign_basic_expert/00008.png new file mode 100644 index 0000000..4a77269 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00008.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00009.png b/tests_zemu/snapshots/sp-sign_basic_expert/00009.png new file mode 100644 index 0000000..b948888 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00009.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00010.png b/tests_zemu/snapshots/sp-sign_basic_expert/00010.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00010.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_expert/00011.png b/tests_zemu/snapshots/sp-sign_basic_expert/00011.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_expert/00011.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00000.png b/tests_zemu/snapshots/sp-sign_basic_normal/00000.png new file mode 100644 index 0000000..4e2fadf Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00001.png b/tests_zemu/snapshots/sp-sign_basic_normal/00001.png new file mode 100644 index 0000000..dd500bf Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00002.png b/tests_zemu/snapshots/sp-sign_basic_normal/00002.png new file mode 100644 index 0000000..4a8bcee Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00003.png b/tests_zemu/snapshots/sp-sign_basic_normal/00003.png new file mode 100644 index 0000000..f719ffd Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00004.png b/tests_zemu/snapshots/sp-sign_basic_normal/00004.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_basic_normal/00005.png b/tests_zemu/snapshots/sp-sign_basic_normal/00005.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_basic_normal/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00000.png b/tests_zemu/snapshots/sp-sign_large_other/00000.png new file mode 100644 index 0000000..4e2fadf Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00000.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00001.png b/tests_zemu/snapshots/sp-sign_large_other/00001.png new file mode 100644 index 0000000..880ff5c Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00001.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00002.png b/tests_zemu/snapshots/sp-sign_large_other/00002.png new file mode 100644 index 0000000..cbafe76 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00002.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00003.png b/tests_zemu/snapshots/sp-sign_large_other/00003.png new file mode 100644 index 0000000..6f5f67c Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00003.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00004.png b/tests_zemu/snapshots/sp-sign_large_other/00004.png new file mode 100644 index 0000000..0aa0d1d Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00004.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00005.png b/tests_zemu/snapshots/sp-sign_large_other/00005.png new file mode 100644 index 0000000..b63432c Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00005.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00006.png b/tests_zemu/snapshots/sp-sign_large_other/00006.png new file mode 100644 index 0000000..b5e518a Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00006.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00007.png b/tests_zemu/snapshots/sp-sign_large_other/00007.png new file mode 100644 index 0000000..1e4be69 Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00007.png differ diff --git a/tests_zemu/snapshots/sp-sign_large_other/00008.png b/tests_zemu/snapshots/sp-sign_large_other/00008.png new file mode 100644 index 0000000..fded6ad Binary files /dev/null and b/tests_zemu/snapshots/sp-sign_large_other/00008.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00004.png b/tests_zemu/snapshots/x-mainmenu/00004.png index 08e3cad..38a88fa 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00004.png and b/tests_zemu/snapshots/x-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00008.png b/tests_zemu/snapshots/x-mainmenu/00008.png index 3922fb6..86e715d 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00008.png and b/tests_zemu/snapshots/x-mainmenu/00008.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00009.png b/tests_zemu/snapshots/x-mainmenu/00009.png index 86e715d..1adff7e 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00009.png and b/tests_zemu/snapshots/x-mainmenu/00009.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00010.png b/tests_zemu/snapshots/x-mainmenu/00010.png index 1adff7e..38a88fa 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00010.png and b/tests_zemu/snapshots/x-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00011.png b/tests_zemu/snapshots/x-mainmenu/00011.png index 08e3cad..e10e004 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00011.png and b/tests_zemu/snapshots/x-mainmenu/00011.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00012.png b/tests_zemu/snapshots/x-mainmenu/00012.png index e10e004..fded6ad 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00012.png and b/tests_zemu/snapshots/x-mainmenu/00012.png differ diff --git a/tests_zemu/snapshots/x-show_address/00001.png b/tests_zemu/snapshots/x-show_address/00001.png index a9caee6..5513d0a 100644 Binary files a/tests_zemu/snapshots/x-show_address/00001.png and b/tests_zemu/snapshots/x-show_address/00001.png differ diff --git a/tests_zemu/snapshots/x-show_address_reject/00001.png b/tests_zemu/snapshots/x-show_address_reject/00001.png index a9caee6..5513d0a 100644 Binary files a/tests_zemu/snapshots/x-show_address_reject/00001.png and b/tests_zemu/snapshots/x-show_address_reject/00001.png differ diff --git a/tests_zemu/snapshots/x-show_address_reject/00005.png b/tests_zemu/snapshots/x-show_address_reject/00005.png index a9caee6..5513d0a 100644 Binary files a/tests_zemu/snapshots/x-show_address_reject/00005.png and b/tests_zemu/snapshots/x-show_address_reject/00005.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00001.png b/tests_zemu/snapshots/x-sign_basic_expert/00001.png index 3b59abd..dd500bf 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00001.png and b/tests_zemu/snapshots/x-sign_basic_expert/00001.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00002.png b/tests_zemu/snapshots/x-sign_basic_expert/00002.png index 33fca65..4a8bcee 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00002.png and b/tests_zemu/snapshots/x-sign_basic_expert/00002.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00003.png b/tests_zemu/snapshots/x-sign_basic_expert/00003.png index 3eea795..f719ffd 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00003.png and b/tests_zemu/snapshots/x-sign_basic_expert/00003.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00004.png b/tests_zemu/snapshots/x-sign_basic_expert/00004.png index 2b09b0d..6032428 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00004.png and b/tests_zemu/snapshots/x-sign_basic_expert/00004.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00005.png b/tests_zemu/snapshots/x-sign_basic_expert/00005.png index a707eac..5863535 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00005.png and b/tests_zemu/snapshots/x-sign_basic_expert/00005.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00006.png b/tests_zemu/snapshots/x-sign_basic_expert/00006.png index 3be6937..a780e25 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00006.png and b/tests_zemu/snapshots/x-sign_basic_expert/00006.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00007.png b/tests_zemu/snapshots/x-sign_basic_expert/00007.png index 974b458..37c45c0 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00007.png and b/tests_zemu/snapshots/x-sign_basic_expert/00007.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00008.png b/tests_zemu/snapshots/x-sign_basic_expert/00008.png index 62faaf6..4a77269 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00008.png and b/tests_zemu/snapshots/x-sign_basic_expert/00008.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_expert/00009.png b/tests_zemu/snapshots/x-sign_basic_expert/00009.png index 3cee097..b948888 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_expert/00009.png and b/tests_zemu/snapshots/x-sign_basic_expert/00009.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_normal/00001.png b/tests_zemu/snapshots/x-sign_basic_normal/00001.png index 3b59abd..dd500bf 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_normal/00001.png and b/tests_zemu/snapshots/x-sign_basic_normal/00001.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_normal/00002.png b/tests_zemu/snapshots/x-sign_basic_normal/00002.png index 33fca65..4a8bcee 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_normal/00002.png and b/tests_zemu/snapshots/x-sign_basic_normal/00002.png differ diff --git a/tests_zemu/snapshots/x-sign_basic_normal/00003.png b/tests_zemu/snapshots/x-sign_basic_normal/00003.png index 3eea795..f719ffd 100644 Binary files a/tests_zemu/snapshots/x-sign_basic_normal/00003.png and b/tests_zemu/snapshots/x-sign_basic_normal/00003.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00001.png b/tests_zemu/snapshots/x-sign_large_other/00001.png index b9173af..880ff5c 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00001.png and b/tests_zemu/snapshots/x-sign_large_other/00001.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00002.png b/tests_zemu/snapshots/x-sign_large_other/00002.png index 56f40a8..cbafe76 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00002.png and b/tests_zemu/snapshots/x-sign_large_other/00002.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00003.png b/tests_zemu/snapshots/x-sign_large_other/00003.png index eb91631..6f5f67c 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00003.png and b/tests_zemu/snapshots/x-sign_large_other/00003.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00004.png b/tests_zemu/snapshots/x-sign_large_other/00004.png index 9c55f0c..0aa0d1d 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00004.png and b/tests_zemu/snapshots/x-sign_large_other/00004.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00005.png b/tests_zemu/snapshots/x-sign_large_other/00005.png index cce999d..b63432c 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00005.png and b/tests_zemu/snapshots/x-sign_large_other/00005.png differ diff --git a/tests_zemu/snapshots/x-sign_large_other/00006.png b/tests_zemu/snapshots/x-sign_large_other/00006.png index 1ba51ee..b5e518a 100644 Binary files a/tests_zemu/snapshots/x-sign_large_other/00006.png and b/tests_zemu/snapshots/x-sign_large_other/00006.png differ diff --git a/tests_zemu/tests/common.ts b/tests_zemu/tests/common.ts index 1ffcdb4..60eb396 100644 --- a/tests_zemu/tests/common.ts +++ b/tests_zemu/tests/common.ts @@ -6,10 +6,12 @@ export const APP_SEED = 'equip will roof matter pink blind book anxiety banner e const APP_PATH_S = Resolve('../app/output/app_s.elf') const APP_PATH_X = Resolve('../app/output/app_x.elf') +const APP_PATH_SP = Resolve('../app/output/app_s2.elf') export const models: DeviceModel[] = [ { name: 'nanos', prefix: 'S', path: APP_PATH_S }, { name: 'nanox', prefix: 'X', path: APP_PATH_X }, + { name: 'nanosp', prefix: 'SP', path: APP_PATH_SP }, ] export const txBasic = diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index fbb3012..79b7ae5 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -50,7 +50,7 @@ describe('Standard', function () { const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) - await sim.navigateAndCompareSnapshots('.', `${m.prefix.toLowerCase()}-mainmenu`, [1, 0, 0, 5, -5]) + await sim.navigateAndCompareSnapshots('.', `${m.prefix.toLowerCase()}-mainmenu`, [1, 0, 0, 4, -5]) } finally { await sim.close() }