Merge pull request #361 from LedgerHQ/improv-dev-experience
Add helpers to avoid tricking user when using a plugin
This commit is contained in:
@@ -134,6 +134,17 @@ The following return codes are expected, any other will abort the signing proces
|
||||
* ETH_PLUGIN_RESULT_OK : if the plugin can be successfully initialized
|
||||
* ETH_PLUGIN_RESULT_FALLBACK : if the signing logic should fallback to the generic one
|
||||
|
||||
There are already defined functions to extract data from a parameter:
|
||||
[source,C]
|
||||
----
|
||||
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
|
||||
// Get the value from the beginning of the parameter (right to left) and check if the rest of it is zero
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value);
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value);
|
||||
----
|
||||
|
||||
### ETH_PLUGIN_FINALIZE
|
||||
|
||||
[source,C]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "ethUtils.h" // allzeroes
|
||||
|
||||
bool erc20_plugin_available_check(void);
|
||||
|
||||
@@ -15,6 +16,24 @@ void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
|
||||
memmove(dst, parameter, copy_size);
|
||||
}
|
||||
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint16_t))) {
|
||||
*value = U2BE(parameter, PARAMETER_LENGTH - sizeof(uint16_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint32_t))) {
|
||||
*value = U4BE(parameter, PARAMETER_LENGTH - sizeof(uint32_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
void starkware_plugin_call(int message, void* parameters);
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,11 @@ void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
void erc721_plugin_call(int message, void* parameters);
|
||||
void erc1155_plugin_call(int message, void* parameters);
|
||||
|
||||
// Get the value from the beginning of the parameter (right to left) and check if the rest of it is
|
||||
// zero
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value);
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value);
|
||||
|
||||
typedef bool (*PluginAvailableCheck)(void);
|
||||
|
||||
typedef struct internalEthPlugin_t {
|
||||
|
||||
@@ -66,7 +66,7 @@ bool adjustDecimals(const char *src,
|
||||
size_t targetLength,
|
||||
uint8_t decimals);
|
||||
|
||||
static __attribute__((no_instrument_function)) inline int allzeroes(void *buf, size_t n) {
|
||||
static __attribute__((no_instrument_function)) inline int allzeroes(const void *buf, size_t n) {
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (p[i]) {
|
||||
|
||||
@@ -164,7 +164,7 @@ if __name__ == "__main__":
|
||||
"typedef union": ["extraInfo_t"],
|
||||
"__attribute__((no_instrument_function)) inline": ["int allzeroes"],
|
||||
"const": ["HEXDIGITS"],
|
||||
"fn": ["void getEthAddressStringFromBinary", "void getEthAddressFromKey", "void getEthDisplayableAddress", "bool adjustDecimals", "bool uint256_to_decimal", "void amountToString", "void u64_to_string", "void copy_address", "void copy_parameter"]
|
||||
"fn": ["void getEthAddressStringFromBinary", "void getEthAddressFromKey", "void getEthDisplayableAddress", "bool adjustDecimals", "bool uint256_to_decimal", "void amountToString", "void u64_to_string", "void copy_address", "void copy_parameter", "bool U2BE_from_parameter", "bool U4BE_from_parameter"]
|
||||
}
|
||||
merge_headers(headers_to_merge, nodes_to_extract)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user