Move more functions to utils

This commit is contained in:
Clément Péron
2019-01-04 10:48:57 +01:00
parent 334372c12f
commit 1ad2170560
3 changed files with 60 additions and 45 deletions

View File

@@ -953,17 +953,6 @@ const bagl_element_t ui_data_parameter_blue[] = {
{{BAGL_RECTANGLE | BAGL_FLAG_TOUCHABLE, 0x00, 165, 414, 115, 36, 0,18, BAGL_FILL, 0x41ccb4, COLOR_BG_1, BAGL_FONT_OPEN_SANS_REGULAR_11_14PX|BAGL_FONT_ALIGNMENT_CENTER|BAGL_FONT_ALIGNMENT_MIDDLE, 0 }, "CONFIRM", 0, 0x3ab7a2, COLOR_BG_1, io_seproxyhal_touch_data_ok, NULL, NULL},
};
int local_strchr(char *string, char ch) {
unsigned int length = strlen(string);
unsigned int i;
for (i=0; i<length; i++) {
if (string[i] == ch) {
return i;
}
}
return -1;
}
unsigned int ui_data_parameter_blue_prepro(const bagl_element_t* element) {
copy_element_and_map_coin_colors(element);
if(element->component.userid > 0) {
@@ -1096,33 +1085,6 @@ unsigned int ui_address_nanos_button(unsigned int button_mask, unsigned int butt
}
#endif // #if defined(TARGET_NANOS)
uint32_t getV(txContent_t *txContent) {
uint32_t v = 0;
if (txContent->vLength == 1) {
v = txContent->v[0];
}
else
if (txContent->vLength == 2) {
v = (txContent->v[0] << 8) | txContent->v[1];
}
else
if (txContent->vLength == 3) {
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
}
else
if (txContent->vLength == 4) {
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) |
(txContent->v[2] << 8) | txContent->v[3];
}
else
if (txContent->vLength != 0) {
PRINTF("Unexpected v format\n");
THROW(EXCEPTION);
}
return v;
}
void io_seproxyhal_send_status(uint32_t sw) {
G_io_apdu_buffer[0] = ((sw >> 8) & 0xff);
G_io_apdu_buffer[1] = (sw & 0xff);
@@ -1411,13 +1373,6 @@ uint32_t set_result_get_publicKey() {
return tx;
}
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
uint8_t tmp[32];
os_memset(tmp, 0, 32);
os_memmove(tmp + 32 - length, data, length);
readu256BE(tmp, target);
}
uint32_t splitBinaryParameterPart(char *result, uint8_t *parameter) {
uint32_t i;
for (i=0; i<8; i++) {

View File

@@ -15,6 +15,12 @@
* limitations under the License.
********************************************************************************/
#include <stdint.h>
#include <string.h>
#include "ethUstream.h"
#include "uint256.h"
static const unsigned char hex_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
@@ -25,4 +31,48 @@ void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
bin = (const void *)((unsigned int)bin + 1);
}
*strbuf = 0; // EOS
}
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
uint8_t tmp[32];
os_memset(tmp, 0, 32);
os_memmove(tmp + 32 - length, data, length);
readu256BE(tmp, target);
}
int local_strchr(char *string, char ch) {
unsigned int length = strlen(string);
unsigned int i;
for (i=0; i<length; i++) {
if (string[i] == ch) {
return i;
}
}
return -1;
}
uint32_t getV(txContent_t *txContent) {
uint32_t v = 0;
if (txContent->vLength == 1) {
v = txContent->v[0];
}
else
if (txContent->vLength == 2) {
v = (txContent->v[0] << 8) | txContent->v[1];
}
else
if (txContent->vLength == 3) {
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
}
else
if (txContent->vLength == 4) {
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) |
(txContent->v[2] << 8) | txContent->v[3];
}
else
if (txContent->vLength != 0) {
PRINTF("Unexpected v format\n");
THROW(EXCEPTION);
}
return v;
}

View File

@@ -18,6 +18,16 @@
#ifndef _UTILS_H_
#define _UTILS_H_
#include <stdint.h>
#include "uint256.h"
void array_hexstr(char *strbuf, const void *bin, unsigned int len);
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target);
int local_strchr(char *string, char ch);
uint32_t getV(txContent_t *txContent);
#endif /* _UTILS_H_ */