Beispiel #1
0
int get_left_linked_read(string chain, tables& table, int delta){
    string r_t;
    int q = 0;
    int right_cut = 0;
    //Try to join and cut the chain on the right
    while(q <= delta){
        ::seqan::assign(r_t,::seqan::infix(chain,::seqan::length(chain)-2*delta+q,::seqan::length(chain)-delta+q));
        //std::cout << r_t << std::endl;
        hash_map::iterator l_it = table.left_map.find(fingerprint(r_t));
        if(l_it != table.left_map.end()){
            if((*l_it).second.half_spliced){
                string head;
                //::std::cout << delta-q << ::std::endl;
                assign(head,::seqan::prefix(chain,delta));
                //::std::cout << "CH R " << chain << ::std::endl;
                //::std::cout << "SE L " << ::seqan::prefix((*l_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << "  " << ::seqan::suffix((*l_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << ::std::endl;
                table_entry* t = (*l_it).second.p;
                while(t != NULL){
                    t->push_D_link(fingerprint(head));
                    t = t->get_l_next();
                }
                
                if(delta-q>right_cut){
                    //::std::cout << "UNO" << ::std::endl;
                    right_cut = delta-q;
                }
            }else{
                table_entry* t = (*l_it).second.p;
                while(t != NULL){
                    hash_map::iterator r_it = table.right_map.find(t->get_right_fingerprint());
                    if((*r_it).second.half_spliced){
                        string head;
                        //::std::cout << delta-q << ::std::endl;
                        //::std::cout << "CH R " << chain << ::std::endl;
                        //::std::cout << "SE R " << ::seqan::prefix((*r_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << "  " << ::seqan::suffix((*r_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << ::std::endl;
                        assign(head,::seqan::prefix(chain,delta));
                        //::std::cout << r_t << ::std::endl;
                        table_entry* right_t = (*r_it).second.p;
                        while(right_t != NULL){
                            if(fingerprint(r_t) == right_t->get_left_fingerprint()){
                                right_t->push_D_link(fingerprint(head));
                            }
                            right_t = right_t->get_r_next();
                        }
                        
                        if(delta-q>right_cut){
                            //::std::cout << "DUE" << ::std::endl;
                            right_cut = delta-q;
                        }
                    }
                    t = t-> get_l_next();
                }
            }
        }//End_If
        ++q;
    }//End_For
    return right_cut;
}//End_Method
Beispiel #2
0
int get_right_linked_read(string chain, tables& table, int delta){
    string l_t;
    int q = delta;
    int left_cut = 0;
    //Try to join and cut the chain on the left
    while(q >= 0){
        ::seqan::assign(l_t,::seqan::infix(chain,q,delta+q));
        //::std::cout << r_t << ::std::endl;
        hash_map::iterator r_it = table.right_map.find(fingerprint(l_t));
        if(r_it != table.right_map.end()){
            if((*r_it).second.half_spliced){
                string head;
                //::std::cout << q << ::std::endl;
                //::std::cout << "CH L " << chain << ::std::endl;
                //::std::cout << "R " << ::seqan::prefix((*r_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << "  " << ::seqan::suffix((*r_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << ::std::endl;
                assign(head,::seqan::prefix(chain,delta));
                table_entry* t = (*r_it).second.p;
                while(t != NULL){
                    t->push_A_link(fingerprint(head));
                    t = t->get_r_next();
 
                }
                if(q>left_cut){
                    //::std::cout << "TRE " << q << ::std::endl;
                    left_cut = q;
                }
            }else{
                table_entry* t = (*r_it).second.p;
                while(t != NULL){
                    hash_map::iterator l_it = table.left_map.find(t->get_left_fingerprint());
                    if((*l_it).second.half_spliced){
                        string head;
                        //::std::cout << q << ::std::endl;
                        //::std::cout << "CH L " << chain << ::std::endl;
                        //::std::cout << "L " << ::seqan::prefix((*l_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << "  " << ::seqan::suffix((*l_it).second.p->get_short_read()->get_RNA_seq_sequence(),delta) << ::std::endl;
                        assign(head,::seqan::prefix(chain,delta));
                        table_entry* left_t = (*l_it).second.p;
                        while(left_t != NULL){
                            if(fingerprint(l_t) == left_t->get_right_fingerprint()){
                                left_t->push_A_link(fingerprint(head));
                            }
                            left_t = left_t->get_l_next();
                        }
                        if(q>left_cut){
                            //::std::cout << "QUA " << q << ::std::endl;
                            left_cut = q;
                        }
                    }
                    t = t->get_r_next();
                }
            }
        }//End_If
        --q;
    }//End_While
    return left_cut;
}//End_Mehtod
Beispiel #3
0
BCW_API hd_private_key hd_private_key::generate_private_key(uint32_t i) const
{
    if (!valid_)
        return hd_private_key();

    data_chunk data;
    data.reserve(33 + 4);
    if (first_hardened_key <= i)
    {
        data.push_back(0x00);
        extend_data(data, k_);
        extend_data(data, to_big_endian(i));
    }
    else
    {
        extend_data(data, K_);
        extend_data(data, to_big_endian(i));
    }
    auto I = split(hmac_sha512_hash(data, to_data_chunk(c_)));

    // The child key ki is (parse256(IL) + kpar) mod n:
    ec_secret ki = k_;
    if (!ec_add(ki, I.L))
        return hd_private_key();

    hd_key_lineage lineage
    {
        lineage_.testnet,
        static_cast<uint8_t>(lineage_.depth + 1),
        fingerprint(),
        i
    };
    return hd_private_key(ki, I.R, lineage);
}
Beispiel #4
0
hd_private_key hd_private_key::generate_private_key(uint32_t i) const
{
    if (!valid_)
        return hd_private_key();

    data_chunk data;
    if (first_hardened_key <= i)
        data = build_data({to_byte(0x00), k_, to_big_endian(i)});
    else
        data = build_data({K_, to_big_endian(i)});
    const auto I = split(hmac_sha512_hash(data, c_));

    // The child key ki is (parse256(IL) + kpar) mod n:
    ec_secret ki = k_;
    if (!ec_add(ki, I.L))
        return hd_private_key();

    hd_key_lineage lineage
    {
        lineage_.testnet,
        static_cast<uint8_t>(lineage_.depth + 1),
        fingerprint(),
        i
    };
    return hd_private_key(ki, I.R, lineage);
}
Beispiel #5
0
BCW_API hd_public_key hd_public_key::generate_public_key(uint32_t i) const
{
    if (!valid_)
        return hd_private_key();
    if (first_hardened_key <= i)
        return hd_public_key();

    data_chunk data;
    data.reserve(33 + 4);
    extend_data(data, K_);
    extend_data(data, to_big_endian(i));
    auto I = split(hmac_sha512_hash(data, to_data_chunk(c_)));

    // The returned child key Ki is point(parse256(IL)) + Kpar.
    ec_point Ki = K_;
    if (!ec_tweak_add(Ki, I.L))
        return hd_public_key();

    hd_key_lineage lineage
    {
        lineage_.testnet,
        static_cast<uint8_t>(lineage_.depth + 1),
        fingerprint(), i
    };
    return hd_public_key(Ki, I.R, lineage);
}
Beispiel #6
0
void check_cutted_frags(CharString frag, std::vector<table_entry*> &links, 
                        map<unsigned long long, string> &chains, unsigned int min_length){
    if(length(frag) > min_length){
	
        std::queue<int> l_link;
        std::queue<int> r_link;
        Pattern<CharString, ShiftOr > pattern(frag);
        for(unsigned int i=0; i<links.size(); ++i){
            CharString text = links[i]->get_short_read()->get_RNA_seq_sequence();
            Finder<CharString> finder(text);
            find(finder,pattern);
            if(beginPosition(finder) < min_length){
                //std::cout << "L link " << i << ::std::endl;
                l_link.push(i);
            }
            if(endPosition(finder) > length(text) - min_length){
                //std::cout << "R link" << ::std::endl;
                r_link.push(i);
            }
        }
        
        if(l_link.size() != 0 && r_link.size() != 0){
            string head;
            assign(head,frag);
            for(unsigned int z=0; z<min_length*2 - length(frag);++z){
                head.append("A");
            }
	    if(chains.find(fingerprint(head)) == chains.end()){
            	chains[fingerprint(head)] = toCString(frag);
		//std::cerr << "CUT: " << frag << " " << length(frag) << std::endl;
	    }else{
		//std::cerr << "Problem:" << std::endl;
		//std::cerr << chains[fingerprint(head)] << std::endl;
		//std::cerr << toCString(frag) << std::endl;
	    }            
            //::std::cout << toCString(frag) << ::std::endl;
            while(!l_link.empty()){
                links[l_link.front()]->push_D_link(fingerprint(head));
                l_link.pop();
            }
            while(!r_link.empty()){
                links[r_link.front()]->push_A_link(fingerprint(head));
                r_link.pop();
            }
        }        
    }
}
Beispiel #7
0
int
parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
{
	int r;
	struct handler * h;
	vector cmdvec = NULL;
	struct timespec tmo;

	r = get_cmdvec(cmd, &cmdvec);

	if (r) {
		*reply = genhelp_handler(cmd, r);
		*len = strlen(*reply) + 1;
		return 0;
	}

	h = find_handler(fingerprint(cmdvec));

	if (!h || !h->fn) {
		*reply = genhelp_handler(cmd, EINVAL);
		*len = strlen(*reply) + 1;
		free_keys(cmdvec);
		return 0;
	}

	/*
	 * execute handler
	 */
	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
		tmo.tv_sec += timeout;
	} else {
		tmo.tv_sec = 0;
	}
	if (h->locked) {
		int locked = 0;
		struct vectors * vecs = (struct vectors *)data;

		pthread_cleanup_push(cleanup_lock, &vecs->lock);
		if (tmo.tv_sec) {
			r = timedlock(&vecs->lock, &tmo);
		} else {
			lock(&vecs->lock);
			r = 0;
		}
		if (r == 0) {
			locked = 1;
			pthread_testcancel();
			r = h->fn(cmdvec, reply, len, data);
		}
		pthread_cleanup_pop(locked);
	} else
		r = h->fn(cmdvec, reply, len, data);
	free_keys(cmdvec);

	return r;
}
// ----------------------------------------------------------------------------
// UntrustedCertificateInfoSymbian::Md5FingerprintL()
// ----------------------------------------------------------------------------
//
QByteArray UntrustedCertificateInfoSymbian::Md5FingerprintL( const TDesC8& aEncodedCert ) const
{
    CMD5* md5 = CMD5::NewL();
    CleanupStack::PushL( md5 );

    const TPtrC8 fingerprintSymbian = md5->Hash( aEncodedCert );
    QByteArray fingerprint( reinterpret_cast<const char*>( fingerprintSymbian.Ptr() ),
        fingerprintSymbian.Length() );

    CleanupStack::PopAndDestroy( md5 );
    return fingerprint;
}
Beispiel #9
0
	bool ca_moudle::process_csr_request(google::protobuf::Message* msg, connection_ptr connection, connection_manager&)
	{
		boost::lock_guard<boost::mutex> l(m_mutex);
		auto ca_con = m_ca_connection.lock();
		if (ca_con)
		{
			// 存入待回复表.
			ca_con->write_msg(encode(*msg));

			auto csr_request = dynamic_cast<proto::ca::csr_request*>(msg);
			m_user_cons.insert(std::make_pair(csr_request->fingerprint(), connection));
			return true;
		}
		return false;
	}
Beispiel #10
0
bool
SecureSocket::verifyCertFingerprint()
{
	// calculate received certificate fingerprint
	X509 *cert = cert = SSL_get_peer_certificate(m_ssl->m_ssl);
	EVP_MD* tempDigest;
	unsigned char tempFingerprint[EVP_MAX_MD_SIZE];
	unsigned int tempFingerprintLen;
	tempDigest = (EVP_MD*)EVP_sha1();
	int digestResult = X509_digest(cert, tempDigest, tempFingerprint, &tempFingerprintLen);

	if (digestResult <= 0) {
		LOG((CLOG_ERR "failed to calculate fingerprint, digest result: %d", digestResult));
		return false;
	}

	// format fingerprint into hexdecimal format with colon separator
	String fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
	formatFingerprint(fingerprint);
	LOG((CLOG_INFO "server fingerprint: %s", fingerprint.c_str()));

	String trustedServersFilename;
	trustedServersFilename = synergy::string::sprintf(
		"%s/%s/%s",
		ARCH->getProfileDirectory().c_str(),
		kFingerprintDirName,
		kFingerprintTrustedServersFilename);

	// check if this fingerprint exist
	String fileLine;
	std::ifstream file;
	file.open(trustedServersFilename.c_str());

	bool isValid = false;
	while (!file.eof() && file.is_open()) {
		getline(file,fileLine);
		if (!fileLine.empty()) {
			if (fileLine.compare(fingerprint) == 0) {
				isValid = true;
				break;
			}
		}
	}

	file.close();
	return isValid;
}
Beispiel #11
0
int parse_v4_public_key_packet(struct openPGP_packet *packet, struct openPGP_pubkey *key_result)
{
	int rslt = 0;


	#ifdef DEBUG
	fprintf(stderr,"Calling: parse_v4_public_key_packet\n");
	#endif

	if( (packet == NULL) || (key_result == NULL) )
	{
		return -1;
	}

        key_result->the_packet = packet;
        key_result->key_version = 0x04;
        key_result->creation_time = (packet->packet_data[1] << 24) + (packet->packet_data[2] << 16) + (packet->packet_data[3] << 8) + packet->packet_data[4];
        rslt = set_pk_algo_type(packet->packet_data[5], key_result->algo);
	if(rslt == -1)
	{
		fprintf(stderr,_("parse.c: parse_v4_pubkey_key_packet failed in call to set_pk_algo_type.\n"));

		return -1;
	}
        key_result->algo_id = packet->packet_data[5];
        key_result->key_size = (packet->packet_data[6] << 8) + packet->packet_data[7];
        rslt = fingerprint(&key_result->buffer[0], packet->packet_length+3, &key_result->fp[0]);
	if(rslt == -1)
	{
		fprintf(stderr,_("parse.c: parse_v4_pubkey_key_packet failed in call to fingerprint.\n"));

		return -1;
	}
        key_result->special_data[0] = 0x99;
        key_result->special_data[1] = key_result->buffer[1];
        key_result->special_data[2] = key_result->buffer[2];

        /*  I need to modify this code to account for nulls in the data. */
        snprintf(key_result->fp_db, 41, "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",key_result->fp[0],key_result->fp[1],key_result->fp[2],key_result->fp[3],key_result->fp[4],key_result->fp[5],key_result->fp[6],key_result->fp[7],key_result->fp[8],key_result->fp[9],key_result->fp[10],key_result->fp[11],key_result->fp[12],key_result->fp[13],key_result->fp[14],key_result->fp[15],key_result->fp[16],key_result->fp[17],key_result->fp[18],key_result->fp[19]);
        snprintf(key_result->fp_t, 61, "%.2X%.2X %.2X%.2X %.2X%.2X %.2X%.2X %.2X%.2X&nbsp;&nbsp;%.2X%.2X %.2X%.2X %.2X%.2X %.2X%.2X %.2X%.2X",key_result->fp[0],key_result->fp[1],key_result->fp[2],key_result->fp[3],key_result->fp[4],key_result->fp[5],key_result->fp[6],key_result->fp[7],key_result->fp[8],key_result->fp[9],key_result->fp[10],key_result->fp[11],key_result->fp[12],key_result->fp[13],key_result->fp[14],key_result->fp[15],key_result->fp[16],key_result->fp[17],key_result->fp[18],key_result->fp[19]);
        snprintf(key_result->keyid_t,9,"%.2X%.2X%.2X%.2X",key_result->fp[16],key_result->fp[17],key_result->fp[18],key_result->fp[19]);
        snprintf(key_result->fkeyid_t,17,"%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",key_result->fp[12],key_result->fp[13],key_result->fp[14],key_result->fp[15],key_result->fp[16],key_result->fp[17],key_result->fp[18],key_result->fp[19]);


	return 0;
}
Beispiel #12
0
	bool ca_moudle::process_csr_result(google::protobuf::Message* msg, connection_ptr, connection_manager&)
	{
		auto csr_reslt = dynamic_cast<proto::ca::csr_result*>(msg);

		auto fingerprint = csr_reslt->fingerprint();

		boost::lock_guard<boost::mutex> l(m_mutex);
		auto res_it = m_user_cons.find(fingerprint);
		if (res_it != m_user_cons.end())
		{
			proto::user_register_result register_result;
			register_result.set_result((proto::user_register_result::user_register_result_code)(int)csr_reslt->result());
			register_result.set_cert(csr_reslt->cert());
			res_it->second->write_msg(encode(register_result));
			m_user_cons.erase(res_it);
		}
		return true;
	}
// ----------------------------------------------------------------------------
// UntrustedCertificateInfoSymbian::certificateDetails()
// ----------------------------------------------------------------------------
//
QString UntrustedCertificateInfoSymbian::certificateDetails(const QString &siteName) const
{
    // TODO: localized UI string needed
    QString details = tr("Service:\n%1\n\nIssuer:\n%2\n\nSubject:\n%3\n\n"
        "Valid from:\n%4\n\nValid until:\n%5\n\nCertificate format:\n%6\n\n"
        "Algorithm:\n%7\n\nSerial number:\n%8\n\n"
        "Fingerprint (SHA1):\n%9\n\nFingerprint (MD5):\n%10")
        .arg(siteName)                                  // %1
        .arg(issuerName())                              // %2
        .arg(subjectName())                             // %3
        .arg(validFrom().toString())                    // %4
        .arg(validTo().toString())                      // %5
        .arg(format())                                  // %6
        .arg(combinedAlgorithmName())                   // %7
        .arg(formattedSerialNumber(serialNumber()))     // %8
        .arg(formattedFingerprint(fingerprint()))       // %9
        .arg(formattedFingerprint(mMd5Fingerprint));    // %10
    return details;
}
Beispiel #14
0
hd_public_key hd_public_key::generate_public_key(uint32_t i) const
{
    if (!valid_)
        return hd_private_key();
    if (first_hardened_key <= i)
        return hd_public_key();

    auto data = build_data({K_, to_big_endian(i)});
    const auto I = split(hmac_sha512_hash(data, c_));

    // The returned child key Ki is point(parse256(IL)) + Kpar.
    ec_point Ki = K_;
    if (!ec_add(Ki, I.L))
        return hd_public_key();

    hd_key_lineage lineage
    {
        lineage_.testnet,
        static_cast<uint8_t>(lineage_.depth + 1),
        fingerprint(), i
    };
    return hd_public_key(Ki, I.R, lineage);
}
Beispiel #15
0
uschar *
tls_cert_fprt_sha256(void * cert)
{
    return fingerprint((gnutls_x509_crt_t)cert, GNUTLS_DIG_SHA256);
}
Beispiel #16
0
uschar *
tls_cert_fprt_md5(void * cert)
{
    return fingerprint((gnutls_x509_crt_t)cert, GNUTLS_DIG_MD5);
}
Beispiel #17
0
/*
 * This is the readline completion handler
 */
char *
key_generator (const char * str, int state)
{
	static int index, len, has_param;
	static uint64_t rlfp;
	struct key * kw;
	int i;
	struct handler *h;
	vector v = NULL;

	if (!state) {
		index = 0;
		has_param = 0;
		rlfp = 0;
		len = strlen(str);
		int r = get_cmdvec(rl_line_buffer, &v);
		/*
		 * If a word completion is in progess, we don't want
		 * to take an exact keyword match in the fingerprint.
		 * For ex "show map[tab]" would validate "map" and discard
		 * "maps" as a valid candidate.
		 */
		if (v && len)
			vector_del_slot(v, VECTOR_SIZE(v) - 1);
		/*
		 * Clean up the mess if we dropped the last slot of a 1-slot
		 * vector
		 */
		if (v && !VECTOR_SIZE(v)) {
			vector_free(v);
			v = NULL;
		}
		/*
		 * If last keyword takes a param, don't even try to guess
		 */
		if (r == EINVAL) {
			has_param = 1;
			return (strdup("(value)"));
		}
		/*
		 * Compute a command fingerprint to find out possible completions.
		 * Once done, the vector is useless. Free it.
		 */
		if (v) {
			rlfp = fingerprint(v);
			free_keys(v);
		}
	}
	/*
	 * No more completions for parameter placeholder.
	 * Brave souls might try to add parameter completion by walking paths and
	 * multipaths vectors.
	 */
	if (has_param)
		return ((char *)NULL);
	/*
	 * Loop through keywords for completion candidates
	 */
	vector_foreach_slot_after (keys, kw, index) {
		if (!strncmp(kw->str, str, len)) {
			/*
			 * Discard keywords already in the command line
			 */
			if (key_match_fingerprint(kw, rlfp)) {
				struct key * curkw = find_key(str);
				if (!curkw || (curkw != kw))
					continue;
			}
			/*
			 * Discard keywords making syntax errors.
			 *
			 * nfp is the candidate fingerprint we try to
			 * validate against all known command fingerprints.
			 */
			uint64_t nfp = rlfp | kw->code;
			vector_foreach_slot(handlers, h, i) {
				if (!rlfp || ((h->fingerprint & nfp) == nfp)) {
					/*
					 * At least one full command is
					 * possible with this keyword :
					 * Consider it validated
					 */
					index++;
					return (strdup(kw->str));
				}
			}
		}
	}
	/*
	 * No more candidates
	 */
	return ((char *)NULL);
}
Beispiel #18
0
std::map<unsigned long long, unsigned long long> chain_back_merging(map<unsigned long long, string>& chains, int len){
    ::std::map<unsigned long long, unsigned long long> mapping;
    ::std::multimap<unsigned long long, unsigned long long> new_chains;
    ::std::map<unsigned long long, string>::iterator chain_it;
    //unsigned int c = 0;
    queue<unsigned long long> q;
    for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){
        mapping[chain_it->first] = chain_it->first;
        //c++;
        string tail;
        ::seqan::assign(tail,::seqan::suffix(chain_it->second,chain_it->second.length()-len));
        //::std::cout << c  << " " << tail << " " << tail.length() << ::std::endl;
        unsigned long long f_print = fingerprint(tail);
        if(new_chains.find(f_print) != new_chains.end()){
            multimap<unsigned long long, unsigned long long>::iterator it;
            pair<multimap<unsigned long long,unsigned long long>::iterator,
                multimap<unsigned long long,unsigned long long>::iterator> ret;
            ret = new_chains.equal_range(f_print);
            bool erased = false;
            for(it=ret.first; it!=ret.second; ++it){
                string dub = chains[it->second];
                if(dub.length() > chain_it->second.length()){
                    long diff = dub.length() - chain_it->second.length();
                    if(::seqan::suffix(dub,diff) == chain_it->second){
                        //::std::cout << "Merging 1 " << diff << ::std::endl;
                        //::std::cout << ::seqan::suffix(dub,diff) << ::std::endl;
                        //::std::cout << chain_it->second << ::std::endl;
                        q.push(chain_it->first);
                        erased = true;
                        mapping[chain_it->first] = chains.find(it->second)->first;
                    }
                }else{
                    long diff = chain_it->second.length() - dub.length();
                    if(::seqan::suffix(chain_it->second,diff) == dub){
                        //::std::cout << "Merging 2 " << diff << ::std::endl;
                        //::std::cout << ::seqan::suffix(chain_it->second,diff) << ::std::endl;
                        //::std::cout << dub << ::std::endl;
                        q.push(chains.find(it->second)->first);
                        erased = true;
                        mapping[chains.find(it->second)->first] = chain_it->first;
                    }
                }
            }
            if(!erased){
                new_chains.insert(pair<unsigned long long, unsigned long long>(f_print,chain_it->first));
            }
        }else{
            new_chains.insert(pair<unsigned long long, unsigned long long>(f_print,chain_it->first));
        }
    }
    while(!q.empty()){
        chains.erase(q.front());
        q.pop();
    }
    /*
    c=0;
    ::std::cout << ::std::endl;
    for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){
        c++;
        string tail;
        ::seqan::assign(tail,::seqan::suffix(chain_it->second,chain_it->second.length()-len));
        ::std::cout << c  << " " << tail << " " << tail.length() << ::std::endl;
    }
    */
    return mapping;
}
Beispiel #19
0
static int sign(const char *msgfile)
{
	struct seckey skey;
	struct sig sig = {
		.pkalg = "Ed",
	};
	struct stat st;
	char buf[512];
	void *pubkey = buf;
	long mlen;
	void *m;
	int mfd;

	if (!get_base64_file(seckeyfile, &skey, sizeof(skey), buf, sizeof(buf)) ||
	    memcmp(skey.pkalg, "Ed", 2) != 0) {
		fprintf(stderr, "Failed to decode secret key\n");
		return 1;
	}

	if (skey.kdfrounds) {
		fprintf(stderr, "Password protected secret keys are not supported\n");
		return 1;
	}

	mfd = open(msgfile, O_RDONLY, 0);
	if (mfd < 0 || fstat(mfd, &st) < 0 ||
		(m = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, mfd, 0)) == MAP_FAILED) {
		if (mfd >= 0)
			close(mfd);
		perror("Cannot open message file");
		return 1;
	}
	mlen = st.st_size;

	memcpy(sig.fingerprint, skey.fingerprint, sizeof(sig.fingerprint));
	edsign_sec_to_pub(pubkey, skey.seckey);
	edsign_sign(sig.sig, pubkey, skey.seckey, m, mlen);
	munmap(m, mlen);
	close(mfd);

	if (b64_encode(&sig, sizeof(sig), buf, sizeof(buf)) < 0)
		return 1;

	write_file(sigfile, sig.fingerprint, "signed by key", buf);

	return 0;
}

static int fingerprint(void)
{
	struct seckey skey;
	struct pubkey pkey;
	struct sig sig;
	char buf[512];
	uint8_t *fp;

	if (seckeyfile &&
	    get_base64_file(seckeyfile, &skey, sizeof(skey), buf, sizeof(buf)))
		fp = skey.fingerprint;
	else if (pubkeyfile &&
	         get_base64_file(pubkeyfile, &pkey, sizeof(pkey), buf, sizeof(buf)))
		fp = pkey.fingerprint;
	else if (sigfile &&
	         get_base64_file(sigfile, &sig, sizeof(sig), buf, sizeof(buf)))
		fp = sig.fingerprint;
	else
		return 1;

	fprintf(stdout, "%"PRIx64"\n", fingerprint_u64(fp));
	return 0;
}

static int generate(void)
{
	struct seckey skey = {
		.pkalg = "Ed",
		.kdfalg = "BK",
		.kdfrounds = 0,
	};
	struct pubkey pkey = {
		.pkalg = "Ed",
	};
	struct sha512_state s;
	char buf[512];
	FILE *f;

	f = fopen("/dev/urandom", "r");
	if (!f ||
	    fread(skey.fingerprint, sizeof(skey.fingerprint), 1, f) != 1 ||
	    fread(skey.seckey, EDSIGN_SECRET_KEY_SIZE, 1, f) != 1 ||
	    fread(skey.salt, sizeof(skey.salt), 1, f) != 1) {
		fprintf(stderr, "Can't read data from /dev/urandom\n");
		return 1;
	}
	if (f)
		fclose(f);

	ed25519_prepare(skey.seckey);
	edsign_sec_to_pub(skey.seckey + 32, skey.seckey);

	sha512_init(&s);
	sha512_add(&s, skey.seckey, sizeof(skey.seckey));
	memcpy(skey.checksum, sha512_final_get(&s), sizeof(skey.checksum));

	if (b64_encode(&skey, sizeof(skey), buf, sizeof(buf)) < 0)
		return 1;

	write_file(seckeyfile, skey.fingerprint, "public key", buf);

	memcpy(pkey.fingerprint, skey.fingerprint, sizeof(pkey.fingerprint));
	memcpy(pkey.pubkey, skey.seckey + 32, sizeof(pkey.pubkey));

	if (b64_encode(&pkey, sizeof(pkey), buf, sizeof(buf)) < 0)
		return 1;

	write_file(pubkeyfile, pkey.fingerprint, "private key", buf);

	return 0;
}

static int usage(const char *cmd)
{
	fprintf(stderr,
		"Usage: %s <command> <options>\n"
		"Commands:\n"
		"  -V:			verify (needs at least -m and -p|-P)\n"
		"  -S:			sign (needs at least -m and -s)\n"
		"  -F:			print key fingerprint of public/secret key or signature\n"
		"  -G:			generate a new keypair\n"
		"Options:\n"
		"  -c <comment>: 	add comment to keys\n"
		"  -m <file>:		message file\n"
		"  -p <file>:		public key file (verify/fingerprint only)\n"
		"  -P <path>:		public key directory (verify only)\n"
		"  -q:			quiet (do not print verification result, use return code only)\n"
		"  -s <file>:		secret key file (sign/fingerprint only)\n"
		"  -x <file>:		signature file (defaults to <message file>.sig)\n"
		"\n",
		cmd);
	return 1;
}

static void set_cmd(const char *prog, int val)
{
	if (cmd != CMD_NONE)
		exit(usage(prog));

	cmd = val;
}

int main(int argc, char **argv)
{
	const char *msgfile = NULL;
	int ch;

	while ((ch = getopt(argc, argv, "FGSVc:m:P:p:qs:x:")) != -1) {
		switch (ch) {
		case 'V':
			set_cmd(argv[0], CMD_VERIFY);
			break;
		case 'S':
			set_cmd(argv[0], CMD_SIGN);
			break;
		case 'F':
			set_cmd(argv[0], CMD_FINGERPRINT);
			break;
		case 'G':
			set_cmd(argv[0], CMD_GENERATE);
			break;
		case 'c':
			comment = optarg;
			break;
		case 'm':
			msgfile = optarg;
			break;
		case 'P':
			pubkeydir = optarg;
			break;
		case 'p':
			pubkeyfile = optarg;
			break;
		case 's':
			seckeyfile = optarg;
			break;
		case 'x':
			sigfile = optarg;
			break;
		case 'q':
			quiet = true;
			break;
		default:
			return usage(argv[0]);
		}
	}

	if (!sigfile && msgfile) {
		char *buf = alloca(strlen(msgfile) + 5);

		if (!strcmp(msgfile, "-")) {
			fprintf(stderr, "Need signature file when reading message from stdin\n");
			return 1;
		}

		sprintf(buf, "%s.sig", msgfile);
		sigfile = buf;
	}

	switch (cmd) {
	case CMD_VERIFY:
		if ((!pubkeyfile && !pubkeydir) || !msgfile)
			return usage(argv[0]);
		return verify(msgfile);
	case CMD_SIGN:
		if (!seckeyfile || !msgfile || !sigfile)
			return usage(argv[0]);
		return sign(msgfile);
	case CMD_FINGERPRINT:
		if (!!seckeyfile + !!pubkeyfile + !!sigfile != 1) {
			fprintf(stderr, "Need one secret/public key or signature\n");
			return usage(argv[0]);
		}
		return fingerprint();
	case CMD_GENERATE:
		if (!seckeyfile || !pubkeyfile)
			return usage(argv[0]);
		return generate();
	default:
		return usage(argv[0]);
	}
}
Beispiel #20
0
/**
 * First Panel - Meta Info
 * All the usual MetaData are displayed and can be changed.
 **/
MetaPanel::MetaPanel( QWidget *parent,
                      intf_thread_t *_p_intf )
                      : QWidget( parent ), p_intf( _p_intf )
{
    QGridLayout *metaLayout = new QGridLayout( this );
    metaLayout->setVerticalSpacing( 0 );

    QFont smallFont = QApplication::font();
    smallFont.setPointSize( smallFont.pointSize() - 1 );
    smallFont.setBold( true );

    int line = 0; /* Counter for GridLayout */
    p_input = NULL;
    QLabel *label;

#define ADD_META( string, widget, col, colspan ) {                        \
    label = new QLabel( qtr( string ) ); label->setFont( smallFont );     \
    label->setContentsMargins( 3, 2, 0, 0 );                              \
    metaLayout->addWidget( label, line++, col, 1, colspan );              \
    widget = new QLineEdit;                                               \
    metaLayout->addWidget( widget, line, col, 1, colspan );               \
    CONNECT( widget, textEdited( QString ), this, enterEditMode() );      \
}

    /* Title, artist and album*/
    ADD_META( VLC_META_TITLE, title_text, 0, 10 ); line++;
    ADD_META( VLC_META_ARTIST, artist_text, 0, 10 ); line++;
    ADD_META( VLC_META_ALBUM, collection_text, 0, 7 );

    /* Date */
    label = new QLabel( qtr( VLC_META_DATE ) );
    label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
    metaLayout->addWidget( label, line - 1, 7, 1, 2 );

    /* Date (Should be in years) */
    date_text = new QLineEdit;
    date_text->setAlignment( Qt::AlignRight );
    date_text->setInputMask("0000");
    date_text->setMaximumWidth( 140 );
    metaLayout->addWidget( date_text, line, 7, 1, -1 );
    line++;

    /* Genre Name */
    /* TODO List id3genres.h is not includable yet ? */
    ADD_META( VLC_META_GENRE, genre_text, 0, 7 );

    /* Number - on the same line */
    label = new QLabel( qtr( VLC_META_TRACK_NUMBER ) );
    label->setFont( smallFont ); label->setContentsMargins( 3, 2, 0, 0 );
    metaLayout->addWidget( label, line - 1, 7, 1, 3  );

    seqnum_text = new QLineEdit;
    seqnum_text->setMaximumWidth( 64 );
    seqnum_text->setAlignment( Qt::AlignRight );
    metaLayout->addWidget( seqnum_text, line, 7, 1, 1 );

    label = new QLabel( "/" ); label->setFont( smallFont );
    metaLayout->addWidget( label, line, 8, 1, 1 );

    seqtot_text = new QLineEdit;
    seqtot_text->setMaximumWidth( 64 );
    seqtot_text->setAlignment( Qt::AlignRight );
    metaLayout->addWidget( seqtot_text, line, 9, 1, 1 );
    line++;

    /* Rating - on the same line */
    /*
    metaLayout->addWidget( new QLabel( qtr( VLC_META_RATING ) ), line, 4, 1, 2 );
    rating_text = new QSpinBox; setSpinBounds( rating_text );
    metaLayout->addWidget( rating_text, line, 6, 1, 1 );
    */

    /* Now Playing - Useful for live feeds (HTTP, DVB, ETC...) */
    ADD_META( VLC_META_NOW_PLAYING, nowplaying_text, 0, 7 );
    nowplaying_text->setReadOnly( true ); line--;

    /* Language on the same line */
    ADD_META( VLC_META_LANGUAGE, language_text, 7, -1 ); line++;
    ADD_META( VLC_META_PUBLISHER, publisher_text, 0, 7 );

    fingerprintButton = new QPushButton( qtr("&Fingerprint") );
    fingerprintButton->setToolTip( qtr( "Find meta data using audio fingerprinting" ) );
    fingerprintButton->setVisible( false );
    metaLayout->addWidget( fingerprintButton, line, 7 , 3, -1 );
    CONNECT( fingerprintButton, clicked(), this, fingerprint() );

    line++;

    lblURL = new QLabel;
    lblURL->setOpenExternalLinks( true );
    lblURL->setTextFormat( Qt::RichText );
    metaLayout->addWidget( lblURL, line -1, 7, 1, -1 );

    ADD_META( VLC_META_COPYRIGHT, copyright_text, 0,  7 ); line++;

    /* ART_URL */
    art_cover = new CoverArtLabel( this, p_intf );
    metaLayout->addWidget( art_cover, line, 7, 6, 3, Qt::AlignLeft );

    ADD_META( VLC_META_ENCODED_BY, encodedby_text, 0, 7 ); line++;

    label = new QLabel( qtr( N_("Comments") ) ); label->setFont( smallFont );
    label->setContentsMargins( 3, 2, 0, 0 );
    metaLayout->addWidget( label, line++, 0, 1, 7 );
    description_text = new QTextEdit;
    description_text->setAcceptRichText( false );
    metaLayout->addWidget( description_text, line, 0, 1, 7 );
    // CONNECT( description_text, textChanged(), this, enterEditMode() ); //FIXME
    line++;

    /* VLC_META_SETTING: Useless */
    /* ADD_META( TRACKID )  Useless ? */
    /* ADD_URI - Do not show it, done outside */

    metaLayout->setColumnStretch( 1, 20 );
    metaLayout->setColumnMinimumWidth ( 1, 80 );
    metaLayout->setRowStretch( line, 10 );
#undef ADD_META

    CONNECT( seqnum_text, textEdited( QString ), this, enterEditMode() );
    CONNECT( seqtot_text, textEdited( QString ), this, enterEditMode() );

    CONNECT( date_text, textEdited( QString ), this, enterEditMode() );
//    CONNECT( THEMIM->getIM(), artChanged( QString ), this, enterEditMode() );
/*    CONNECT( rating_text, valueChanged( QString ), this, enterEditMode( QString ) );*/

    /* We are not yet in Edit Mode */
    b_inEditMode = false;
}
void small_blocks(::std::vector<table_entry*> & links, map<unsigned long long, string> &chains, unsigned int len,
                  map<unsigned long long, unsigned long long>& mapping){
    map<unsigned long long, string>::iterator ch_iter;
    ::std::vector<small_frag> short_blocks;
    stack<unsigned int> s;
    for(unsigned int i=0; i<links.size(); ++i){
        for(unsigned int j=0; j<links.size(); ++j){
            if(i!=j && links[i]->size_D_link() != 0 && links[i]->size_A_link() == 0
               && links[j]->size_D_link() == 0 && links[j]->size_A_link() != 0 ){
                
                string s1,s2;
                ::seqan::assign(s1,links[i]->get_short_read()->get_RNA_seq_sequence());
                ::seqan::assign(s2,links[j]->get_short_read()->get_RNA_seq_sequence());
                
		//Overlap between s1 and s2 grater or equal than s1/2
                unsigned int overlap = overlappedStringLength(s1,s2);
                
                if(overlap > 0 && overlap <= s1.length()/2){
                    assign(s2,::seqan::suffix(s2,overlap));
                    s1.append(s2);
                    //::std::cout << s1 << " " << s1.length() << ::std::endl;
                    small_frag f;
                    f.frag_links.D_chain = i;
                    f.frag_links.A_chain = j;
                    f.frag = ::seqan::infix(s1,len, s1.length() - len);
                    //::std::cout << overlap << " " << f.frag << " " << length(f.frag) << ::std::endl;
                    short_blocks.push_back(f);
                }
            }
        }
    }
    for(unsigned int i=0; i<short_blocks.size(); ++i){
        bool sub_seq = false;
        for(unsigned int k=0; k<short_blocks.size(); ++k){
            if(short_blocks[i].frag == short_blocks[k].frag && i>k){
                links_pair erased_links;
                erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                short_blocks[k].other_links.push_back(erased_links);
                sub_seq = true;
            }
            if(i!=k && (::seqan::length(short_blocks[i].frag)) > (::seqan::length(short_blocks[k].frag))){
                Finder<CharString> finder(short_blocks[i].frag);
                Pattern<CharString, ShiftAnd> pattern(short_blocks[k].frag);
                if(find(finder,pattern)){
                    links_pair erased_links;
                    erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                    erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                    //::std::cout << i << k << " - " << beginPosition(finder) << " " << endPosition(finder) << ::std::endl;
                    short_blocks[k].other_links.push_back(erased_links);
                    sub_seq = true;
                }
            }
        }
        if(sub_seq){
            s.push(i);
        }
    }
    
    while(!s.empty()){
        short_blocks.erase(short_blocks.begin()+s.top());
        s.pop();
    }

    for(unsigned int i=0; i<short_blocks.size(); ++i){
        //::std::cout << short_blocks[i].frag << " " << length(short_blocks[i].frag) << ::std::endl;
        string ch;
        assign(ch,::seqan::prefix(short_blocks[i].frag,len));
        //::std::cout << ch << " " << ch.length() << ::std::endl;
        if(chains.find(fingerprint(ch)) == chains.end()){
            chains[fingerprint(ch)] = ::seqan::toCString(short_blocks[i].frag);
            //::std::cout << ::seqan::toCString(short_blocks[i].frag) << " " << length(short_blocks[i].frag) << ::std::endl;
            mapping[fingerprint(ch)] = fingerprint(ch);
            links[short_blocks[i].frag_links.D_chain]->push_A_link(fingerprint(ch));
            links[short_blocks[i].frag_links.A_chain]->push_D_link(fingerprint(ch));
        }
        for(unsigned int j=0; j<short_blocks[i].other_links.size(); ++j){
            links[short_blocks[i].other_links[j].D_chain]->push_A_link(fingerprint(ch));
            links[short_blocks[i].other_links[j].A_chain]->push_D_link(fingerprint(ch));
        }
    }
}
void check_overlapping_nodes(::std::vector<table_entry*> & links, map<unsigned long long, string> & chains, int len,
                             ::std::map<unsigned long long, unsigned long long>& mapping, unsigned int min_overlap,
                             int ov_perc){
    ::std::map<unsigned long long, string>::iterator chain_it;
    ::std::map<unsigned long long, string>::iterator chain_it_2;
    ::std::vector<small_frag> short_blocks;
    stack<unsigned int> s;
    queue<unsigned long long> q;
    for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){
        for(chain_it_2 = chains.begin(); chain_it_2 != chains.end(); ++chain_it_2){
            unsigned int ov = overlappedStringLength(chain_it->second,chain_it_2->second);
            if(chain_it != chain_it_2 && ov < (ov_perc*chain_it->second.length())/100 &&
               (ov_perc*ov < chain_it_2->second.length())/100 && ov > min_overlap){
                bool new_node = false;
                CharString pat_text=prefix(chain_it_2->second,ov);
                //::std::cout << chain_it->second << ::std::endl;
                //::std::cout << chain_it_2->second << ::std::endl;
                //::std::cout << ov << ::std::endl;
                Pattern<CharString, ShiftAnd> pattern(pat_text);
                for(unsigned int i=0; i<links.size();++i){
                    CharString link_read = links[i]->get_short_read()->get_RNA_seq_sequence();
                    Finder<CharString> finder(link_read);
                    if(find(finder,pattern) && (
                       prefix(link_read,beginPosition(finder)) == infix(chain_it->second,chain_it->second.length()-ov-beginPosition(finder),chain_it->second.length()-ov) ||
                       suffix(link_read,length(link_read) - endPosition(finder)) == infix(chain_it_2->second,ov,ov+endPosition(finder)))){
                        //::std::cout << link_read << ::std::endl;
                        //::std::cout << prefix(link_read,beginPosition(finder)) << ::std::endl;
                        //::std::cout << infix(chain_it->second,chain_it->second.length()-ov-beginPosition(finder),chain_it->second.length()-ov) << ::std::endl;
                        //::std::cout << suffix(link_read,length(link_read) - endPosition(finder)) << ::std::endl;
                        //::std::cout << infix(chain_it_2->second,ov,ov+endPosition(finder)) << ::std::endl;
                      
                        new_node = true;
                    }
                }
                if(new_node){
                    small_frag f;
                    f.frag_links.D_chain = chain_it->first;
                    f.frag_links.A_chain = chain_it_2->first;
                    f.frag = prefix(chain_it_2->second,ov);
                    short_blocks.push_back(f);
                }
            }else{
                if(chain_it != chain_it_2 && ov>=(ov_perc*chain_it->second.length())/100){
                    //::std::cout << "Chain_it sub-node of Chain_it_2" << ::std::endl;
                    //::std::cout << "Chain_it " << chain_it->second << ::std::endl;
                    //::std::cout << "Chain_it_2 " << chain_it_2->second << ::std::endl;
                    //::std::cout << ov << ::std::endl;
                    q.push(chain_it->first);
                }else{
                    if(chain_it != chain_it_2 && ov>=(ov_perc*chain_it_2->second.length())/100){
                        //::std::cout << "Chain_it_2 sub-node of Chain_it" << ::std::endl;
                        //::std::cout << "Chain_it " << chain_it->second << ::std::endl;
                        //::std::cout << "Chain_it_2 " <<chain_it_2->second << ::std::endl;
                        //::std::cout << ov << ::std::endl;
                        q.push(chain_it_2->first);
                    }
                }
            }
        }
    }

    for(unsigned int i=0; i<short_blocks.size(); ++i){
        bool sub_seq = false;
        for(unsigned int k=0; k<short_blocks.size(); ++k){
            if(short_blocks[i].frag == short_blocks[k].frag && i<k){
                links_pair erased_links;
                erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                short_blocks[k].other_links.push_back(erased_links);
                sub_seq = true;
            }
            if(i!=k && (::seqan::length(short_blocks[i].frag)) < (::seqan::length(short_blocks[k].frag))){
                Finder<CharString> finder(short_blocks[k].frag);
                Pattern<CharString, ShiftAnd> pattern(short_blocks[i].frag);
                if(find(finder,pattern)){
                    links_pair erased_links;
                    erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                    erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                    //::std::cout << i << k << " - " << beginPosition(finder) << " " << endPosition(finder) << ::std::endl;
                    short_blocks[k].other_links.push_back(erased_links);
                    sub_seq = true;
                }
            }
        }
        if(sub_seq){
            s.push(i);
        }
    }

    while(!s.empty()){
        short_blocks.erase(short_blocks.begin()+s.top());
        s.pop();
    }
    while(!q.empty()){
        chains.erase(q.front());
        q.pop();
    }

    for(unsigned int i=0; i<short_blocks.size(); ++i){
        //::std::cout << short_blocks[i].frag << " " << length(short_blocks[i].frag) << ::std::endl; 
        string ch = "";
        for(unsigned int z = 0; z<len-length(short_blocks[i].frag); ++z){
            ch.append("A");
        }
        ch.append(toCString(short_blocks[i].frag));
        //if(chains.find(fingerprint(ch)) == chains.end()){//Start_If_5
            //chains[fingerprint(ch)] = ::seqan::toCString(short_blocks[i].frag);
            //::std::cout << ::seqan::toCString(short_blocks[i].frag) <<" "<< length(short_blocks[i].frag)<<::std::endl;
            //mapping[fingerprint(ch)] = fingerprint(ch);
            //Add the first link
            string first_half;
            assign(first_half,prefix(chains[short_blocks[i].frag_links.D_chain],len));
            string new_link_1 = first_half;
            new_link_1.append(ch);
            table_entry* link_1 = new table_entry(new_link_1,fingerprint(first_half),fingerprint(ch));
            link_1->push_D_link(short_blocks[i].frag_links.D_chain);
            link_1->push_A_link(short_blocks[i].frag_links.A_chain);
            links.push_back(link_1);
            /*
            //Add the second link
            string second_half;
            assign(second_half,prefix(chains[short_blocks[i].frag_links.A_chain],len));
            string new_link_2 = ch;
            new_link_2.append(second_half);
            table_entry* link_2 = new table_entry(new_link_2,fingerprint(ch),fingerprint(second_half));
            link_2->push_D_link(short_blocks[i].frag_links.D_chain);
            link_2->push_A_link(short_blocks[i].frag_links.A_chain);
            links.push_back(link_2);
            */
            //::std::cout<<links[short_blocks[i].frag_links.D_chain]->get_short_read()->get_RNA_seq_sequence()<<::std::endl;
            //::std::cout<<links[short_blocks[i].frag_links.A_chain]->get_short_read()->get_RNA_seq_sequence()<<::std::endl;

            for(unsigned int j=0; j<short_blocks[i].other_links.size(); ++j){//Start_For_6
                string second_half;
                assign(first_half,prefix(chains[short_blocks[i].other_links[j].D_chain],len));
                string new_link_2 = second_half;
                new_link_2.append(ch);
                table_entry* link_2 = new table_entry(new_link_2,fingerprint(second_half),fingerprint(ch));
                link_2->push_D_link(short_blocks[i].other_links[j].D_chain);
                link_2->push_A_link(short_blocks[i].other_links[j].A_chain);
                links.push_back(link_1);
            }//End_For_6
            //}//End_If_5
    }
}
void linking_refinement(::std::vector<table_entry*> & links, map<unsigned long long, string> & chains, unsigned int len,
                        ::std::map<unsigned long long, unsigned long long> & mapping){
    for(unsigned int i=0; i<links.size(); ++i){
        //Linkato solo a dx
        if(links[i]->size_D_link() == 0 && links[i]->size_A_link() != 0){
            //::std::cout << "D link" << ::std::endl;
            CharString p = ::seqan::prefix(links[i]->get_short_read()->get_RNA_seq_sequence(),len);
            Pattern<CharString, ShiftOr > pattern(p);
            ::std::map<unsigned long long, string>::iterator chain_it;
            ::std::set<unsigned long long> modif_chains;
            for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){ 
                
                CharString text = chain_it->second;
                Finder<CharString> finder(text);
                
                if(modif_chains.find(chain_it->first) == modif_chains.end() && find(finder,pattern)){
                    links[i]->push_D_link(chain_it->first);
                    if(chain_it->second.length()- endPosition(finder) > len){
                        //::std::cout << "D " << (i+1) << " " << beginPosition(finder) << ::std::endl;
                        CharString pre = ::seqan::prefix(chain_it->second, beginPosition(finder) + len);
                        string str_pre = ::seqan::toCString(pre);
                        CharString suf = ::seqan::suffix(chain_it->second, beginPosition(finder) + len);
                        string str_suf = ::seqan::toCString(suf);
                        //::std::cout << chain_it->second << " - " << chain_it->second.length() << ::std::endl;
                        //Sono sicuro che sia > len dato che la estraggo da un prefisso
                        //di lunghezza len...
                        chains[chain_it->first] = str_pre;
                        //::std::cout << str_pre << " - " << str_pre.length() << ::std::endl;
                        modif_chains.insert(chain_it->first);
                        //...ma il suffissopotrebbe essere piu' corto di len
                        string head;
                        if(str_suf.length() >= len){
                            head = ::seqan::toCString(::seqan::prefix(suf,len));
                            chains[fingerprint(head)] = str_suf;
                            mapping[fingerprint(head)] = fingerprint(head);
                        }else{
                            head = str_suf;
                            for(unsigned int z=0; z<len-str_suf.length();++z){
                                head.append("A");
                            }
                            chains[fingerprint(head)] = str_suf;
                            mapping[fingerprint(head)] = fingerprint(head);
                        }
                        //::std::cout << str_suf << " - " << str_suf.length() << ::std::endl << ::std::endl;
                        modif_chains.insert(fingerprint(head));
                        for(unsigned int z=0; z<links.size();++z){
                            for(int k=0; k<links[z]->size_D_link();++k){
                                if(links[z]->at_D_link(k) == chain_it->first){
                                    links[z]->at_D_link(k) = fingerprint(head);
                                }
                            }
                        }
                        //Aggiungere un link tra le due catene create
                        CharString l_part = chains[chain_it->first];
                        string new_link = ::seqan::toCString(::seqan::suffix(l_part,length(l_part) - len));
                        unsigned long long f_l = fingerprint(new_link);
                        new_link.append(head);
                        table_entry* t_new = new table_entry(new_link,f_l,fingerprint(head));
                        t_new->push_D_link(chain_it->first);
                        t_new->push_A_link(fingerprint(head));
                        links.push_back(t_new);
                    }
                }
            }
        }
        
        //Linkato solo a sx
        if(links[i]->size_A_link() == 0 && links[i]->size_D_link() != 0){
            //::std::cout << "A link" << ::std::endl;
            CharString p = ::seqan::suffix(links[i]->get_short_read()->get_RNA_seq_sequence(),len);
            Pattern<CharString, ShiftOr > pattern(p);
            ::std::map<unsigned long long, string>::iterator chain_it;
            ::std::set<unsigned long long> modif_chains;
            for(chain_it = chains.begin(); chain_it != chains.end(); ++chain_it){ 
                CharString text = chain_it->second;
                Finder<CharString> finder(text);
            
                if(modif_chains.find(chain_it->first) == modif_chains.end() && find(finder,pattern)){
                //if(find(finder,pattern)){
                    //::std::cout << "1 - if " << beginPosition(finder) << " " << endPosition(finder) << ::std::endl;
                    if(beginPosition(finder) == 0){
                        links[i]->push_A_link(chain_it->first);
                    }
                    if(endPosition(finder) > len){
                        //::std::cout << "A " << (i+1) << " " << beginPosition(finder) << ::std::endl;
                        CharString pre = ::seqan::prefix(chain_it->second, beginPosition(finder) + len);
                        string str_pre = ::seqan::toCString(pre);
                        CharString suf = ::seqan::suffix(chain_it->second, beginPosition(finder) + len);
                        string str_suf = ::seqan::toCString(suf);
                        chains[chain_it->first] = str_pre;
                        //::std::cout << str_pre << " - " << str_pre.length() << ::std::endl;
                        modif_chains.insert(chain_it->first);
                        string head;
                        if(str_suf.length() >= len){
                            head = ::seqan::toCString(::seqan::prefix(suf,len));
                            chains[fingerprint(head)] = str_suf;
                            mapping[fingerprint(head)] = fingerprint(head);
                        }else{
                            head = str_suf;
                            for(unsigned int z=0; z<len-str_suf.length();++z){
                                head.append("A");
                            }
                            chains[fingerprint(head)] = str_suf;
                            mapping[fingerprint(head)] = fingerprint(head);
                        }
                        //::std::cout << str_suf << " - " << str_suf.length() << ::std::endl << ::std::endl;
                        modif_chains.insert(fingerprint(head));
                        for(unsigned int z=0; z<links.size();++z){
                            for(int k=0; k<links[z]->size_D_link();++k){
                                if(links[z]->at_D_link(k) == chain_it->first){
                                    links[z]->at_D_link(k) = fingerprint(head);
                                }
                            }
                        }
                        //Aggiungere un link tra le due catene create
                        CharString l_part = chains[chain_it->first];
                        string new_link = ::seqan::toCString(::seqan::suffix(l_part,length(l_part) - len));
                        unsigned long long f_l = fingerprint(new_link);
                        new_link.append(head);
                        table_entry* t_new = new table_entry(new_link,f_l,fingerprint(head));
                        t_new->push_D_link(chain_it->first);
                        t_new->push_A_link(fingerprint(head));
                        links.push_back(t_new);

                        links[i]->push_A_link(fingerprint(head));
                    }
                }
            }
        }
    }
    //::std::cout << chains.size() << ::std::endl;
}
void tiny_blocks(::std::vector<table_entry*> & links, map<unsigned long long, string> &chains, int len,
                  map<unsigned long long, unsigned long long>& mapping){
    //map<unsigned long long, int> graph_nodes;
    map<unsigned long long, string>::iterator ch_iter;
    ::std::vector<small_frag> short_blocks;
    stack<unsigned int> s;

    //::std::cerr << "Link size: " << links.size() << ::std::endl;

    for(unsigned int i=0; i<links.size(); ++i){
        for(unsigned int j=0; j<links.size(); ++j){
            if(i!=j && links[i]->size_D_link() != 0 && links[j]->size_A_link() != 0){
               //&& links[j]->size_D_link() == 0 && links[j]->size_A_link() != 0 ){
                
                string s1,s2;
                ::seqan::assign(s1,links[i]->get_short_read()->get_RNA_seq_sequence());
                ::seqan::assign(s2,links[j]->get_short_read()->get_RNA_seq_sequence());
                
		//Overlap between s1 and s2 grater or equal than s1/2
                unsigned int overlap = overlappedStringLength(s1,s2);
                
                if(overlap > s1.length()/2 && overlap < s1.length()-6){
                    //::std::cout << s1 << ::std::endl;
                    //::std::cout << s2 << ::std::endl;
                    assign(s2,::seqan::suffix(s2,overlap));
                    s1.append(s2);
                    small_frag f;
                    f.frag_links.D_chain = i;
                    f.frag_links.A_chain = j;
                    f.frag = ::seqan::infix(s1,len, s1.length() - len);
                    //::std::cout << overlap << " " << f.frag << " " << length(f.frag) << ::std::endl;
                    short_blocks.push_back(f);
                }
            }
        }
        //::std::cerr << i << " ";
    }
    //::std::cerr << "Fine Primo Ciclo" << ::std::endl;
    //::std::cerr << "Short Blocks (initial) size: " << short_blocks.size() << ::std::endl;
    for(unsigned int i=0; i<short_blocks.size(); ++i){
        bool sub_seq = false;
        for(unsigned int k=0; k<short_blocks.size(); ++k){
            if(short_blocks[i].frag == short_blocks[k].frag && i<k){
                links_pair erased_links;
                erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                short_blocks[k].other_links.push_back(erased_links);
                sub_seq = true;
            }
            if(i!=k && (::seqan::length(short_blocks[i].frag)) < (::seqan::length(short_blocks[k].frag))){
                Finder<CharString> finder(short_blocks[k].frag);
                Pattern<CharString, ShiftAnd> pattern(short_blocks[i].frag);
                if(find(finder,pattern)){
                    links_pair erased_links;
                    erased_links.D_chain = short_blocks[i].frag_links.D_chain;
                    erased_links.A_chain = short_blocks[i].frag_links.A_chain;
                    //::std::cout << i << k << " - " << beginPosition(finder) << " " << endPosition(finder) << ::std::endl;
                    short_blocks[k].other_links.push_back(erased_links);
                    sub_seq = true;
                }
            }
        }
        if(sub_seq){
            s.push(i);
        }
    }
    
    while(!s.empty()){
        short_blocks.erase(short_blocks.begin()+s.top());
        s.pop();
    }
    //::std::cerr << "Fine Secondo Ciclo" << ::std::endl;
    //::std::cerr << "Short Blocks (final) size: " << short_blocks.size() << ::std::endl;
    for(unsigned int i=0; i<short_blocks.size(); ++i){//Start_For_1
        bool new_frag = true;
        Pattern<CharString, ShiftAnd> pattern(short_blocks[i].frag);
        for(ch_iter = chains.begin(); ch_iter != chains.end(); ++ch_iter){//Start_For_2
            if(ch_iter->second.length() > length(short_blocks[i].frag)){
                CharString ch_text = ch_iter->second;
                Finder<CharString> finder(ch_text);
                
                if(find(finder,pattern) ||
                   overlappedStringLength(ch_iter->second,toCString(short_blocks[i].frag))>length(short_blocks[i].frag)/2 ||
                   overlappedStringLength(toCString(short_blocks[i].frag),ch_iter->second)>length(short_blocks[i].frag)/2){//Start_If_3
                    new_frag = false;
                }//End_If_3
            }
        }//End_For_2
        
        
        if(new_frag){//Start_If_7
            //::std::cout << short_blocks[i].frag << " " << length(short_blocks[i].frag) << ::std::endl;
            string ch = "";
            for(unsigned int z = 0; z<len-length(short_blocks[i].frag); ++z){//Start_If_4
                ch.append("A");
            }//End_If_4
            ch.append(toCString(short_blocks[i].frag));
            //::std::cout << ch << " " << ch.length() << ::std::endl;
            if(chains.find(fingerprint(ch)) == chains.end()){//Start_If_5
                chains[fingerprint(ch)] = ::seqan::toCString(short_blocks[i].frag);
                //::std::cout << ::seqan::toCString(short_blocks[i].frag) <<" "<< length(short_blocks[i].frag)<<::std::endl;
                mapping[fingerprint(ch)] = fingerprint(ch);
                links[short_blocks[i].frag_links.D_chain]->push_A_link(fingerprint(ch));
                links[short_blocks[i].frag_links.A_chain]->push_D_link(fingerprint(ch));
                //::std::cout <<  links[short_blocks[i].frag_links.D_chain]->get_short_read()->get_RNA_seq_sequence() << ::std::endl;
                //::std::cout <<  links[short_blocks[i].frag_links.A_chain]->get_short_read()->get_RNA_seq_sequence() << ::std::endl;
                for(unsigned int j=0; j<short_blocks[i].other_links.size(); ++j){//Start_For_6
                    links[short_blocks[i].other_links[j].D_chain]->push_A_link(fingerprint(ch));
                    links[short_blocks[i].other_links[j].A_chain]->push_D_link(fingerprint(ch));
                }//End_For_6
            }//End_If_5
        }//End_If_7
    }//End_For_1
}//End_Method
Beispiel #25
0
static void
list_keyblock_print ( KBNODE keyblock, int secret )
{
    int rc = 0;
    KBNODE kbctx;
    KBNODE node;
    PKT_public_key *pk;
    PKT_secret_key *sk;
    u32 keyid[2];
    int any=0;

    /* get the keyid from the keyblock */
    node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
    if( !node ) {
	log_error("Oops; key lost!\n");
	dump_kbnode( keyblock );
	return;
    }

    if( secret ) {
	pk = NULL;
	sk = node->pkt->pkt.secret_key;
	keyid_from_sk( sk, keyid );
        printf("sec  %4u%c/%08lX %s ", nbits_from_sk( sk ),
				       pubkey_letter( sk->pubkey_algo ),
				       (ulong)keyid[1],
				       datestr_from_sk( sk ) );
    }
    else {
	pk = node->pkt->pkt.public_key;
	sk = NULL;
	keyid_from_pk( pk, keyid );
        printf("pub  %4u%c/%08lX %s ", nbits_from_pk( pk ),
				       pubkey_letter( pk->pubkey_algo ),
				       (ulong)keyid[1],
				       datestr_from_pk( pk ) );
    }

    for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
	if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
	    if( any ) 
                printf("uid%*s", 28, "");

            if ( node->pkt->pkt.user_id->is_revoked )
                fputs ("[revoked] ", stdout);
            print_utf8_string( stdout,  node->pkt->pkt.user_id->name,
                               node->pkt->pkt.user_id->len );
	    putchar('\n');
	    if( !any ) {
		if( opt.fingerprint )
		    fingerprint( pk, sk );
		if( opt.with_key_data )
		    print_key_data( pk, keyid );
		any = 1;
	    }
	}
	else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
	    u32 keyid2[2];
	    PKT_public_key *pk2 = node->pkt->pkt.public_key;

	    if( !any ) {
		putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk ); /* of the main key */
		any = 1;
	    }

	    keyid_from_pk( pk2, keyid2 );
            printf("sub  %4u%c/%08lX %s", nbits_from_pk( pk2 ),
                   pubkey_letter( pk2->pubkey_algo ),
                   (ulong)keyid2[1],
                   datestr_from_pk( pk2 ) );
            if( pk2->expiredate ) {
                printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
            }
            putchar('\n');
	    if( opt.fingerprint > 1 )
		fingerprint( pk2, NULL );
	    if( opt.with_key_data )
		print_key_data( pk2, keyid2 );
	}
	else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
	    u32 keyid2[2];
	    PKT_secret_key *sk2 = node->pkt->pkt.secret_key;

	    if( !any ) {
		putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk ); /* of the main key */
		any = 1;
	    }

	    keyid_from_sk( sk2, keyid2 );
            printf("ssb  %4u%c/%08lX %s\n", nbits_from_sk( sk2 ),
					   pubkey_letter( sk2->pubkey_algo ),
					   (ulong)keyid2[1],
					   datestr_from_sk( sk2 ) );
	    if( opt.fingerprint > 1 )
		fingerprint( NULL, sk2 );
	}
	else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
	    PKT_signature *sig = node->pkt->pkt.signature;
	    int sigrc;
            char *sigstr;

	    if( !any ) { /* no user id, (maybe a revocation follows)*/
		if( sig->sig_class == 0x20 )
		    puts("[revoked]");
		else if( sig->sig_class == 0x18 )
		    puts("[key binding]");
		else if( sig->sig_class == 0x28 )
		    puts("[subkey revoked]");
		else
		    putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk );
		any=1;
	    }

	    if( sig->sig_class == 0x20 || sig->sig_class == 0x28
				       || sig->sig_class == 0x30 )
	       sigstr = "rev";
	    else if( (sig->sig_class&~3) == 0x10 )
	       sigstr = "sig";
	    else if( sig->sig_class == 0x18 )
	       sigstr = "sig";
	    else {
                printf("sig                             "
		       "[unexpected signature class 0x%02x]\n",sig->sig_class );
		continue;
	    }
	    if( opt.check_sigs ) {
		fflush(stdout);
		rc = check_key_signature( keyblock, node, NULL );
		switch( rc ) {
		  case 0:		   sigrc = '!'; break;
		  case G10ERR_BAD_SIGN:    sigrc = '-'; break;
		  case G10ERR_NO_PUBKEY: 
		  case G10ERR_UNU_PUBKEY:  sigrc = '?'; break;
		  default:		   sigrc = '%'; break;
		}
	    }
	    else {
		rc = 0;
		sigrc = ' ';
	    }
            fputs( sigstr, stdout );
            printf("%c       %08lX %s  ",
		    sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig));
	    if( sigrc == '%' )
		printf("[%s] ", g10_errstr(rc) );
	    else if( sigrc == '?' )
		;
	    else if ( !opt.fast_list_mode ) {
		size_t n;
		char *p = get_user_id( sig->keyid, &n );
                print_utf8_string( stdout, p, n );
		m_free(p);
	    }
	    putchar('\n');
	    /* fixme: check or list other sigs here */
	}
    }
    putchar('\n');
}
Beispiel #26
0
int parse_v4_public_subkey(struct openPGP_packet *packet, struct openPGP_pubkey *key_result)
{
        struct openPGP_subkey *the_subkey = NULL;
        unsigned char *tmp_buffer = NULL;
	unsigned int debug_tmp_var = 0;
        int i =0;
        int j=3;
	int rslt = 0;

	#ifdef DEBUG
	fprintf(stderr,"Calling: parse_v4_public_subkey\n");
	#endif


        the_subkey = (struct openPGP_subkey *)malloc(sizeof(struct openPGP_subkey));
	if(the_subkey == NULL)
	{
		fprintf(stderr,_("parse.c: malloc call failed. unable to malloc subkey.\n"));
		key_result->key_status = -1;
		return -1;
	}
	rslt = init_openPGP_subkey(the_subkey);
	if(rslt == -1)
	{
		fprintf(stderr,_("parse.c: call to int_openPGP_subkey failed in parse_v4_public_subkey\n"));
		key_result->key_status = -1;

		return -1;
	}
        the_subkey->the_packet = packet;
        the_subkey->subkey_version = 0x04;
        the_subkey->algo_id = packet->packet_data[5];
        the_subkey->algo[0] = '\0';
	rslt = set_pk_algo_type(packet->packet_data[5],the_subkey->algo);
	if(rslt == -1)
	{
		fprintf(stderr,_("parse.c: call to set_pk_algo_type failed in parse_v4_public_subkey\n"));
		key_result->key_status = -1;
		/* TODO: Free the subkey */

		return -1;
	}
        the_subkey->keyid[0] = '\0';
        the_subkey->keyid_t[0] = '\0';
        the_subkey->creation_time = (packet->packet_data[1] << 24) + (packet->packet_data[2] << 16) + (packet->packet_data[3] << 8) + packet->packet_data[4];
        the_subkey->expiration_time = 0;
        the_subkey->fp[0] = '\0';
        the_subkey->key_size = (packet->packet_data[6] << 8) + packet->packet_data[7];

        tmp_buffer = (unsigned char *)malloc(packet->packet_length+4);
	if(tmp_buffer == NULL)
	{
		fprintf(stderr,_("parse.c: call to malloc failed in parse_v4_public_subkey\n"));
		key_result->key_status = -1;

		return -1;
	}
	/* FIXME This is wrong I think */
        tmp_buffer[0] = 0x99;
        tmp_buffer[1] = packet->pkt_len_d[0];
        tmp_buffer[2] = packet->pkt_len_d[1];
        tmp_buffer[3] = '\0';
        for(i = 0; i<packet->packet_length;i++)
        {
        	tmp_buffer[j] = packet->packet_data[i];
		j++;
        }

        debug_tmp_var =packet->packet_length +3;
        rslt = fingerprint(&tmp_buffer[0],debug_tmp_var, &the_subkey->fp[0]);
	if(rslt == -1)
	{
		fprintf(stderr,_("parse.c: call to fingerprint failed in parse_v4_public_subkey\n"));
		key_result->key_status = -1;
		if(tmp_buffer != NULL)
		{
			free(tmp_buffer);
		}

		return -1;
	}

        snprintf(the_subkey->keyid_t,9,"%.2X%.2X%.2X%.2X",the_subkey->fp[16],the_subkey->fp[17],the_subkey->fp[18],the_subkey->fp[19]);

        rslt = add_subkey(key_result,the_subkey);
	
	if(tmp_buffer != NULL)
		free(tmp_buffer);

	return rslt;
}
Beispiel #27
0
static void
list_keyblock_colon( KBNODE keyblock, int secret )
{
    int rc = 0;
    KBNODE kbctx;
    KBNODE node;
    PKT_public_key *pk;
    PKT_secret_key *sk;
    u32 keyid[2];
    int any=0;
    int trustletter = 0;
    int ulti_hack = 0;

    /* get the keyid from the keyblock */
    node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
    if( !node ) {
	log_error("Oops; key lost!\n");
	dump_kbnode( keyblock );
	return;
    }

    if( secret ) {
	pk = NULL;
	sk = node->pkt->pkt.secret_key;
	keyid_from_sk( sk, keyid );
        printf("sec:u:%u:%d:%08lX%08lX:%s:%s:::",
		    nbits_from_sk( sk ),
		    sk->pubkey_algo,
		    (ulong)keyid[0],(ulong)keyid[1],
		    colon_datestr_from_sk( sk ),
		    colon_strtime (sk->expiredate)
		    /* fixme: add LID here */ );
    }
    else {
	pk = node->pkt->pkt.public_key;
	sk = NULL;
	keyid_from_pk( pk, keyid );
        fputs( "pub:", stdout );
        trustletter = 0;
        if ( !pk->is_valid )
            putchar ('i');
        else if ( pk->is_revoked )
            putchar ('r');
        else if ( pk->has_expired )
            putchar ('e');
        else if ( opt.fast_list_mode || opt.no_expensive_trust_checks ) 
            ;
        else {
            trustletter = query_trust_info( pk, NULL );
            if( trustletter == 'u' )
                ulti_hack = 1;
            putchar(trustletter);
        }
        printf(":%u:%d:%08lX%08lX:%s:%s:",
		    nbits_from_pk( pk ),
		    pk->pubkey_algo,
		    (ulong)keyid[0],(ulong)keyid[1],
		    colon_datestr_from_pk( pk ),
		    colon_strtime (pk->expiredate) );
        if( pk->local_id )
            printf("%lu", pk->local_id );
        putchar(':');
        if( pk->local_id && !opt.fast_list_mode
            && !opt.no_expensive_trust_checks  )
            putchar( get_ownertrust_info( pk->local_id ) );
	    putchar(':');
    }
    
    if (opt.fixed_list_mode) {
        /* do not merge the first uid with the primary key */
        putchar(':');
        putchar(':');
        print_capabilities (pk, sk, keyblock);
        putchar('\n');
        if( opt.fingerprint )
            fingerprint( pk, sk );
        if( opt.with_key_data )
            print_key_data( pk, keyid );
        any = 1;
    }


    for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
	if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
            /*
             * Fixme: We need a is_valid flag here too 
             */
	    if( any ) {
                if ( node->pkt->pkt.user_id->is_revoked )
        	    printf("uid:r::::::::");
		else if ( opt.no_expensive_trust_checks ) {
        	    printf("uid:::::::::");
	        }
                else {
		    byte namehash[20];

		    if( pk && !ulti_hack ) {
			if( node->pkt->pkt.user_id->photo )
			    rmd160_hash_buffer( namehash,
					    node->pkt->pkt.user_id->photo,
					    node->pkt->pkt.user_id->photolen);
			else
			    rmd160_hash_buffer( namehash,
					    node->pkt->pkt.user_id->name,
					    node->pkt->pkt.user_id->len  );
			trustletter = query_trust_info( pk, namehash );
		    }
		    else
			trustletter = 'u';
		    printf("uid:%c::::::::", trustletter);
                }
	    }
            print_string( stdout,  node->pkt->pkt.user_id->name,
                          node->pkt->pkt.user_id->len, ':' );
            putchar(':');
	    if (any)
                putchar('\n');
            else {
                putchar(':');
                print_capabilities (pk, sk, keyblock);
                putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk );
		if( opt.with_key_data )
		    print_key_data( pk, keyid );
		any = 1;
	    }
	}
	else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
	    u32 keyid2[2];
	    PKT_public_key *pk2 = node->pkt->pkt.public_key;

	    if( !any ) {
                putchar(':');
                putchar(':');
                print_capabilities (pk, sk, keyblock);
                putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk ); /* of the main key */
		any = 1;
	    }

	    keyid_from_pk( pk2, keyid2 );
            fputs ("sub:", stdout );
            if ( !pk2->is_valid )
                putchar ('i');
            else if ( pk2->is_revoked )
                putchar ('r');
            else if ( pk2->has_expired )
                putchar ('e');
            else if ( opt.fast_list_mode || opt.no_expensive_trust_checks )
                ;
            else {
                printf("%c", trustletter );
            }
            printf(":%u:%d:%08lX%08lX:%s:%s:",
			nbits_from_pk( pk2 ),
			pk2->pubkey_algo,
			(ulong)keyid2[0],(ulong)keyid2[1],
			colon_datestr_from_pk( pk2 ),
			colon_strtime (pk2->expiredate)
			/* fixme: add LID and ownertrust here */
						);
            if( pk->local_id ) /* use the local_id of the main key??? */
                printf("%lu", pk->local_id );
            putchar(':');
            putchar(':');
            putchar(':');
            putchar(':');
            print_capabilities (pk2, NULL, NULL);
            putchar('\n');
	    if( opt.fingerprint > 1 )
		fingerprint( pk2, NULL );
	    if( opt.with_key_data )
		print_key_data( pk2, keyid2 );
	}
	else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
	    u32 keyid2[2];
	    PKT_secret_key *sk2 = node->pkt->pkt.secret_key;

	    if( !any ) {
                putchar(':');
                putchar(':');
                print_capabilities (pk, sk, keyblock);
		putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk ); /* of the main key */
		any = 1;
	    }

	    keyid_from_sk( sk2, keyid2 );
            printf("ssb::%u:%d:%08lX%08lX:%s:%s:::::",
			nbits_from_sk( sk2 ),
			sk2->pubkey_algo,
			(ulong)keyid2[0],(ulong)keyid2[1],
			colon_datestr_from_sk( sk2 ),
			colon_strtime (sk2->expiredate)
                   /* fixme: add LID */ );
            print_capabilities (NULL, sk2, NULL);
            putchar ('\n');
	    if( opt.fingerprint > 1 )
		fingerprint( NULL, sk2 );
	}
	else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
	    PKT_signature *sig = node->pkt->pkt.signature;
	    int sigrc;
            char *sigstr;

	    if( !any ) { /* no user id, (maybe a revocation follows)*/
		if( sig->sig_class == 0x20 )
		    fputs("[revoked]:", stdout);
		else if( sig->sig_class == 0x18 )
		    fputs("[key binding]:", stdout);
		else if( sig->sig_class == 0x28 )
		    fputs("[subkey revoked]:", stdout);
                else
                    putchar (':');
                putchar(':');
                print_capabilities (pk, sk, keyblock);
                putchar('\n');
		if( opt.fingerprint )
		    fingerprint( pk, sk );
		any=1;
	    }

	    if( sig->sig_class == 0x20 || sig->sig_class == 0x28
				       || sig->sig_class == 0x30 )
	       sigstr = "rev";
	    else if( (sig->sig_class&~3) == 0x10 )
	       sigstr = "sig";
	    else if( sig->sig_class == 0x18 )
	       sigstr = "sig";
	    else {
                printf("sig::::::::::%02x:\n",sig->sig_class );
		continue;
	    }
	    if( opt.check_sigs ) {
		fflush(stdout);
		rc = check_key_signature( keyblock, node, NULL );
		switch( rc ) {
		  case 0:		   sigrc = '!'; break;
		  case G10ERR_BAD_SIGN:    sigrc = '-'; break;
		  case G10ERR_NO_PUBKEY: 
		  case G10ERR_UNU_PUBKEY:  sigrc = '?'; break;
		  default:		   sigrc = '%'; break;
		}
	    }
	    else {
		rc = 0;
		sigrc = ' ';
	    }
            fputs( sigstr, stdout );
            putchar(':');
            if( sigrc != ' ' )
                putchar(sigrc);
            printf("::%d:%08lX%08lX:%s::::", sig->pubkey_algo,
						 (ulong)sig->keyid[0],
			   (ulong)sig->keyid[1], colon_datestr_from_sig(sig));
	    if( sigrc == '%' )
		printf("[%s] ", g10_errstr(rc) );
	    else if( sigrc == '?' )
		;
	    else if ( !opt.fast_list_mode ) {
		size_t n;
		char *p = get_user_id( sig->keyid, &n );
                print_string( stdout, p, n, ':' );
		m_free(p);
	    }
            printf(":%02x:\n", sig->sig_class );
	    /* fixme: check or list other sigs here */
	}
    }
    if( !any ) {/* oops, no user id */
        putchar(':');
        putchar(':');
        print_capabilities (pk, sk, keyblock);
	putchar('\n');
    }
}