Skip to content

Commit f477be3

Browse files
committed
Converting to C++.
1 parent 690967f commit f477be3

29 files changed

+884
-757
lines changed

configure

Lines changed: 601 additions & 298 deletions
Large diffs are not rendered by default.

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ AC_CONFIG_SRCDIR([src/seedtool.cpp])
77
AC_CONFIG_HEADERS([config.h])
88

99
# Checks for programs.
10+
AC_PROG_CXX
1011
AC_PROG_CC
1112
AC_PROG_INSTALL
1213

src/Makefile.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ OBJS = \
3535
utils.o \
3636
params.o \
3737
random.o \
38-
randombytes.o \
39-
hkdf.o \
4038
format.o \
4139
format-base6.o \
4240
format-base10.o \
@@ -47,7 +45,9 @@ OBJS = \
4745
format-hex.o \
4846
format-ints.o \
4947
format-random.o \
50-
format-slip39.o
48+
format-slip39.o \
49+
randombytes.o \
50+
hkdf.o
5151

5252
LDFLAGS = -lstdc++ -lbc-crypto-base -lbc-shamir -lbc-slip39 -lbc-bip39 -largp
5353

src/format-base10.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,9 @@
99
#include "params.hpp"
1010
#include "utils.hpp"
1111

12-
void format_base10_process_output(format* f, params* p) {
13-
p->output = data_to_ints(p->seed, 0, 9, "");
14-
}
15-
16-
static void format_base10_dispose(format* f) {
17-
free(f);
12+
void FormatBase10::process_input(Params* p) {
1813
}
1914

20-
format* format_base10_new() {
21-
format* f = (format*)calloc(sizeof(format), 1);
22-
f->key = format_key_base10;
23-
f->name = "base10";
24-
f->process_output = format_base10_process_output;
25-
f->dispose = format_base10_dispose;
26-
return f;
15+
void FormatBase10::process_output(Params* p) {
16+
p->output = data_to_ints(p->seed, 0, 9, "");
2717
}

src/format-base10.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BASE10_HPP
9-
#define FORMAT_BASE10_HPP
8+
#pragma once
109

1110
#include "format.hpp"
1211

13-
format* format_base10_new();
12+
class FormatBase10 : public Format {
13+
public:
14+
FormatBase10() : Format(Format::Key::base10, "base10") {}
1415

15-
#endif /* FORMAT_BASE10_HPP */
16+
virtual void process_input(Params* p);
17+
virtual void process_output(Params* p);
18+
};

src/format-base6.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,9 @@
99
#include "params.hpp"
1010
#include "utils.hpp"
1111

12-
void format_base6_process_output(format* f, params* p) {
13-
p->output = data_to_ints(p->seed, 0, 5, "");
14-
}
15-
16-
static void format_base6_dispose(format* f) {
17-
free(f);
12+
void FormatBase6::process_input(Params* p) {
1813
}
1914

20-
format* format_base6_new() {
21-
format* f = (format*)calloc(sizeof(format), 1);
22-
f->key = format_key_base6;
23-
f->name = "base6";
24-
f->process_output = format_base6_process_output;
25-
f->dispose = format_base6_dispose;
26-
return f;
15+
void FormatBase6::process_output(Params* p) {
16+
p->output = data_to_ints(p->seed, 0, 5, "");
2717
}

src/format-base6.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BASE6_HPP
9-
#define FORMAT_BASE6_HPP
8+
#pragma once
109

1110
#include "format.hpp"
1211

13-
format* format_base6_new();
12+
class FormatBase6 : public Format {
13+
public:
14+
FormatBase6() : Format(Format::Key::base6, "base6") {}
1415

15-
#endif /* FORMAT_BASE6_HPP */
16+
virtual void process_input(Params* p);
17+
virtual void process_output(Params* p);
18+
};

src/format-bip39.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
#include "params.hpp"
1414
#include "utils.hpp"
1515

16-
bool format_bip39_is_seed_length_valid(size_t seed_len) {
16+
bool FormatBIP39::is_seed_length_valid(size_t seed_len) {
1717
if(!(12 <= seed_len && seed_len <= 32)) { return false; }
1818
if(seed_len % 2 != 0) { return false; }
1919
return true;
2020
}
2121

22-
void format_bip39_process_output(format* f, params* p) {
23-
if(!format_bip39_is_seed_length_valid(p->seed.size())) { return; }
22+
void FormatBIP39::process_input(Params* p) {
23+
}
24+
25+
void FormatBIP39::process_output(Params* p) {
26+
if(!is_seed_length_valid(p->seed.size())) { return; }
2427

2528
size_t max_mnemonics_len = 300;
2629
char mnemonics[max_mnemonics_len];
@@ -29,16 +32,3 @@ void format_bip39_process_output(format* f, params* p) {
2932
strcpy(string, mnemonics);
3033
p->output = string;
3134
}
32-
33-
static void format_bip39_dispose(format* f) {
34-
free(f);
35-
}
36-
37-
format* format_bip39_new() {
38-
format* f = (format*)calloc(sizeof(format), 1);
39-
f->key = format_key_bip39;
40-
f->name = "bip39";
41-
f->process_output = format_bip39_process_output;
42-
f->dispose = format_bip39_dispose;
43-
return f;
44-
}

src/format-bip39.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BIP39_HPP
9-
#define FORMAT_BIP39_HPP
10-
11-
#include "format.hpp"
8+
#pragma once
129

1310
#include <stdbool.h>
1411
#include <stdlib.h>
1512

16-
format* format_bip39_new();
17-
bool format_bip39_is_seed_length_valid(size_t seed_len);
13+
#include "format.hpp"
14+
15+
class FormatBIP39 : public Format {
16+
public:
17+
FormatBIP39() : Format(Format::Key::bip39, "bip39") {}
18+
19+
virtual void process_input(Params* p);
20+
virtual void process_output(Params* p);
1821

19-
#endif /* FORMAT_BIP39_HPP */
22+
static bool is_seed_length_valid(size_t seed_len);
23+
};

src/format-bits.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,12 @@
66
//
77

88
#include "format-bits.hpp"
9-
10-
#include <strings.h>
11-
129
#include "params.hpp"
1310
#include "utils.hpp"
1411

15-
void format_bits_process_output(format* f, params* p) {
16-
p->output = data_to_ints(p->seed, 0, 1, "");
17-
}
18-
19-
static void format_bits_dispose(format* f) {
20-
free(f);
12+
void FormatBits::process_input(Params* p) {
2113
}
2214

23-
format* format_bits_new() {
24-
format* f = (format*)calloc(sizeof(format), 1);
25-
f->key = format_key_bits;
26-
f->name = "bits";
27-
f->process_output = format_bits_process_output;
28-
f->dispose = format_bits_dispose;
29-
return f;
15+
void FormatBits::process_output(Params* p) {
16+
p->output = data_to_ints(p->seed, 0, 1, "");
3017
}

0 commit comments

Comments
 (0)