diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-09 13:46:41 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-12 01:00:00 +0100 |
commit | 459f8f201393ac458445aebbd14c45bf4d6f5912 (patch) | |
tree | 67c7eb3c6338f701cdbd3fae808b45fa126fcd74 /other/fun | |
parent | 8339e3449f41f5d6edd16a8657f7faa84040fdc3 (diff) |
Check code formatting on Travis.
We run astyle on Travis and check if there is a diff. The build terminates if
git finds a difference.
Diffstat (limited to 'other/fun')
-rw-r--r-- | other/fun/strkey.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/other/fun/strkey.c b/other/fun/strkey.c index 7e5a1e1c..649b26dd 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c | |||
@@ -46,6 +46,7 @@ | |||
46 | void print_key(unsigned char *key) | 46 | void print_key(unsigned char *key) |
47 | { | 47 | { |
48 | size_t i; | 48 | size_t i; |
49 | |||
49 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { | 50 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { |
50 | if (key[i] < 16) { | 51 | if (key[i] < 16) { |
51 | fprintf(stdout, "0"); | 52 | fprintf(stdout, "0"); |
@@ -67,11 +68,14 @@ int main(int argc, char *argv[]) | |||
67 | offset = atoi(argv[1]); | 68 | offset = atoi(argv[1]); |
68 | char *desired_hex = argv[2]; | 69 | char *desired_hex = argv[2]; |
69 | len = strlen(desired_hex); | 70 | len = strlen(desired_hex); |
71 | |||
70 | if (len % 2 != 0) { | 72 | if (len % 2 != 0) { |
71 | fprintf(stderr, "Desired key should have an even number of letters\n"); | 73 | fprintf(stderr, "Desired key should have an even number of letters\n"); |
72 | exit(1); | 74 | exit(1); |
73 | } | 75 | } |
74 | size_t block_length = (offset < 0 ? 0 : offset) + len/2; | 76 | |
77 | size_t block_length = (offset < 0 ? 0 : offset) + len / 2; | ||
78 | |||
75 | if (block_length > crypto_box_PUBLICKEYBYTES) { | 79 | if (block_length > crypto_box_PUBLICKEYBYTES) { |
76 | fprintf(stderr, "The given key with the given offset exceed public key's length\n"); | 80 | fprintf(stderr, "The given key with the given offset exceed public key's length\n"); |
77 | exit(1); | 81 | exit(1); |
@@ -80,6 +84,7 @@ int main(int argc, char *argv[]) | |||
80 | // convert hex to bin | 84 | // convert hex to bin |
81 | char *pos = desired_hex; | 85 | char *pos = desired_hex; |
82 | size_t i; | 86 | size_t i; |
87 | |||
83 | for (i = 0; i < len; pos += 2) { | 88 | for (i = 0; i < len; pos += 2) { |
84 | sscanf(pos, "%2hhx", &desired_bin[i]); | 89 | sscanf(pos, "%2hhx", &desired_bin[i]); |
85 | ++i; | 90 | ++i; |
@@ -97,12 +102,14 @@ int main(int argc, char *argv[]) | |||
97 | 102 | ||
98 | if (offset < 0) { | 103 | if (offset < 0) { |
99 | int found = 0; | 104 | int found = 0; |
105 | |||
100 | do { | 106 | do { |
101 | #ifdef PRINT_TRIES_COUNT | 107 | #ifdef PRINT_TRIES_COUNT |
102 | tries ++; | 108 | tries ++; |
103 | #endif | 109 | #endif |
104 | crypto_box_keypair(public_key, secret_key); | 110 | crypto_box_keypair(public_key, secret_key); |
105 | int i; | 111 | int i; |
112 | |||
106 | for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) { | 113 | for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) { |
107 | if (memcmp(public_key + i, desired_bin, len) == 0) { | 114 | if (memcmp(public_key + i, desired_bin, len) == 0) { |
108 | found = 1; | 115 | found = 1; |
@@ -115,7 +122,7 @@ int main(int argc, char *argv[]) | |||
115 | 122 | ||
116 | do { | 123 | do { |
117 | #ifdef PRINT_TRIES_COUNT | 124 | #ifdef PRINT_TRIES_COUNT |
118 | tries ++; | 125 | tries ++; |
119 | #endif | 126 | #endif |
120 | crypto_box_keypair(public_key, secret_key); | 127 | crypto_box_keypair(public_key, secret_key); |
121 | } while (memcmp(p, desired_bin, len) != 0); | 128 | } while (memcmp(p, desired_bin, len) != 0); |
@@ -130,7 +137,7 @@ int main(int argc, char *argv[]) | |||
130 | fprintf(stdout, "\n"); | 137 | fprintf(stdout, "\n"); |
131 | 138 | ||
132 | #ifdef PRINT_TRIES_COUNT | 139 | #ifdef PRINT_TRIES_COUNT |
133 | fprintf(stdout, "Found the key pair on %llu try.\n", tries); | 140 | fprintf(stdout, "Found the key pair on %llu try.\n", tries); |
134 | #endif | 141 | #endif |
135 | 142 | ||
136 | return 0; | 143 | return 0; |