Rev 6 | Rev 10 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6 | Rev 7 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /*################################################################################# |
1 | /*################################################################################# |
2 | ### ### |
2 | ### ### |
3 | ### Object ID converter. Matthias Gaertner, 06/1999 ### |
3 | ### Object ID converter. Matthias Gaertner, 06/1999 ### |
4 | ### Converted to plain 'C' 07/2001 ### |
4 | ### Converted to plain 'C' 07/2001 ### |
5 | ### ### |
5 | ### ### |
6 | ### Enhanced version by Daniel Marschall, ViaThinkSoft 06-07/2011 ### |
6 | ### Enhanced version by Daniel Marschall, ViaThinkSoft 06-07/2011, 2022 ### |
7 | ### based on (or rather synchronized to) upstream version 1.3 ### |
7 | ### based on (or rather synchronized to) upstream version 1.3 ### |
8 | ### -- NEW in +viathinksoft2: 2.48 can also be encoded! ### |
8 | ### -- NEW in +viathinksoft2: 2.48 can also be encoded! ### |
9 | ### -- NEW in +viathinksoft2: UUIDs (128-bit) are now supported! ### |
9 | ### -- NEW in +viathinksoft2: UUIDs (128-bit) are now supported! ### |
10 | ### (requires GMPLib) ### |
10 | ### (requires GMPLib) ### |
11 | ### -- NEW in +viathinksoft3: Length can now have more than 1 byte ### |
11 | ### -- NEW in +viathinksoft3: Length can now have more than 1 byte ### |
Line 27... | Line 27... | ||
27 | ### ### |
27 | ### ### |
28 | ### Freeware - do with it whatever you want. ### |
28 | ### Freeware - do with it whatever you want. ### |
29 | ### Use at your own risk. No warranty of any kind. ### |
29 | ### Use at your own risk. No warranty of any kind. ### |
30 | ### ### |
30 | ### ### |
31 | #################################################################################*/ |
31 | #################################################################################*/ |
32 | /* $Version: 1.3+viathinksoft11$ */ |
32 | /* $Version: 1.3+viathinksoft12$ */ |
33 | 33 | ||
34 | // FUTURE |
34 | // FUTURE |
35 | // - Alles in Funktionen kapseln. Als Parameter: Array of integer (= dot notation) oder Array of byte (= hex notation) |
35 | // - Alles in Funktionen kapseln. Als Parameter: Array of integer (= dot notation) oder Array of byte (= hex notation) |
36 | 36 | ||
37 | // MINOR THINGS |
37 | // MINOR THINGS |
Line 46... | Line 46... | ||
46 | // - 2.9a9 is not recognized as error |
46 | // - 2.9a9 is not recognized as error |
47 | // - "./oid R 2.999" is not interpretet correctly |
47 | // - "./oid R 2.999" is not interpretet correctly |
48 | // - "./oid .2.999" will be interpreted as "0.2.999" |
48 | // - "./oid .2.999" will be interpreted as "0.2.999" |
49 | 49 | ||
50 | // NICE TO HAVE: |
50 | // NICE TO HAVE: |
51 | // - also allow -x to interpret "\x06\x02\x88\x37" and { 0x06, 0x02, 0x88, 0x37 } |
- | |
52 | // - makefile, manpage, linuxpackage |
51 | // - makefile, manpage, linuxpackage |
53 | // - better make functions instead of putting everything in main() with fprintf... |
52 | // - better make functions instead of putting everything in main() with fprintf... |
54 | 53 | ||
55 | // NICE TO HAVE (INFINITY-IDEA - NOT IMPORTANT): |
54 | // NICE TO HAVE (INFINITY-IDEA - NOT IMPORTANT): |
56 | // - Is it possible to detect integer overflows and therefore output errors? |
55 | // - Is it possible to detect integer overflows and therefore output errors? |
Line 172... | Line 171... | ||
172 | int nAfterOption = 0; |
171 | int nAfterOption = 0; |
173 | bool isRelative = false; |
172 | bool isRelative = false; |
174 | 173 | ||
175 | if (argc == 1) { |
174 | if (argc == 1) { |
176 | fprintf(stderr, |
175 | fprintf(stderr, |
177 | "OID encoder/decoder 1.3+viathinksoft11 - Matthias Gaertner 1999/2001, Daniel Marschall 2011/2012 - Freeware\n" |
176 | "OID encoder/decoder 1.3+viathinksoft12 - Matthias Gaertner 1999/2001, Daniel Marschall 2011/2012 - Freeware\n" |
178 | #ifdef is_gmp |
177 | #ifdef is_gmp |
179 | "GMP Edition (unlimited arc sizes)\n" |
178 | "GMP Edition (unlimited arc sizes)\n" |
180 | #else |
179 | #else |
181 | "%d-bit Edition (arc sizes are limited!)\n" |
180 | "%d-bit Edition (arc sizes are limited!)\n" |
182 | #endif |
181 | #endif |
Line 327... | Line 326... | ||
327 | p = abCommandLine; |
326 | p = abCommandLine; |
328 | 327 | ||
329 | while (*p) { |
328 | while (*p) { |
330 | unsigned char b; |
329 | unsigned char b; |
331 | 330 | ||
332 | // This allows also C-notation |
331 | // This allows also C-hexstring-notation |
333 | if ((p[0] == '\\') && (p[1] == 'x')) { |
332 | if ((p[0] == '\\') && (p[1] == 'x')) { |
334 | p += 2; |
333 | p += 2; |
335 | continue; |
334 | continue; |
336 | } |
335 | } |
337 | 336 | ||
- | 337 | // This allows also C-array-notation |
|
- | 338 | if ((p[0] == '0') && (p[1] == 'x')) { |
|
- | 339 | p += 2; |
|
- | 340 | continue; |
|
- | 341 | } |
|
- | 342 | if ((p[0] == ',') || (p[0] == '{') || (p[0] == '}') || (p[0] == ' ')) { |
|
- | 343 | p++; |
|
- | 344 | continue; |
|
- | 345 | } |
|
- | 346 | ||
338 | // Interpret upper nibble |
347 | // Interpret upper nibble |
339 | if (p[0] >= 'A' && p[0] <= 'F') { |
348 | if (p[0] >= 'A' && p[0] <= 'F') { |
340 | b = (p[0] - 'A' + 10) * 16; |
349 | b = (p[0] - 'A' + 10) * 16; |
341 | } else if (p[0] >= 'a' && p[0] <= 'f') { |
350 | } else if (p[0] >= 'a' && p[0] <= 'f') { |
342 | b = (p[0] - 'a' + 10) * 16; |
351 | b = (p[0] - 'a' + 10) * 16; |