From 00413c0b6ea66efc334e3bc3bf8507dc2ea0caa3 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 6 Oct 2016 12:36:23 +0200 Subject: [PATCH] bip32: serialization returns nu. of written bytes --- bip32.c | 14 +++++++------- bip32.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bip32.c b/bip32.c index fac809eac6..c72a672acc 100644 --- a/bip32.c +++ b/bip32.c @@ -438,7 +438,7 @@ int hdnode_sign_digest(HDNode *node, const uint8_t *digest, uint8_t *sig, uint8_ } -void hdnode_serialize(const HDNode *node, uint32_t fingerprint, uint32_t version, char use_public, char *str, int strsize) +int hdnode_serialize(const HDNode *node, uint32_t fingerprint, uint32_t version, char use_public, char *str, int strsize) { uint8_t node_data[78]; write_be(node_data, version); @@ -452,19 +452,19 @@ void hdnode_serialize(const HDNode *node, uint32_t fingerprint, uint32_t version node_data[45] = 0; memcpy(node_data + 46, node->private_key, 32); } - base58_encode_check(node_data, sizeof(node_data), str, strsize); - + int ret = base58_encode_check(node_data, sizeof(node_data), str, strsize); MEMSET_BZERO(node_data, sizeof(node_data)); + return ret; } -void hdnode_serialize_public(const HDNode *node, uint32_t fingerprint, char *str, int strsize) +int hdnode_serialize_public(const HDNode *node, uint32_t fingerprint, char *str, int strsize) { - hdnode_serialize(node, fingerprint, 0x0488B21E, 1, str, strsize); + return hdnode_serialize(node, fingerprint, 0x0488B21E, 1, str, strsize); } -void hdnode_serialize_private(const HDNode *node, uint32_t fingerprint, char *str, int strsize) +int hdnode_serialize_private(const HDNode *node, uint32_t fingerprint, char *str, int strsize) { - hdnode_serialize(node, fingerprint, 0x0488ADE4, 0, str, strsize); + return hdnode_serialize(node, fingerprint, 0x0488ADE4, 0, str, strsize); } // check for validity of curve point in case of public data not performed diff --git a/bip32.h b/bip32.h index 1cf0312204..fe12a1a2f3 100644 --- a/bip32.h +++ b/bip32.h @@ -74,14 +74,14 @@ int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash); int hdnode_sign(HDNode *node, const uint8_t *msg, uint32_t msg_len, uint8_t *sig, uint8_t *pby); int hdnode_sign_digest(HDNode *node, const uint8_t *digest, uint8_t *sig, uint8_t *pby); -void hdnode_serialize_public(const HDNode *node, uint32_t fingerprint, char *str, int strsize); +int hdnode_serialize_public(const HDNode *node, uint32_t fingerprint, char *str, int strsize); -void hdnode_serialize_private(const HDNode *node, uint32_t fingerprint, char *str, int strsize); +int hdnode_serialize_private(const HDNode *node, uint32_t fingerprint, char *str, int strsize); int hdnode_deserialize(const char *str, HDNode *node); // Private -void hdnode_serialize(const HDNode *node, uint32_t fingerprint, uint32_t version, char use_public, char *str, int strsize); +int hdnode_serialize(const HDNode *node, uint32_t fingerprint, uint32_t version, char use_public, char *str, int strsize); void hdnode_get_address_raw(HDNode *node, uint8_t version, uint8_t *addr_raw);