<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 10, 2014 at 6:41 AM, Rusty Russell <span dir="ltr"><<a href="mailto:rusty@rustcorp.com.au" target="_blank">rusty@rustcorp.com.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, sorry for the delayed response!<br>
<br>
Minor feedback below.<br>
<br>
First, I generally prefer patches inline (git am can do this for you),<br>
so I can directly quote them. Also mailman seems to eat your<br>
attachments, so they didn't reach the archive.<br>
<br>
Second, I've added a Signed-off-by: requirement a-la Linux kernel. I've<br>
had lawyers tell me it's important in the past, and maybe they're right.<br></blockquote><div><br></div><div>Hi there.</div><div><br></div><div>I don't have my current environment configured for Linux-kernel-like patches, I'll configure it and resend with the observations.</div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> commit d9a7fd88ae802d5ca8d4aad6e57ad0f09dd8ab8e<br>
> Author: Nelson Castillo <<a href="mailto:nelsoneci@gmail.com">nelsoneci@gmail.com</a>><br>
> Date: Wed Aug 6 04:28:06 2014 -0400<br>
><br>
> Generalize raw_decode_base58 adding raw_decode_base_n<br>
><br>
> This will make this function useful for other bases.<br>
><br>
> I was trying to make code to import from a raw hex bitcoin key.<br>
> I do not know if this (raw hex import) makes sense for Pettycoin.<br>
><br>
> diff --git a/base58.c b/base58.c<br>
> index da4a17d..5093b77 100644<br>
> --- a/base58.c<br>
> +++ b/base58.c<br>
> @@ -12,16 +12,17 @@<br>
> #include <openssl/sha.h><br>
> #include <string.h><br>
><br>
> -static const char enc[] =<br>
> +static const char enc_16[] = "0123456789abcdef";<br>
> +static const char enc_58[] =<br>
> "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";<br>
><br>
> -static char encode_char(unsigned long val)<br>
> +static char encode_char(unsigned long val, const char *enc)<br>
> {<br>
> assert(val < strlen(enc));<br>
> return enc[val];<br>
> }<br>
><br>
> -static int decode_char(char c)<br>
> +static int decode_char(char c, const char *enc)<br>
> {<br>
> const char *pos = strchr(enc, c);<br>
> if (!pos)<br>
> @@ -58,7 +59,7 @@ static char *encode_base58(char *buf, size_t buflen,<br>
> p = NULL;<br>
> goto out;<br>
> }<br>
> - *p = encode_char(rem);<br>
> + *p = encode_char(rem, enc_58);<br>
> }<br>
><br>
> /* Now, this is really weird. We pad with zeroes, but not at<br>
> @@ -69,7 +70,7 @@ static char *encode_base58(char *buf, size_t buflen,<br>
> p = NULL;<br>
> goto out;<br>
> }<br>
> - *p = encode_char(0);<br>
> + *p = encode_char(0, enc_58);<br>
> data_len--;<br>
> data++;<br>
> }<br>
> @@ -80,20 +81,36 @@ out:<br>
> }<br>
><br>
> /*<br>
> - * Decode a base58-encoded string into a byte sequence.<br>
> + * Decode a base_n-encoded string into a byte sequence.<br>
> */<br>
> -bool raw_decode_base58(BIGNUM *bn, const char *src, size_t len)<br>
> +bool raw_decode_base_n(BIGNUM *bn, const char *src, size_t len, int base)<br>
> {<br>
> + const char *enc;<br>
> BN_init(bn);<br>
> BN_zero(bn);<br>
><br>
> + assert(base == 16 || base == 58);<br>
> + switch (base) {<br>
> + case 16:<br>
> + enc = enc_16;<br>
> + break;<br>
> + case 58:<br>
> + enc = enc_58;<br>
> + break;<br>
> + default:<br>
> + abort();<br>
<br>
Doesn't need both assert() and abort() :)<br></blockquote><div><br></div><div>Yeah. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And given your comment in your test, you might want to have the caller<br>
do the BN_init()?<br></blockquote><div><br></div><div>Yes. I think that's better.</div><div><br></div><div>Thanks.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers,<br>
Rusty.<br>
_______________________________________________<br>
Pettycoin-dev mailing list<br>
<a href="mailto:Pettycoin-dev@lists.ozlabs.org">Pettycoin-dev@lists.ozlabs.org</a><br>
<a href="https://lists.ozlabs.org/listinfo/pettycoin-dev" target="_blank">https://lists.ozlabs.org/listinfo/pettycoin-dev</a><br>
</blockquote></div><br></div></div>