util  Diff

Differences From Artifact [0502e2ccfd]:

To Artifact [20cdbef471]:


     1      1   /* [ʞ] soda - libsodium front end
     2      2    *  ~ lexi hale <lexi@hale.su>
     3      3    *  © AGPLv3
     4      4    *  @ vim: ft=c
            5  + *  ! ascii armor decoding is completely broken;
            6  + *    needs to be fixed before this program can
            7  + *    become usable
     5      8    */
     6      9   
     7     10   #define _POSIX_C_SOURCE 200809L
     8     11   #include <unistd.h>
     9     12   #include <stdio.h>
    10     13   #include <errno.h> /* boo hiss */
    11     14   #include <stdint.h>
................................................................................
   413    416   #undef _declflag_raw
   414    417   
   415    418   /* the casts here are a bit wacky. this is unfortunately necessary as C
   416    419    * insists on evaluating each branch of the generic expression regardless
   417    420    * of which type is picked. why anyone thought this was a good idea is
   418    421    * beyond me. */
   419    422   #define _t(x) (_Generic((x), \
   420         -	      const char**: (struct sayp){say_string_list, .strlist  = (const char**)(size_t)(x)}, \
   421         -	              char: (struct sayp){say_char,   .ch   = (char)(size_t)(x)}, \
   422         -	             char*: (struct sayp){say_string, .str  = (const char*)(size_t)(x)}, \
   423         -	       const char*: (struct sayp){say_string, .str  = (const char*)(size_t)(x)}, \
          423  +	      const char**: (struct sayp){say_string_list, .strlist  = (const char**)(intptr_t)(x)}, \
          424  +	              char: (struct sayp){say_char,   .ch   = (char)(intptr_t)(x)}, \
          425  +	             char*: (struct sayp){say_string, .str  = (const char*)(intptr_t)(x)}, \
          426  +	       const char*: (struct sayp){say_string, .str  = (const char*)(intptr_t)(x)}, \
   424    427   				   int: (struct sayp){say_sint,   .sint = (long long)(x)}, \
   425    428   	             short: (struct sayp){say_sint,   .sint = (long long)(x)}, \
   426    429   	              long: (struct sayp){say_sint,   .sint = (long long)(x)}, \
   427    430   	         long long: (struct sayp){say_sint,   .sint = (long long)(x)}, \
   428    431   		      unsigned: (struct sayp){say_uint,   .uint = (long long unsigned)(x)}, \
   429    432   	    unsigned short: (struct sayp){say_uint,   .uint = (long long unsigned)(x)}, \
   430    433   	     long unsigned: (struct sayp){say_uint,   .uint = (long long unsigned)(x)}, \
   431    434   	long long unsigned: (struct sayp){say_uint,   .uint = (long long unsigned)(x)}, \
   432         -	default: (struct sayp){say_hex, .uint = (size_t)(x)})),
          435  +	default: (struct sayp){say_hex, .uint = (intptr_t)(x)})),
   433    436   #define _say(k,...)  say(c, noise_##k, ((struct sayp[]){__VA_ARGS__ {say_stop}}))
   434    437   #define _report(k,s) _say(k, _t(s))
   435    438   
   436    439   void
   437    440   usage(struct ctx c, const struct cmd_spec* tree) {
   438    441   	const char* bin = c.bin;
   439    442   	const char* fmt_flag,* fmt_usage,* fmt_enum,* head_start,* head_fin;
................................................................................
   521    524   	"\x31\x32\00\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e"
   522    525   	"\00\00\00\00\x3f\00\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13"
   523    526   	"\x14\x15\x16\x17\00\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21"
   524    527   	"\x22";
   525    528   	/* generated by a script. do not touch. */
   526    529   
   527    530   enum { armor_split_every = 48 };
   528         -char*
   529         -armor(const unsigned char* src, char* dest, size_t sz, size_t brstart, bool format) {
          531  +
          532  +char* armor
          533  +(	char unsigned const* const src,
          534  +	char               * const dest,
          535  +	size_t               const sz,
          536  +	size_t               const brstart,
          537  +	bool                 const format
          538  +) {
   530    539   	char* bufptr = dest;
   531    540   	unsigned char carry = 0;
   532    541   	for(size_t i = 0; i<sz; ++i) {
   533    542   		/* insert line breaks every so many chars */
   534    543   		*(bufptr++)=ascii_armory[src[i] % 64];
   535    544   		if (format) if ((brstart + (bufptr - dest)) % armor_split_every == 0)
   536    545   			*(bufptr++)='\n', *(bufptr++)=' ';
................................................................................
   544    553   		if (format) if ((brstart + (bufptr - dest)) % armor_split_every == 0)
   545    554   			*(bufptr++)='\n', *(bufptr++)=' ';
   546    555   	}
   547    556   	/* if(carry != 0) */ *(bufptr++)=ascii_armory[carry];
   548    557   	return bufptr;
   549    558   }
   550    559   
   551         -char* disarmor(const unsigned char* src, char* dest, size_t sz) {
          560  +char* disarmor(char unsigned const* const src, char* dest, size_t const sz) {
   552    561   	/* transforms ascii armor into binary. can transform in place. */
   553    562   	for(size_t i = 0; i<sz; i += 3) {
   554    563   		while (isws(src[i])) ++i;
   555    564   		const char* s = src + i;
   556    565   		unsigned char carry = ascii_value[s[2] - '-'],
   557    566   			          b1    = ascii_value[s[0] - '-'] + (64 * ((carry & 12) >> 2)),
   558    567   		              b2    = ascii_value[s[1] - '-'] + (64 * ( carry &  3));
................................................................................
  1102   1111   		++ c.cmdc; ++ paramcount;
  1103   1112   	}
  1104   1113   	
  1105   1114   	parse_done: _say(debug, _t("stored") _t(c.cmdc) _t("arguments and") _t(paramcount) _t("parameters"));
  1106   1115   	
  1107   1116   	if (c.flags.noise <= noise_debug) for (size_t i = 0; i<c.cmdc; ++i) {
  1108   1117   		if (cmdlist[i] < _atom_n) {
  1109         -			dprintf(2, "\t%llu. atom %u (normal form “%s”)\n", i, cmdlist[i], reconstitute(cmdlist[i]));
         1118  +			dprintf(2, "\t%zu. atom %u (normal form “%s”)\n", i, cmdlist[i], reconstitute(cmdlist[i]));
  1110   1119   		} else {
  1111         -			dprintf(2,"\t%llu. parameter “%s”\n", i, paramlist[cmdlist[i] - _atom_n]);
         1120  +			dprintf(2,"\t%zu. parameter “%s”\n", i, paramlist[cmdlist[i] - _atom_n]);
  1112   1121   		}
  1113   1122   	}
  1114   1123   
  1115   1124   	if (c.flags.fmtv >= sz(write_privkey)) {
  1116   1125   		_say(fatal, _t("data format version") _t(c.flags.fmtv) _t("is not known. the highest available version is") _t(sz(write_privkey) - 1) _t("- are you sure you're using the latest release of " _self_name "?"));
  1117   1126   		return -2;
  1118   1127   	}