Exemplo n.º 1
0
/** Generate a new certificate for our loaded or generated keys, and write it
 * to disk.  Return 0 on success, nonzero on failure. */
static int
generate_certificate(void)
{
  char buf[8192];
  time_t now = time(NULL);
  struct tm tm;
  char published[ISO_TIME_LEN+1];
  char expires[ISO_TIME_LEN+1];
  char fingerprint[FINGERPRINT_LEN+1];
  char *ident = key_to_string(identity_key);
  char *signing = key_to_string(signing_key);
  FILE *f;
  size_t signed_len;
  char digest[DIGEST_LEN];
  char signature[1024]; /* handles up to 8192-bit keys. */
  int r;

  get_fingerprint(identity_key, fingerprint);

  tor_localtime_r(&now, &tm);
  tm.tm_mon += months_lifetime;

  format_iso_time(published, now);
  format_iso_time(expires, mktime(&tm));

  tor_snprintf(buf, sizeof(buf),
               "dir-key-certificate-version 3"
               "%s%s"
               "\nfingerprint %s\n"
               "dir-key-published %s\n"
               "dir-key-expires %s\n"
               "dir-identity-key\n%s"
               "dir-signing-key\n%s"
               "dir-key-certification\n",
               address?"\ndir-address ":"", address?address:"",
               fingerprint, published, expires, ident, signing);
  tor_free(ident);
  tor_free(signing);
  signed_len = strlen(buf);
  SHA1((const unsigned char*)buf,signed_len,(unsigned char*)digest);

  r = RSA_private_encrypt(DIGEST_LEN, (unsigned char*)digest,
                          (unsigned char*)signature,
                          EVP_PKEY_get1_RSA(identity_key),
                          RSA_PKCS1_PADDING);
  strlcat(buf, "-----BEGIN SIGNATURE-----\n", sizeof(buf));
  signed_len = strlen(buf);
  base64_encode(buf+signed_len, sizeof(buf)-signed_len, signature, r);
  strlcat(buf, "-----END SIGNATURE-----\n", sizeof(buf));

  if (!(f = fopen(certificate_file, "w"))) {
    log_err(LD_GENERAL, "Couldn't open %s for writing: %s",
            certificate_file, strerror(errno));
    return 1;
  }

  fputs(buf, f);
  fclose(f);
  return 0;
}
Exemplo n.º 2
0
char *function_binding_to_string(xcWidget window, int function)
{
   keybinding *ksearch;
   char *retstr, *tmpstr;
   Bool first = True;

   retstr = (char *)malloc(1);
   retstr[0] = '\0';
   for (ksearch = keylist; ksearch != NULL; ksearch = ksearch->nextbinding) {
      if (function == ksearch->function) {
         if (ksearch->window == ALL_WINDOWS || ksearch->window == window) {
	    tmpstr = key_to_string(ksearch->keywstate);
	    if (tmpstr != NULL) {
	       retstr = (char *)realloc(retstr, strlen(retstr) + strlen(tmpstr) + 
		   ((first) ? 1 : 3));
	       if (!first) strcat(retstr, ", ");
	       strcat(retstr, tmpstr);
	       free(tmpstr);
	    }
	    first = False;
	 }
      }
   }
   if (retstr[0] == '\0') {
      retstr = (char *)realloc(retstr, 10);
      strcat(retstr, "<unbound>");
   }
   return(retstr);
}
Exemplo n.º 3
0
void Note::dump()
{
	INFOLOG( QString( "Note : pos: %1\t humanize offset%2\t instr: %3\t key: %4\t pitch: %5" )
			 .arg( __position )
			 .arg( __humanize_delay )
			 .arg( __instrument->get_name() )
			 .arg( key_to_string() )
			 .arg( __pitch )
			 .arg( __note_off )
		   );
}
Exemplo n.º 4
0
void Note::save_to( XMLNode* node )
{
	node->write_int( "position", __position );
	node->write_float( "leadlag", __lead_lag );
	node->write_float( "velocity", __velocity );
	node->write_float( "pan_L", __pan_l );
	node->write_float( "pan_R", __pan_r );
	node->write_float( "pitch", __pitch );
	node->write_string( "key", key_to_string() );
	node->write_int( "length", __length );
	node->write_int( "instrument", get_instrument()->get_id() );
	node->write_bool( "note_off", __note_off );
}
Exemplo n.º 5
0
void printeditbindings()
{
   char *tstr;

   _STR2[0] = '\0';

   tstr = key_to_string(firstbinding(areawin->area, XCF_Edit_Delete));
   strcat(_STR2, tstr);
   strcat(_STR2, "=");
   strcat(_STR2, func_to_string(XCF_Edit_Delete));
   strcat(_STR2, ", ");
   free(tstr);

   tstr = key_to_string(firstbinding(areawin->area, XCF_Edit_Insert));
   strcat(_STR2, tstr);
   strcat(_STR2, "=");
   strcat(_STR2, func_to_string(XCF_Edit_Insert));
   strcat(_STR2, ", ");
   free(tstr);

   tstr = key_to_string(firstbinding(areawin->area, XCF_Edit_Param));
   strcat(_STR2, tstr);
   strcat(_STR2, "=");
   strcat(_STR2, func_to_string(XCF_Edit_Param));
   strcat(_STR2, ", ");
   free(tstr);

   tstr = key_to_string(firstbinding(areawin->area, XCF_Edit_Next));
   strcat(_STR2, tstr);
   strcat(_STR2, "=");
   strcat(_STR2, func_to_string(XCF_Edit_Next));
   free(tstr);

   /* Use W3printf().  In the Tcl version, this prints to the	*/
   /* message window but does not duplicate the output to 	*/
   /* stdout, where it would be just an annoyance.		*/

   W3printf("%s", _STR2);
}
Exemplo n.º 6
0
String yl_data_point::to_string() const
{
	String result("{");
	String key = key_to_string();
	if (key.length())
	{
		result += key;
		result += ",";
	}
	result += "\"value\":";
	result += value_to_string();
	result += "}";

	return result;
}
Exemplo n.º 7
0
void printeditbindings()
{
   QString str;
   const int functions[] = { XCF_Edit_Delete, XCF_Edit_Insert, XCF_Edit_Param, XCF_Edit_Next };

   for (int i = 0; i < XtNumber(functions); ++ i)  {
       str = key_to_string(firstbinding(areawin->viewport, functions[i])) + "=";
       if (i < XtNumber(functions)-1) str += func_to_string(XCF_Edit_Delete) + ", ";
   }

   /* Use W3printf().  In the Tcl version, this prints to the	*/
   /* message window but does not duplicate the output to 	*/
   /* stdout, where it would be just an annoyance.		*/

   W3printf("%ls", str.utf16());
}
Exemplo n.º 8
0
QString function_binding_to_string(Widget window, int function)
{
   QString tmpstr, retstr;
   keybinding *ksearch;
   bool first = true;

   for (ksearch = keylist; ksearch != NULL; ksearch = ksearch->nextbinding) {
      if (function == ksearch->function) {
         if (ksearch->window == ALL_WINDOWS || ksearch->window == window) {
	    tmpstr = key_to_string(ksearch->keywstate);
            if (! tmpstr.isEmpty()) {
               if (!first) retstr += ", ";
               retstr += tmpstr;
	    }
	    first = false;
	 }
      }
   }
   if (retstr.isEmpty()) retstr = "<unbound>";
   return retstr;
}
Exemplo n.º 9
0
	std::string bucket::random_key_in_bucket(unsigned int bn) {
		std::bitset<KEY_SIZE> ret = string_to_key<KEY_SIZE>(local_key_);
		for (unsigned int i = bn; i < KEY_SIZE; ++i)
			ret[i] = (random() % 2) != 0;
		return key_to_string(ret);
	}
Exemplo n.º 10
0
int main(){
	
	printf("ok, it is done\n");
	lru_cache_t * lru;
	hash_map_t * hash_map;
	int res = hash_map_init(&hash_map, &simple_hash_function, &key_cmp_cbf, &key_free_cbf, & key_clone_cbf);
	printf("hash init result: %d\n", res);
	int rest = lru_cache_init(&lru, &simple_hash_function, &key_cmp_cbf, &key_free_cbf, &key_clone_cbf);
	printf("lru init result: %d\n", rest);
	lru_dump(lru, &value_to_string, &key_to_string);
	int i = 1;
	test_key_t key;
	test_value_t value;
	test_value_t * vp;
	int ret = 0;
	while(i){
		printf("0: quit\n1: insert\n2: lookup\n3: delete\nyour choice:");
		scanf("%d", &i);
		switch(i){
		case 1:
			printf("key:");
			scanf("%19s", key.key);
			printf("got key: %s\nvalue:", key.key);
			scanf("%19s", value.value);
			if(value.value[0] == '0') i=0;
			ret = lru_cache_insert(lru, (const void *)(&key), (const void *)(&value), &value_clone_cbf, &value_free_cbf); 
			if(!ret){
				printf("insert (%s, %s) failed", key.key, value.value);
			}
			break;
		case 3:
			ret = lru_delete_auto(lru);
			if(!ret){
				printf("delete failed\n");
			}
			break;
		case 2:
			printf("key:");
			scanf("%19s", key.key);
			ret = lru_cache_get(lru, (const void *) &key, (void **)(&vp));
			if(!ret || !vp){
				printf("key does not exist\n");
			}
			else{
				printf("key=%s, value=%s\n", key_to_string((const void *)&key), value_to_string((const void *)vp));
			}
			break;
		default:
			i = 0;
			break;
		}
		lru_dump(lru, value_to_string, key_to_string);
	}
	printf("quit cache; test hash map");
	i = 1;
	while(i){
		printf("0: quit\n1: insert\n2: lookup\n3: delete\nyour choice:");
		scanf("%d", &i);
		switch(i){
		case 1:
			printf("key:");
			scanf("%19s", key.key);
			printf("got key: %s\nvalue:", key.key);
			scanf("%19s", value.value);
			if(value.value[0] == '0') i=0;
			ret = hash_map_insert(hash_map, (const void *)(&key), (const void *)(&value), &value_clone_cbf, &value_free_cbf); 
			if(!ret){
				printf("insert (%s, %s) failed", key.key, value.value);
			}
			break;
		case 3:
			printf("key:");
			scanf("%19s", key.key);
			ret = hash_map_delete_entry(hash_map, (const void *) &key);
			if(!ret){
				printf("delete failed\n");
			}
			break;
		case 2:
			printf("key:");
			scanf("%19s", key.key);
			ret = hash_map_lookup(hash_map, (const void *) &key, (void **)(&vp));
			if(!ret || !vp){
				printf("key does not exist\n");
			}
			else{
				printf("key=%s, value=%s\n", key_to_string((const void *)&key), value_to_string((const void *)vp));
			}
			break;
		default:
			i = 0;
			break;
		}
		hash_map_dump(hash_map, &key_to_string, &value_to_string);
	}
	hash_map_fini(hash_map);
	printf("quit hash map\n");
	
	return 0;
}
Exemplo n.º 11
0
static VALUE t_random_key( VALUE self )
{
    SequenceKey key;
    GenerateRandomSequenceKey( &key );
    return key_to_string( &key );
}