コード例 #1
0
ファイル: SODParser.cpp プロジェクト: 12019/svn.gov.pt
void SODParser::ParseSodEncapsulatedContent(const CByteArray & contents){
	ASN1_ITEM           xLev0Item;
	ASN1_ITEM           xLev1Item;
	ASN1_ITEM           xLev2Item;
	ASN1_ITEM           xLev3Item;
	ASN1_ITEM           xLev4Item;

	xLev0Item.p_data = (unsigned char*)contents.GetBytes();
	xLev0Item.l_data = contents.Size();

	if ((asn1_next_item(&xLev0Item, &xLev1Item)!= 0) ||(xLev1Item.tag != ASN_SEQUENCE))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

	if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_INTEGER))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

	if (bin2int(xLev2Item.p_data, xLev2Item.l_data)!=0)
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_VALUE);

	if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_SEQUENCE))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

	if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_OID))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

	// martinho: not the intended way, but for now it will do just fine.
	if (memcmp(xLev3Item.p_data, OID_SHA256_ALGORITHM, xLev3Item.l_data) != 0)
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ALGO_OID);

	if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_NULL))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

	if ((xLev1Item.l_data < 2)|| (asn1_next_item(&xLev1Item, &xLev2Item)!= 0) ||(xLev2Item.tag != ASN_SEQUENCE))
		throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);


	attr = new SODAttributes();
	int i=0;
	while(xLev2Item.l_data > 0){

		if ((xLev2Item.l_data < 2)|| (asn1_next_item(&xLev2Item, &xLev3Item)!= 0) ||(xLev3Item.tag != ASN_SEQUENCE))
			throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

		if ((xLev3Item.l_data < 2)|| (asn1_next_item(&xLev3Item, &xLev4Item)!= 0) ||(xLev4Item.tag != ASN_INTEGER))
			throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

		if (bin2int(xLev4Item.p_data, xLev4Item.l_data)!=(i+1))
			throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_VALUE);

		if ((xLev3Item.l_data < 2)|| (asn1_next_item(&xLev3Item, &xLev4Item)!= 0) ||(xLev4Item.tag != ASN_OCTET_STRING))
			throw CMWEXCEPTION(EIDMW_SOD_UNEXPECTED_ASN1_TAG);

		attr->hashes[i].Append(xLev4Item.p_data,xLev4Item.l_data);
		i++;
	}
}
コード例 #2
0
ファイル: tdav_codec_g729.c プロジェクト: Globik/doubango
/**
* Pack ITU bits into RTP stream
* @param ituBits ITU stream to pack (80 shorts)
* @param bitstream RTP bitstream (80 bits, 5 shorts, 10 bytes)
*/
static void pack_G729(const int16_t ituBits[], uint8_t bitstream[])
{  
    int16_t word16, i;
    for(i=0; i<5; i++){
        word16 = bin2int(16, (int16_t*)&ituBits[i*16]);
        bitstream[i*2] = word16>>8, bitstream[(i*2)+1] = (word16 & 0xFF);
    }
}
コード例 #3
0
ファイル: bits.c プロジェクト: Orange168/lumicall_new
/*----------------------------------------------------------------------------
 *  bits2prm_ld8k - converts serial received bits to  encoder parameter vector
 *----------------------------------------------------------------------------
 */
void bits2prm_ld8k(
 Word16 bits[],          /* input : serial bits (80)                       */
 Word16   prm[]          /* output: decoded parameters (11 parameters)     */
)
{
  Word16 i;
  Word16 nb_bits;

  nb_bits = *bits++;        /* Number of bits in this frame       */

  if(nb_bits == RATE_8000) {
    prm[1] = 1;
    for (i = 0; i < PRM_SIZE; i++) {
      prm[i+2] = bin2int(bitsno[i], bits);
      bits  += bitsno[i];
    }
  }
  else
#ifndef OCTET_TX_MODE
    if(nb_bits == RATE_SID) {
      prm[1] = 2;
      for (i = 0; i < 4; i++) {
        prm[i+2] = bin2int(bitsno2[i], bits);
        bits += bitsno2[i];
      }
    }
#else
  /* the last bit of the SID bit stream under octet mode will be discarded */
  if(nb_bits == RATE_SID_OCTET) {
    prm[1] = 2;
    for (i = 0; i < 4; i++) {
      prm[i+2] = bin2int(bitsno2[i], bits);
      bits += bitsno2[i];
    }
  }
#endif

  else {
    prm[1] = 0;
  }
  return;

}
コード例 #4
0
ファイル: BITS.C プロジェクト: shahid313/MSCourseWork
/*----------------------------------------------------------------------------
 *  bits2prm_ld8k - converts serial received bits to  encoder parameter vector
 *----------------------------------------------------------------------------
 */
void bits2prm_ld8k(
 Word16 bits[],            /* input : serial bits (80)                       */
 Word16   prm[]            /* output: decoded parameters (11 parameters)     */
)
{
   Word16 i;
   for (i = 0; i < PRM_SIZE; i++)
     {
        prm[i] = bin2int(bitsno[i], bits);
        bits  += bitsno[i];
     }

}
コード例 #5
0
ファイル: gp_processor.c プロジェクト: eusafe/libgate
int cb_get_poll_result(int reply) {
//	fprintf(stderr, "Run cb_get_poll_result for %d\n", send_mess.target );
	
	if( send_mess.target == AD_TARGET_GET_CID && receiv_mess.cmd_n == 0x04){
		uint64_t a=bin2int(receiv_mess.cmd_buff,receiv_mess.len,devices[receiv_mess.dev].cid_revert);
		if( devices[receiv_mess.dev].last_cid != a ) {
			devices[receiv_mess.dev].last_cid=a;
			devices[receiv_mess.dev].new_cid_flag=1;
		}
		return ad_get_regs(AD_Q_SHORT, receiv_mess.src);
 	} else if (send_mess.target == AD_TARGET_GET_REGS && receiv_mess.cmd_n == 0x06 ) {
 		gp_reg_cid_t* t=(gp_reg_cid_t*)receiv_mess.cmd_buff;
 		if( devices[receiv_mess.dev].new_cid_flag == 1 || devices[receiv_mess.dev].last_ev != t->ev ) {
// 			uint8_t t[20]= {'0','0','0','0'};
// 			int l=bin2hex(&t,&receiv_mess.cmd_buff,( (receiv_mess.len <= 6)? receiv_mess.len : 6), devices[receiv_mess.dev].cid_revert);

//	 		bin2hex(cid,t->cid,6,devices[receiv_mess.dev].cid_revert);
//			fprintf(stderr, "cid: 0x%12s, addr: %d, ev: %02x, src: %d\n", cid,t->addr,t->ev, receiv_mess.dev);

//			uint8_t cid[20];
//			long2hex(cid,devices[receiv_mess.dev].last_cid);
			
			zprintf(6,"dev=%d, ev=%02x, cid: 0x%016llX\n", receiv_mess.dev,  t->ev, devices[receiv_mess.dev].last_cid);
// новая карта!!!		
			if( (t->ev & ~1 ) == 0x02 ) {
				proc_add_cid_t tt = { 
					.dev = receiv_mess.dev,
					.subdev = t->ev & 1,
//					.cid = devices[receiv_mess.dev].last_cid,
					.ev = t->ev
				};

// TODO	 - check cid in  db, and if not found - added
				db_token_rec_t* token=db_get_token_by_c(devices[receiv_mess.dev].last_cid);
				if( token != NULL  ) {
					ad_turn_on(AD_Q_SECOND, tt.dev, tt.subdev);
					memcpy(&tt.token, token, sizeof(db_token_rec_t));
					if( cmd_add_cid(tt) == 0) {
						tt.token.addr=0;
						cmd_add_cid_to_all(tt);
					}
				} else {
					tt.token.cid = devices[receiv_mess.dev].last_cid;
					cb_push_new_cid_handler(tt);
				}
// TODO 				
			} else
			if( (t->ev & ~1 ) == 0x04 ) {
コード例 #6
0
ファイル: bits.c プロジェクト: cld820323/codec-g729
/*----------------------------------------------------------------------------
 *  bits2prm_ld8k - converts serial received bits to  encoder parameter vector
 *----------------------------------------------------------------------------
 */
void bits2prm_ld8k(
 Word16 bits[],          /* input : serial bits (80)                       */
 Word16   prm[]            /* output: decoded parameters (11 parameters)     */
)
{
   Word16 i,j=0;
   //for (i = 0; i < PRM_SIZE; i+=2)
   for (i = 0; i < PRM_SIZE; i++)
     {
        prm[i] = bin2int(bitsno[i], bits);
        bits  += bitsno[i];
	   //prm[i] = bits[j]&0xFF;
	   //prm[i+1] = bits[j++]>>8&0xFF;
     }

}
コード例 #7
0
ファイル: FanmotorDlg.cpp プロジェクト: ChenChengCC/test2
void CFanmotorDlg::dataupdate_anybits(int addr, int ind, CString datbits,int length)
{
		
	int temp,datupdated;
	CString datbintemp;
	temp = rreg(addr);
	if (!success){goto end;};
	datbintemp = int2bin(temp);

	for(int i = 0;i<length;i++){
		datbintemp.SetAt(ind+i,datbits[i]);
	}

	datupdated = bin2int(datbintemp);
	wreg(addr,datupdated);
	if (!success){goto end;};
    end:;
}
コード例 #8
0
ファイル: mux_8_1.cpp プロジェクト: 0x0mar/FHEAgainstHTH
LWE::CipherText mux_8_1(vector<LWE::CipherText> cipher_8, vector<int> sel_3, int en_n, LWE::SecretKey LWEsk, FHEW::EvalKey Ek)
{

	LWE::CipherText cipherEva;
	if(!en_n)
	{
		// Evaluation
		int pos = bin2int(sel_3);
		FHEW::HomNAND(&cipherEva, Ek, cipher_8[pos], cipher_8[pos]);
	}
	else
	{
		LWE::CipherText cipherOfZero;
		// Encrypt zero
		int data = 0;
		LWE::Encrypt(&cipherOfZero, LWEsk, 1 - data);
		FHEW::HomNAND(&cipherEva, Ek, cipherOfZero, cipherOfZero);
	}

	return cipherEva;
}
コード例 #9
0
ファイル: catvcd.c プロジェクト: nsauzede/catvcd
int main( int argc, char *argv[])
{
	FILE *in;
	char *fname = NULL;

	if (argc > 1)
	{
		fname = argv[1];
	}
	
	if (!fname)
	{
		printf( "Usage : %s filename.vcd\n", argv[0]);
		exit( -1);
	}
	in = fopen( fname, "rt");
	if (!in)
	{
		perror( "reading input file\n");
		exit( -1);
	}
	while (!feof( in))
	{
		static int state = 0;
		int i;
		char buf[1024], token[1024];
		
		fgets( buf, sizeof( buf), in);
		if (sscanf( buf, "%s", token) != 1)
		{
			if (state >= 2)
			{
				if (lastime != curtime)
				{
					lastime = curtime;
				printf( "time %6d:\t", curtime);
				for (i = 0; i < nsig; i++)
				{
					printf( "%02X ", sigs[i].value);
				}
				printf( "\n");
				}
			}
			
			continue;
		}
		if (!strcmp( token, "$var"))
		{
			char name[1024], title[1024];
			
			sscanf( buf, "%*s %*s %*s %s %s %*s", name, title);
			if (nsig < MAXSIG) {
				strncpy( sigs[nsig].name, name, sizeof( sigs[nsig].name));
				strncpy( sigs[nsig].title, title, sizeof( sigs[nsig].title));
				printf("added sig %d %s %s\n", nsig, name, title);
				nsig++;
			}
		}
		else if (!strcmp( token, "$dumpvars"))
		{
			state = 2;
		}
		else if (!strcmp( token, "$end"))
		{
			if (state == 2)
			{
				printf( "Found %d sigs :\t", nsig);
				for (i = 0; i < nsig; i++)
				{
//					printf( "%s ", sigs[i].name);
					printf( "%s ", sigs[i].title);
				}
				printf( "\n");
				curtime = 0;
				state = 3;
			}
		}
		else
		{
			if (state >= 2)
			{
				int val;
				char name[1024];
				
				if (token[0] == '#')
				{
					sscanf( token, "%*c%d", &curtime);
				}
				if (token[0] == 'b')
				{
					char v[1024];
					
					sscanf( buf, "b%s %s", v, name);
					val = bin2int( v);
//					printf( "Got name=%s bval=%d token=[%s]\n", name, val, token);
				}
				else
				{
					sscanf( token, "%1d%s", &val, name);
//					printf( "Got name=%s val=%d\n", name, val);
				}
				for (i = 0; i < nsig; i++)
				{
					if (!strcmp( sigs[i].name, name))
						sigs[i].value = val;
				}
			}
		}
	}
	fclose( in);
	
	return 0;
}
コード例 #10
0
ファイル: bitsf.c プロジェクト: SibghatullahSheikh/codecs
/*----------------------------------------------------------------------------
 *  bits2prm_ld8f - converts serial received bits to  encoder parameter vector
 *----------------------------------------------------------------------------
 */
void bits2prm_ld8f(
    Word16 bits[],  /* I   serial bits (nb_bits)                          */
    Word16 prm[]   /* O   output: decoded parameters (11 parameters)     */
)

{
    Word16 i;
    Word16 nb_bits;

    nb_bits = *bits++;        /* Number of bits in this frame       */

    switch(nb_bits){
        case RATE_0 : {        /* DTX: no bits transmitted */
            prm[1] = 0;
            break;
         }
                
#ifndef OCTET_TX_MODE
        case RATE_SID : {        /* SID: 15 bits (not in OCTET mode) */
            prm[1] = 1;
            for (i = 0; i < PRM_SIZE_SID; i++) {
                prm[i+2] = bin2int(bitsno2[i], bits);
                bits += bitsno2[i];
            }
            break;
        }
#else
            /* the last bit of the SID bit stream under octet mode will be discarded */
        case RATE_SID_OCTET : {        /* SID: 16 bits (OCTET mode) */
            prm[1] = 1;
            for (i = 0; i < PRM_SIZE_SID; i++) {
                prm[i+2] = bin2int(bitsno2[i], bits);
                bits += bitsno2[i];
            }
            break;
        }
#endif
        case RATE_6400 : {        /* G729 Annex D: 64 bits*/
            prm[1] = 2;
            for (i = 0; i < PRM_SIZE_6K; i++) {
                prm[i+2] = bin2int(bitsno_6k[i], bits);
                bits += bitsno_6k[i];
            }
            break;
        }
                
        case RATE_8000 : {        /* G729: 80 bits*/
            prm[1] = 3;
            for (i = 0; i < PRM_SIZE; i++) {
                prm[i+2] = bin2int(bitsno[i], bits);
                bits += bitsno[i];
            }
            break;
         }

        default : {
            printf("Unrecognized frame type: uncorrect value of serial_size\n");
            exit(-1);
        }
            
    }
        
    return;
}
コード例 #11
0
ファイル: bitsg.c プロジェクト: Orange168/lumicall_new
/*----------------------------------------------------------------------------
 *  bits2prm_ld8g - converts serial received bits to  encoder parameter vector
 *----------------------------------------------------------------------------
 */
void bits2prm_ld8g(
    Word16 bits[],  /* I   serial bits (nb_bits)                          */
    Word16 prm[]   /* O   output: decoded parameters (11 parameters)     */
)

{
    Word16 i;
    Word16 mode;
    Word16 parity_mode;

    Word16 nb_bits;

    nb_bits = *bits++;        /* Number of bits in this frame       */

    switch(nb_bits){
        case RATE_0 : {        /* DTX: no bits transmitted */
            prm[1] = 0;
            break;
         }

#ifndef OCTET_TX_MODE
        case RATE_SID : {        /* SID: 15 bits (not in OCTET mode) */
            prm[1] = 1;
            for (i = 0; i < PRM_SIZE_SID; i++) {
                prm[i+2] = bin2int(bitsno2[i], bits);
                bits += bitsno2[i];
            }
            break;
        }
#else
            /* the last bit of the SID bit stream under octet mode will be discarded */
        case RATE_SID_OCTET : {        /* SID: 16 bits (OCTET mode) */
            prm[1] = 1;
            for (i = 0; i < PRM_SIZE_SID; i++) {
                prm[i+2] = bin2int(bitsno2[i], bits);
                bits += bitsno2[i];
            }
            break;
        }
#endif
        case RATE_8000 : {        /* G729: 80 bits*/
            prm[1] = 3;
            for (i = 0; i < PRM_SIZE; i++) {
                prm[i+2] = bin2int(bitsno[i], bits);
                bits += bitsno[i];
            }
            break;
         }
                
        case RATE_11800 : {        /* G729 Annex E: 118 bits*/
            prm[1] = 4;

            if( *bits++ == BIT_0) {
                mode = 0;
            }
            else {
                mode = 1;
            }
            if( *bits++ == BIT_0) {
                parity_mode = 0;
            }
            else {
                parity_mode = 1;
            }
            
            if (mode != parity_mode) { /* ==> frame erased */
                for (i=0; i<RATE_11800-2; i++) bits[i] = 0;
            }

            prm[2] = mode;

            if (mode == 0) {
                for (i = 0; i < PRM_SIZE_E_fwd-1; i++) {
                    prm[i+3] = bin2int(bitsno_E_fwd[i], bits);
                    bits += bitsno_E_fwd[i];
                }
            }
            else {
                for (i = 0; i < PRM_SIZE_E_bwd-1; i++) {
                    prm[i+3] = bin2int(bitsno_E_bwd[i], bits);
                    bits += bitsno_E_bwd[i];
                }
            }
            break;
        }
                
        default : {
            printf("Unrecognized frame type: uncorrect value of serial_size\n");
            exit(-1);
        }
            
    }
        
    return;
}
コード例 #12
0
ファイル: tdav_codec_g729.c プロジェクト: Globik/doubango
/**
* Pack ITU bits containing SID frame as RTP stream
* @param ituBits ITU stream to pack
* @param bitstream RTP bitstream (15 bits, 1 short, 2 bytes)
*/
static void pack_SID(const int16_t ituBits[], uint8_t bitstream[])
{  
    int16_t word16 = bin2int(16, ituBits);
    bitstream[0] = word16>>8, bitstream[1] = (word16 & 0xFF);
}