Skip to content

Commit 690967f

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

33 files changed

+285
-382
lines changed

src/Makefile.in

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ LDFLAGS = -lstdc++ -lbc-crypto-base -lbc-shamir -lbc-slip39 -lbc-bip39 -largp
5353

5454
$(toolname): $(OBJS)
5555

56-
seedtool.o: params.h format.h
57-
utils.o: utils.h
58-
params.o: params.h utils.h random.h formats-all.h
59-
random.o: random.h randombytes.h hkdf.h
56+
seedtool.o: params.hpp format.hpp
57+
utils.o: utils.hpp
58+
params.o: params.hpp utils.hpp random.hpp formats-all.hpp
59+
random.o: random.hpp randombytes.h hkdf.h
6060
randombytes.o: randombytes.h
6161
hkdf.o: hkdf.h
62-
format.o: format.h utils.h
63-
formats-all.h: format-base6.h format-base10.h format-bip39.h format-bits.h format-cards.h format-dice.h format-hex.h format-ints.h format-random.h format-slip39.h
64-
format-base6.o: format-base6.h format.h params.h
65-
format-base10.o: format-base10.h format.h params.h
66-
format-bip39.o: format-bip39.h format.h params.h
67-
format-bits.o: format-bits.h format.h params.h
68-
format-cards.o: format-cards.h format.h params.h
69-
format-dice.o: format-dice.h format.h params.h
70-
format-hex.o: format-hex.h format.h params.h
71-
format-ints.o: format-ints.h format.h params.h
72-
format-random.o: format-random.h format.h params.h
73-
format-slip39.o: format-slip39.h format.h params.h
62+
format.o: format.hpp utils.hpp
63+
formats-all.hpp: format-base6.hpp format-base10.hpp format-bip39.hpp format-bits.hpp format-cards.hpp format-dice.hpp format-hex.hpp format-ints.hpp format-random.hpp format-slip39.hpp
64+
format-base6.o: format-base6.hpp format.hpp params.hpp
65+
format-base10.o: format-base10.hpp format.hpp params.hpp
66+
format-bip39.o: format-bip39.hpp format.hpp params.hpp
67+
format-bits.o: format-bits.hpp format.hpp params.hpp
68+
format-cards.o: format-cards.hpp format.hpp params.hpp
69+
format-dice.o: format-dice.hpp format.hpp params.hpp
70+
format-hex.o: format-hex.hpp format.hpp params.hpp
71+
format-ints.o: format-ints.hpp format.hpp params.hpp
72+
format-random.o: format-random.hpp format.hpp params.hpp
73+
format-slip39.o: format-slip39.hpp format.hpp params.hpp
7474

7575
bindir = $(DESTDIR)/$(prefix)/bin
7676

src/format-base10.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//
2-
// format-base10.c
2+
// format-base10.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-base10.h"
9-
#include "params.h"
10-
#include "utils.h"
8+
#include "format-base10.hpp"
9+
#include "params.hpp"
10+
#include "utils.hpp"
1111

1212
void format_base10_process_output(format* f, params* p) {
13-
p->output = data_to_ints(p->seed, p->seed_len, 0, 9, "");
13+
p->output = data_to_ints(p->seed, 0, 9, "");
1414
}
1515

1616
static void format_base10_dispose(format* f) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//
2-
// format-base10.h
2+
// format-base10.hpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BASE10_H
9-
#define FORMAT_BASE10_H
8+
#ifndef FORMAT_BASE10_HPP
9+
#define FORMAT_BASE10_HPP
1010

11-
#include "format.h"
11+
#include "format.hpp"
1212

1313
format* format_base10_new();
1414

15-
#endif /* FORMAT_BASE10_H */
15+
#endif /* FORMAT_BASE10_HPP */

src/format-base6.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//
2-
// format-base6.c
2+
// format-base6.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-base6.h"
9-
#include "params.h"
10-
#include "utils.h"
8+
#include "format-base6.hpp"
9+
#include "params.hpp"
10+
#include "utils.hpp"
1111

1212
void format_base6_process_output(format* f, params* p) {
13-
p->output = data_to_ints(p->seed, p->seed_len, 0, 5, "");
13+
p->output = data_to_ints(p->seed, 0, 5, "");
1414
}
1515

1616
static void format_base6_dispose(format* f) {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//
2-
// format-base6.h
2+
// format-base6.hpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BASE6_H
9-
#define FORMAT_BASE6_H
8+
#ifndef FORMAT_BASE6_HPP
9+
#define FORMAT_BASE6_HPP
1010

11-
#include "format.h"
11+
#include "format.hpp"
1212

1313
format* format_base6_new();
1414

15-
#endif /* FORMAT_BASE6_H */
15+
#endif /* FORMAT_BASE6_HPP */

src/format-bip39.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//
2-
// format-bip39.c
2+
// format-bip39.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-bip39.h"
8+
#include "format-bip39.hpp"
99

1010
#include <strings.h>
1111
#include <bc-bip39/bc-bip39.h>
1212

13-
#include "params.h"
14-
#include "utils.h"
13+
#include "params.hpp"
14+
#include "utils.hpp"
1515

1616
bool format_bip39_is_seed_length_valid(size_t seed_len) {
1717
if(!(12 <= seed_len && seed_len <= 32)) { return false; }
@@ -20,11 +20,11 @@ bool format_bip39_is_seed_length_valid(size_t seed_len) {
2020
}
2121

2222
void format_bip39_process_output(format* f, params* p) {
23-
if(!format_bip39_is_seed_length_valid(p->seed_len)) { return; }
23+
if(!format_bip39_is_seed_length_valid(p->seed.size())) { return; }
2424

2525
size_t max_mnemonics_len = 300;
2626
char mnemonics[max_mnemonics_len];
27-
size_t len = bip39_mnemonics_from_secret(p->seed, p->seed_len, mnemonics, max_mnemonics_len);
27+
size_t len = bip39_mnemonics_from_secret(&p->seed[0], p->seed.size(), mnemonics, max_mnemonics_len);
2828
char* string = (char*)malloc(len);
2929
strcpy(string, mnemonics);
3030
p->output = string;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//
2-
// format-bip39.h
2+
// format-bip39.hpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BIP39_H
9-
#define FORMAT_BIP39_H
8+
#ifndef FORMAT_BIP39_HPP
9+
#define FORMAT_BIP39_HPP
1010

11-
#include "format.h"
11+
#include "format.hpp"
1212

1313
#include <stdbool.h>
1414
#include <stdlib.h>
1515

1616
format* format_bip39_new();
1717
bool format_bip39_is_seed_length_valid(size_t seed_len);
1818

19-
#endif /* FORMAT_BIP39_H */
19+
#endif /* FORMAT_BIP39_HPP */

src/format-bits.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//
2-
// format-bits.c
2+
// format-bits.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-bits.h"
8+
#include "format-bits.hpp"
99

1010
#include <strings.h>
1111

12-
#include "params.h"
13-
#include "utils.h"
12+
#include "params.hpp"
13+
#include "utils.hpp"
1414

1515
void format_bits_process_output(format* f, params* p) {
16-
p->output = data_to_ints(p->seed, p->seed_len, 0, 1, "");
16+
p->output = data_to_ints(p->seed, 0, 1, "");
1717
}
1818

1919
static void format_bits_dispose(format* f) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
2-
// format-bits.h
2+
// format-bits.hpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#ifndef FORMAT_BITS_H
9-
#define FORMAT_BITS_H
8+
#ifndef FORMAT_BITS_HPP
9+
#define FORMAT_BITS_HPP
1010

11-
#include "format.h"
11+
#include "format.hpp"
1212

1313
format* format_bits_new();
1414

src/format-cards.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
//
2-
// format-cards.c
2+
// format-cards.cpp
33
//
44
// Copyright © 2020 by Blockchain Commons, LLC
55
// Licensed under the "BSD-2-Clause Plus Patent License"
66
//
77

8-
#include "format-cards.h"
8+
#include "format-cards.hpp"
99

1010
#include <strings.h>
1111

12-
#include "params.h"
13-
#include "utils.h"
12+
#include "params.hpp"
13+
#include "utils.hpp"
1414

15-
static const char* card_suits[] = { "c", "d", "h", "s" };
16-
static const char* card_ranks[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k"};
15+
static const std::string card_suits[] = { "c", "d", "h", "s" };
16+
static const std::string card_ranks[] = { "a", "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k"};
1717

18-
static char* to_card(size_t n) {
18+
static std::string to_card(size_t n) {
1919
if(n > 51) { return NULL; }
20-
char* buf = (char*)malloc(3);
20+
std::string buf;
2121
size_t rank = n % 13;
2222
size_t suit = n / 13;
23-
const char* rank_string = card_ranks[rank];
24-
const char* suit_string = card_suits[suit];
25-
strcpy(buf, rank_string);
26-
strcat(buf, suit_string);
23+
buf.append(card_ranks[rank]);
24+
buf.append(card_suits[suit]);
2725
return buf;
2826
}
2927

30-
void format_cards_process_output(format* f, params* p) {
31-
p->output = data_to_alphabet(p->seed, p->seed_len, 52, to_card);
28+
static void format_cards_process_output(format* f, params* p) {
29+
p->output = data_to_alphabet(p->seed, 52, to_card);
3230
}
3331

3432
static void format_cards_dispose(format* f) {

0 commit comments

Comments
 (0)