b58 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.gitmodules +3 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/b58.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/b58/b58.c +126 -0
- data/ext/b58/b58.h +6 -0
- data/ext/b58/extconf.rb +14 -0
- data/ext/libbase58/.gitignore +25 -0
- data/ext/libbase58/.travis.yml +48 -0
- data/ext/libbase58/AUTHORS +2 -0
- data/ext/libbase58/COPYING +19 -0
- data/ext/libbase58/INSTALL +20 -0
- data/ext/libbase58/Makefile.am +44 -0
- data/ext/libbase58/README.md +66 -0
- data/ext/libbase58/autogen.sh +11 -0
- data/ext/libbase58/base58.c +205 -0
- data/ext/libbase58/clitool.c +130 -0
- data/ext/libbase58/configure.ac +49 -0
- data/ext/libbase58/libbase58.h +23 -0
- data/ext/libbase58/libbase58.pc.in +10 -0
- data/ext/libbase58/tests/decode-b58c-fail.sh +2 -0
- data/ext/libbase58/tests/decode-b58c-null.sh +3 -0
- data/ext/libbase58/tests/decode-b58c-toolong.sh +2 -0
- data/ext/libbase58/tests/decode-b58c-tooshort.sh +2 -0
- data/ext/libbase58/tests/decode-b58c.sh +3 -0
- data/ext/libbase58/tests/decode-highbit-prefix.sh +3 -0
- data/ext/libbase58/tests/decode-highbit.sh +3 -0
- data/ext/libbase58/tests/decode-small.sh +3 -0
- data/ext/libbase58/tests/decode-zero.sh +3 -0
- data/ext/libbase58/tests/decode.sh +3 -0
- data/ext/libbase58/tests/encode-b58c-high.sh +3 -0
- data/ext/libbase58/tests/encode-b58c.sh +3 -0
- data/ext/libbase58/tests/encode-fail.sh +3 -0
- data/ext/libbase58/tests/encode-neg-index.sh +4 -0
- data/ext/libbase58/tests/encode-small.sh +3 -0
- data/ext/libbase58/tests/encode.sh +3 -0
- data/lib/b58.rb +7 -0
- data/lib/b58/version.rb +3 -0
- metadata +93 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2014 Luke Dashjr
|
3
|
+
*
|
4
|
+
* This program is free software; you can redistribute it and/or modify it
|
5
|
+
* under the terms of the standard MIT license. See COPYING for more details.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <ctype.h>
|
9
|
+
#include <stdbool.h>
|
10
|
+
#include <stdint.h>
|
11
|
+
#include <stdio.h>
|
12
|
+
#include <stdlib.h>
|
13
|
+
#include <string.h>
|
14
|
+
#include <unistd.h>
|
15
|
+
|
16
|
+
#include <gcrypt.h>
|
17
|
+
|
18
|
+
#include "libbase58.h"
|
19
|
+
|
20
|
+
static
|
21
|
+
bool my_sha256(void *digest, const void *data, size_t datasz)
|
22
|
+
{
|
23
|
+
gcry_md_hash_buffer(GCRY_MD_SHA256, digest, data, datasz);
|
24
|
+
return true;
|
25
|
+
}
|
26
|
+
|
27
|
+
static
|
28
|
+
void usage(const char *prog)
|
29
|
+
{
|
30
|
+
fprintf(stderr, "Usage: %s [-c] [-d] [data]\n", prog);
|
31
|
+
fprintf(stderr, "\t-c Use base58check (default: raw base58)\n");
|
32
|
+
fprintf(stderr, "\t-d <size> Decode <size> bytes\n");
|
33
|
+
exit(1);
|
34
|
+
}
|
35
|
+
|
36
|
+
int main(int argc, char **argv)
|
37
|
+
{
|
38
|
+
bool b58c = false;
|
39
|
+
size_t decode = 0;
|
40
|
+
int opt;
|
41
|
+
while ( (opt = getopt(argc, argv, "cd:h")) != -1)
|
42
|
+
{
|
43
|
+
switch (opt)
|
44
|
+
{
|
45
|
+
case 'c':
|
46
|
+
b58c = true;
|
47
|
+
b58_sha256_impl = my_sha256;
|
48
|
+
break;
|
49
|
+
case 'd':
|
50
|
+
{
|
51
|
+
int i = atoi(optarg);
|
52
|
+
if (i < 0 || (uintmax_t)i >= SIZE_MAX)
|
53
|
+
usage(argv[0]);
|
54
|
+
decode = (size_t)i;
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
default:
|
58
|
+
usage(argv[0]);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
size_t rt;
|
63
|
+
union {
|
64
|
+
uint8_t *b;
|
65
|
+
char *s;
|
66
|
+
} r;
|
67
|
+
if (optind >= argc)
|
68
|
+
{
|
69
|
+
rt = 0;
|
70
|
+
r.b = NULL;
|
71
|
+
while (!feof(stdin))
|
72
|
+
{
|
73
|
+
r.b = realloc(r.b, rt + 0x100);
|
74
|
+
rt += fread(&r.b[rt], 1, 0x100, stdin);
|
75
|
+
}
|
76
|
+
if (decode)
|
77
|
+
while (isspace(r.s[rt-1]))
|
78
|
+
--rt;
|
79
|
+
}
|
80
|
+
else
|
81
|
+
{
|
82
|
+
r.s = argv[optind];
|
83
|
+
rt = strlen(argv[optind]);
|
84
|
+
}
|
85
|
+
|
86
|
+
if (decode)
|
87
|
+
{
|
88
|
+
uint8_t bin[decode];
|
89
|
+
size_t ssz = decode;
|
90
|
+
if (!b58tobin(bin, &ssz, r.s, rt))
|
91
|
+
return 2;
|
92
|
+
if (b58c)
|
93
|
+
{
|
94
|
+
int chk = b58check(bin, decode, r.s, rt);
|
95
|
+
if (chk < 0)
|
96
|
+
return chk;
|
97
|
+
if (fwrite(bin, decode, 1, stdout) != 1)
|
98
|
+
return 3;
|
99
|
+
}
|
100
|
+
else
|
101
|
+
{
|
102
|
+
// Raw base58 doesn't check length match
|
103
|
+
uint8_t cbin[ssz];
|
104
|
+
if (ssz > decode)
|
105
|
+
{
|
106
|
+
size_t zeros = ssz - decode;
|
107
|
+
memset(cbin, 0, zeros);
|
108
|
+
memcpy(&cbin[zeros], bin, decode);
|
109
|
+
}
|
110
|
+
else
|
111
|
+
memcpy(cbin, &bin[decode - ssz], ssz);
|
112
|
+
|
113
|
+
if (fwrite(cbin, ssz, 1, stdout) != 1)
|
114
|
+
return 3;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
else
|
118
|
+
{
|
119
|
+
size_t ssz = rt * 2;
|
120
|
+
char s[ssz];
|
121
|
+
bool rv;
|
122
|
+
if (b58c)
|
123
|
+
rv = rt && b58check_enc(s, &ssz, r.b[0], &r.b[1], rt-1);
|
124
|
+
else
|
125
|
+
rv = b58enc(s, &ssz, r.b, rt);
|
126
|
+
if (!rv)
|
127
|
+
return 2;
|
128
|
+
puts(s);
|
129
|
+
}
|
130
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
dnl * Copyright 2012-2014 Luke Dashjr
|
2
|
+
dnl *
|
3
|
+
dnl * This program is free software; you can redistribute it and/or modify it
|
4
|
+
dnl * under the terms of the standard MIT license. See COPYING for more details.
|
5
|
+
|
6
|
+
AC_INIT(
|
7
|
+
[libbase58],
|
8
|
+
[0.1.4],
|
9
|
+
[luke_libbase58@dashjr.org],
|
10
|
+
[libbase58])
|
11
|
+
AC_CONFIG_AUX_DIR([.])
|
12
|
+
AC_PREREQ([2.59])
|
13
|
+
AM_INIT_AUTOMAKE([1.11 -Wall dist-xz foreign])
|
14
|
+
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
|
15
|
+
|
16
|
+
AC_PROG_CC_C99
|
17
|
+
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
18
|
+
LT_INIT([])
|
19
|
+
|
20
|
+
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
21
|
+
AC_SUBST([LIBBASE58_SO_VERSION], [0:2:0])
|
22
|
+
|
23
|
+
AC_CONFIG_FILES([Makefile
|
24
|
+
libbase58.pc:libbase58.pc.in
|
25
|
+
])
|
26
|
+
|
27
|
+
AC_CHECK_LIB([ws2_32], [strchr])
|
28
|
+
|
29
|
+
m4_ifdef([AM_PATH_LIBGCRYPT], [
|
30
|
+
AC_ARG_ENABLE([tool],
|
31
|
+
[AC_HELP_STRING([--disable-tool],[Compile command line base58 tool (default enabled)])],
|
32
|
+
[use_tool=$enableval],
|
33
|
+
[use_tool=auto])
|
34
|
+
if test x$use_tool != xno; then
|
35
|
+
AM_PATH_LIBGCRYPT([],[
|
36
|
+
use_tool=yes
|
37
|
+
],[
|
38
|
+
if test x$use_tool = xyes; then
|
39
|
+
AC_MSG_ERROR([libgcrypt not found; use --disable-tool])
|
40
|
+
fi
|
41
|
+
use_tool=no
|
42
|
+
])
|
43
|
+
fi
|
44
|
+
],[
|
45
|
+
m4_warn([syntax], [AM_PATH_LIBGCRYPT missing; CLI tool will not be available])
|
46
|
+
])
|
47
|
+
AM_CONDITIONAL([USE_TOOL], [test x$use_tool = xyes])
|
48
|
+
|
49
|
+
AC_OUTPUT
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef LIBBASE58_H
|
2
|
+
#define LIBBASE58_H
|
3
|
+
|
4
|
+
#include <stdbool.h>
|
5
|
+
#include <stddef.h>
|
6
|
+
|
7
|
+
#ifdef __cplusplus
|
8
|
+
extern "C" {
|
9
|
+
#endif
|
10
|
+
|
11
|
+
extern bool (*b58_sha256_impl)(void *, const void *, size_t);
|
12
|
+
|
13
|
+
extern bool b58tobin(void *bin, size_t *binsz, const char *b58, size_t b58sz);
|
14
|
+
extern int b58check(const void *bin, size_t binsz, const char *b58, size_t b58sz);
|
15
|
+
|
16
|
+
extern bool b58enc(char *b58, size_t *b58sz, const void *bin, size_t binsz);
|
17
|
+
extern bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver, const void *data, size_t datasz);
|
18
|
+
|
19
|
+
#ifdef __cplusplus
|
20
|
+
}
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#endif
|
data/lib/b58.rb
ADDED
data/lib/b58/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: b58
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian Ker-Seymer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Uses libbase58 to encode Ruby strings to base58
|
14
|
+
email:
|
15
|
+
- i.kerseymer@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/b58/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".gitmodules"
|
23
|
+
- ".rspec"
|
24
|
+
- ".travis.yml"
|
25
|
+
- CODE_OF_CONDUCT.md
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- b58.gemspec
|
32
|
+
- bin/console
|
33
|
+
- bin/setup
|
34
|
+
- ext/b58/b58.c
|
35
|
+
- ext/b58/b58.h
|
36
|
+
- ext/b58/extconf.rb
|
37
|
+
- ext/libbase58/.gitignore
|
38
|
+
- ext/libbase58/.travis.yml
|
39
|
+
- ext/libbase58/AUTHORS
|
40
|
+
- ext/libbase58/COPYING
|
41
|
+
- ext/libbase58/INSTALL
|
42
|
+
- ext/libbase58/Makefile.am
|
43
|
+
- ext/libbase58/README.md
|
44
|
+
- ext/libbase58/autogen.sh
|
45
|
+
- ext/libbase58/base58.c
|
46
|
+
- ext/libbase58/clitool.c
|
47
|
+
- ext/libbase58/configure.ac
|
48
|
+
- ext/libbase58/libbase58.h
|
49
|
+
- ext/libbase58/libbase58.pc.in
|
50
|
+
- ext/libbase58/tests/decode-b58c-fail.sh
|
51
|
+
- ext/libbase58/tests/decode-b58c-null.sh
|
52
|
+
- ext/libbase58/tests/decode-b58c-toolong.sh
|
53
|
+
- ext/libbase58/tests/decode-b58c-tooshort.sh
|
54
|
+
- ext/libbase58/tests/decode-b58c.sh
|
55
|
+
- ext/libbase58/tests/decode-highbit-prefix.sh
|
56
|
+
- ext/libbase58/tests/decode-highbit.sh
|
57
|
+
- ext/libbase58/tests/decode-small.sh
|
58
|
+
- ext/libbase58/tests/decode-zero.sh
|
59
|
+
- ext/libbase58/tests/decode.sh
|
60
|
+
- ext/libbase58/tests/encode-b58c-high.sh
|
61
|
+
- ext/libbase58/tests/encode-b58c.sh
|
62
|
+
- ext/libbase58/tests/encode-fail.sh
|
63
|
+
- ext/libbase58/tests/encode-neg-index.sh
|
64
|
+
- ext/libbase58/tests/encode-small.sh
|
65
|
+
- ext/libbase58/tests/encode.sh
|
66
|
+
- lib/b58.rb
|
67
|
+
- lib/b58/version.rb
|
68
|
+
homepage: https://github.com/ianks/b58
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://github.com/ianks/b58
|
73
|
+
source_code_uri: https://github.com/ianks/b58
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.3.0
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubygems_version: 3.0.3
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: A base58 encoder for Ruby
|
93
|
+
test_files: []
|