1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

update layouts for message operations

This commit is contained in:
Pavol Rusnak 2014-11-26 18:52:30 +01:00
parent f75515544f
commit 0c050e7fca
2 changed files with 34 additions and 78 deletions

View File

@ -149,20 +149,20 @@ void layoutFeeOverThreshold(const CoinType *coin, uint64_t fee, uint32_t kb)
);
}
void layoutSignMessage(const uint8_t *msg, uint32_t len)
// split longer message into 4 rows, 16 chars each
const char **prepare_message(const uint8_t *msg, uint32_t len)
{
bool ascii = true;
bool binary = false;
uint32_t i;
for (i = 0; i < len; i++) {
if (msg[i] < 0x20 || msg[i] >= 0x80) {
ascii = false;
if (msg[i] < 0x20) {
binary = true;
break;
}
}
char str[4][17];
static char str[4][17];
memset(str, 0, sizeof(str));
if (ascii) {
if (!binary) {
strlcpy(str[0], (char *)msg, 17);
if (len > 16) {
strlcpy(str[1], (char *)msg + 16, 17);
@ -185,74 +185,50 @@ void layoutSignMessage(const uint8_t *msg, uint32_t len)
data2hex(msg + 24, len > 32 ? 8 : len - 24, str[3]);
}
}
static const char *ret[4] = { str[0], str[1], str[2], str[3] };
return ret;
}
void layoutSignMessage(const uint8_t *msg, uint32_t len)
{
const char **str = prepare_message(msg, len);
layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm",
ascii ? "Sign text message?" : "Sign binary message?",
"Sign message?",
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutVerifyMessage(const uint8_t *msg, uint32_t len)
{
bool ascii = true;
uint32_t i;
for (i = 0; i < len; i++) {
if (msg[i] < 0x20 || msg[i] >= 0x80) {
ascii = false;
break;
}
}
char str[4][17];
memset(str, 0, sizeof(str));
if (ascii) {
strlcpy(str[0], (char *)msg, 17);
if (len > 16) {
strlcpy(str[1], (char *)msg + 16, 17);
}
if (len > 32) {
strlcpy(str[2], (char *)msg + 32, 17);
}
if (len > 48) {
strlcpy(str[3], (char *)msg + 48, 17);
}
} else {
data2hex(msg, len > 8 ? 8 : len, str[0]);
if (len > 8) {
data2hex(msg + 8, len > 16 ? 8 : len - 8, str[1]);
}
if (len > 16) {
data2hex(msg + 16, len > 24 ? 8 : len - 16, str[2]);
}
if (len > 24) {
data2hex(msg + 24, len > 32 ? 8 : len - 24, str[3]);
}
}
const char **str = prepare_message(msg, len);
layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "OK",
ascii ? "Message contents" : "Binary message contents",
"Verified message",
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutCipherKeyValue(bool encrypt, const char *key)
{
int len = strlen(key);
char str[4][17];
memset(str, 0, sizeof(str));
strlcpy(str[0], (char *)key, 17);
if (len > 16) {
strlcpy(str[1], (char *)key + 16, 17);
}
if (len > 32) {
strlcpy(str[2], (char *)key + 32, 17);
}
if (len > 48) {
strlcpy(str[3], (char *)key + 48, 17);
}
const char **str = prepare_message((const uint8_t *)key, strlen(key));
layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm",
encrypt ? "Encrypt?" : "Decrypt?",
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing)
{
const char **str = prepare_message(msg, len);
layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm",
signing ? "Encrypt+Sign message?" : "Encrypt message?",
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
{
const char **str = prepare_message(msg, len);
layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "OK",
address ? "Decrypted signed message" : "Decrypted message",
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutAddress(const char *address)
{
oledSwipeLeft();
@ -304,23 +280,3 @@ void layoutAddress(const char *address)
oledRefresh();
}
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing)
{
// TODO: finish
(void)msg;
(void)len;
layoutDialogSwipe(DIALOG_ICON_QUESTION, "Cancel", "Confirm",
signing ? "Encrypt message?" : "Encrypt+sign message?",
NULL, NULL, NULL, NULL, NULL, NULL);
}
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address)
{
// TODO: finish
(void)msg;
(void)len;
layoutDialogSwipe(DIALOG_ICON_INFO, NULL, "OK",
address ? "Signed message contents" : "Message contents",
NULL, NULL, NULL, NULL, NULL, NULL);
}

View File

@ -33,8 +33,8 @@ void layoutFeeOverThreshold(const CoinType *coin, uint64_t fee, uint32_t kb);
void layoutSignMessage(const uint8_t *msg, uint32_t len);
void layoutVerifyMessage(const uint8_t *msg, uint32_t len);
void layoutCipherKeyValue(bool encrypt, const char *key);
void layoutAddress(const char *address);
void layoutEncryptMessage(const uint8_t *msg, uint32_t len, bool signing);
void layoutDecryptMessage(const uint8_t *msg, uint32_t len, const char *address);
void layoutAddress(const char *address);
#endif