Exemplo n.º 1
0
static int appserver_create_content(char **prefix, uint8_t *out)
{
    char buf[CCNL_RIOT_CHUNK_SIZE - 1];

    for (int i = 0; i < CCNL_RIOT_CHUNK_SIZE - 1; i++) {
        buf[i] = 'a' + i%26;
    }

    int len = mkContent(prefix, buf, CCNL_RIOT_CHUNK_SIZE - 1, out);
    return len;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
    unsigned char body[64*1024];
    unsigned char out[65*1024];
    unsigned char *publisher = 0;
    char *infname = 0, *outfname = 0;
    int i = 0, f, len, opt, plen;
    char *prefix[CCNL_MAX_NAME_COMP], *cp;
    
    private_key_path = 0;
    witness = 0;

    while ((opt = getopt(argc, argv, "hi:o:p:k:w:")) != -1) {
        switch (opt) {
        case 'i':
	    infname = optarg;
	    break;
        case 'o':
	    outfname = optarg;
	    break;
        case 'k':
            private_key_path = optarg;
            break;
        case 'w':
            witness = optarg;
            break;
        case 'p':
	    publisher = (unsigned char*)optarg;
	    plen = unescape_component(publisher);
	    if (plen != 32) {
		fprintf(stderr,
		 "publisher key digest has wrong length (%d instead of 32)\n",
		 plen);
		exit(-1);
	    }
	    break;
        case 'h':
        default:
Usage:
	    fprintf(stderr, "usage: %s [options] URI\n"
	    "  -i FNAME   input file (instead of stdin)\n"
	    "  -o FNAME   output file (instead of stdout)\n"
	    "  -p DIGEST  publisher fingerprint\n"
            "  -k FNAME   publisher private key\n"  
            "  -w STRING  witness\n"       ,
	    argv[0]);
	    exit(1);
        }
    }

    if (!argv[optind]) 
	goto Usage;
    cp = strtok(argv[optind], "/");
    while (i < (CCNL_MAX_NAME_COMP - 1) && cp) {
	prefix[i++] = cp;
	cp = strtok(NULL, "/");
    }
    prefix[i] = NULL;

    if (infname) {
	f = open(infname, O_RDONLY);
      if (f < 0)
	perror("file open:");
    } else
      f = 0;
    len = read(f, body, sizeof(body));
    close(f);

    len = mkContent(prefix, publisher, plen, body, len, out);

    if (outfname) {
	f = creat(outfname, 0666);
      if (f < 0)
	perror("file open:");
    } else
      f = 1;
    write(f, out, len);
    close(f);

    return 0;
}