Browse code
Reformat
Ed Langley authored on 13/06/2017 22:59:30
Showing 9 changed files
Showing 9 changed files
- base32.cc
- base32.h
- base32_test.cc
- dual_control_tool.cc
- installer_test.cc
- random_source.cc
- random_source.h
- random_source_test.cc
- test_util.h
... | ... |
@@ -31,7 +31,7 @@ private: |
31 | 31 |
using string_size = std::string::size_type; |
32 | 32 |
public: |
33 | 33 |
string_size received_size; |
34 |
- invalid_input_size(string_size received_size) : |
|
34 |
+ invalid_input_size (string_size received_size) : |
|
35 | 35 |
received_size (received_size) |
36 | 36 |
{} |
37 | 37 |
}; |
... | ... |
@@ -177,7 +177,7 @@ private: |
177 | 177 |
std::string::size_type first_equals = input.find_first_of ('='); |
178 | 178 |
|
179 | 179 |
if (input_size == 0 || (input_size % 8 != 0)) { |
180 |
- throw invalid_input_size(input_size); |
|
180 |
+ throw invalid_input_size (input_size); |
|
181 | 181 |
} |
182 | 182 |
|
183 | 183 |
if (first_equals != std::string::npos) { |
... | ... |
@@ -211,8 +211,6 @@ public: |
211 | 211 |
bits_written += 5; |
212 | 212 |
} |
213 | 213 |
|
214 |
- |
|
215 |
- |
|
216 | 214 |
return result; |
217 | 215 |
} |
218 | 216 |
}; |
... | ... |
@@ -223,3 +221,4 @@ template class std::vector<unsigned char>; |
223 | 221 |
base32::base32 (): |
224 | 222 |
delegate_ (std::make_shared<base32_impl> ()) |
225 | 223 |
{} |
224 |
+ |
... | ... |
@@ -65,9 +65,9 @@ int decode_validates_input() |
65 | 65 |
base32 codec = base32(); |
66 | 66 |
|
67 | 67 |
try { |
68 |
- codec.decode("\x00"); |
|
69 |
- codec.decode("\x00\x00\x00\x00\x00\x00\x00\x00\x00"); |
|
70 |
- fail("invalid length should result in an exception"); |
|
68 |
+ codec.decode ("\x00"); |
|
69 |
+ codec.decode ("\x00\x00\x00\x00\x00\x00\x00\x00\x00"); |
|
70 |
+ fail ("invalid length should result in an exception"); |
|
71 | 71 |
} catch (std::exception e) { |
72 | 72 |
succeed(); |
73 | 73 |
} |
... | ... |
@@ -107,3 +107,4 @@ int main (int argc, char *argv[]) |
107 | 107 |
{ |
108 | 108 |
return !run_tests(); |
109 | 109 |
} |
110 |
+ |
... | ... |
@@ -38,7 +38,7 @@ installer init_installer() |
38 | 38 |
{ |
39 | 39 |
fstreams fstreams (fstreams::create()); |
40 | 40 |
|
41 |
- random_source foo (random_source::create(fstreams)); |
|
41 |
+ random_source foo (random_source::create (fstreams)); |
|
42 | 42 |
auto bytes = foo.get_random_bytes (16); |
43 | 43 |
std::cout << "I'm random: "; |
44 | 44 |
|
... | ... |
@@ -71,3 +71,4 @@ int main (int argc, char *argv[]) |
71 | 71 |
std::cout << generated_key_and_sample_token.first << " " << |
72 | 72 |
generated_key_and_sample_token.second << std::endl; |
73 | 73 |
} |
74 |
+ |
... | ... |
@@ -25,7 +25,8 @@ public: |
25 | 25 |
impl (fstreams fstreams) |
26 | 26 |
: fstreams_ (fstreams) |
27 | 27 |
{} |
28 |
- std::vector<uint8_t> get_random_bytes (int length) const override { |
|
28 |
+ std::vector<uint8_t> get_random_bytes (int length) const override |
|
29 |
+ { |
|
29 | 30 |
fstreams::pstream random_source = fstreams_.open_fstream (file_path); |
30 | 31 |
|
31 | 32 |
std::vector<uint8_t> result (length); |
... | ... |
@@ -42,6 +43,8 @@ public: |
42 | 43 |
|
43 | 44 |
const std::string random_source_ifc::file_path = "/dev/urandom"; |
44 | 45 |
|
45 |
-random_source random_source::create(fstreams &fstreams) { |
|
46 |
- return random_source(random_source::delegate (new impl (fstreams))); |
|
46 |
+random_source random_source::create (fstreams &fstreams) |
|
47 |
+{ |
|
48 |
+ return random_source (random_source::delegate (new impl (fstreams))); |
|
47 | 49 |
}; |
50 |
+ |
... | ... |
@@ -49,7 +49,8 @@ int reads_from_the_right_file () |
49 | 49 |
std::string very_random_bytes { 4, 2 }; |
50 | 50 |
// hardcoded file name is .dual_control in the user's home directory |
51 | 51 |
|
52 |
- fstreams test_streams (fstreams::delegate (new fake_fstreams (random_source, very_random_bytes))); |
|
52 |
+ fstreams test_streams (fstreams::delegate (new fake_fstreams (random_source, |
|
53 |
+ very_random_bytes))); |
|
53 | 54 |
|
54 | 55 |
//file_reader test_file_reader (file_reader::delegate (new fake_file_reader)); |
55 | 56 |
class random_source supplier (random_source::create (test_streams)); |
... | ... |
@@ -69,7 +70,8 @@ int handles_missing_random_source_correctly () |
69 | 70 |
std::string very_random_bytes { 4, 2 }; |
70 | 71 |
// hardcoded file name is .dual_control in the user's home directory |
71 | 72 |
|
72 |
- fstreams test_streams (fstreams::delegate (new fake_fstreams ("/nowhere", very_random_bytes))); |
|
73 |
+ fstreams test_streams (fstreams::delegate (new fake_fstreams ("/nowhere", |
|
74 |
+ very_random_bytes))); |
|
73 | 75 |
|
74 | 76 |
//file_reader test_file_reader (file_reader::delegate (new fake_file_reader)); |
75 | 77 |
class random_source supplier (random_source::create (test_streams)); |
... | ... |
@@ -77,7 +79,7 @@ int handles_missing_random_source_correctly () |
77 | 79 |
//when |
78 | 80 |
try { |
79 | 81 |
supplier.get_random_bytes (2); |
80 |
- fail("get_random_bytes() should throw if it can't access /dev/urandom"); |
|
82 |
+ fail ("get_random_bytes() should throw if it can't access /dev/urandom"); |
|
81 | 83 |
} catch (std::exception e) { |
82 | 84 |
succeed(); |
83 | 85 |
} |
... | ... |
@@ -97,3 +99,4 @@ int main (int argc, char *argv[]) |
97 | 99 |
{ |
98 | 100 |
return !run_tests(); |
99 | 101 |
} |
102 |
+ |