/*!
  \brief   crc interface
  \return  1: CRC OK, 0: CRC check failure
*/
int SbrCrcCheck(HANDLE_FDK_BITSTREAM hBs, /*!< handle to bit-buffer  */
                LONG NrBits)              /*!< max. CRC length       */
{
  int crcResult = 1;
  ULONG NrCrcBits;
  ULONG crcCheckResult;
  LONG NrBitsAvailable;
  ULONG crcCheckSum;

  crcCheckSum = FDKreadBits(hBs, 10);

  NrBitsAvailable = FDKgetValidBits(hBs);
  if (NrBitsAvailable <= 0) {
    return 0;
  }

  NrCrcBits = fixMin((INT)NrBits, (INT)NrBitsAvailable);

  crcCheckResult = getCrc(hBs, NrCrcBits);
  FDKpushBack(hBs, (NrBitsAvailable - FDKgetValidBits(hBs)));

  if (crcCheckResult != crcCheckSum) {
    crcResult = 0;
  }

  return (crcResult);
}
void  MessageM::MakeMessageM(void* data,int size,std::vector<MessageM*>* msgCollecter,unsigned char mark,int msgType)
{
	//按3000字节计算
	int crc = getCrc();
	int total = (int)(std::ceil((double)size/(double)3000));
	int currentSize=0;
	int currentNum=0;
	if(size<3000)
	{
		MessageM* msg = new MessageM();
		msg->mark = mark;
		msg->crc = crc;
		msg->client_time = 0;
		msg->server_time = getServerTime();
		msg->msgType = msgType;
		msg->package_total =1;
		msg->size =size;		
		msg->message ->writeBytesChar((char*)data,0,size);
		msgCollecter->push_back(msg);
		return;
	}
	while(size!=currentSize)
	{
		MessageM * msg = new MessageM();
		msg->mark = mark;
		msg->crc = crc;
		msg->client_time = 0;
		msg->server_time = getServerTime();
		msg->msgType = msgType;
		msg->package_total =total;
		if(size-currentSize<=3000)
		{
			msg->size  =size - currentSize;
			currentSize += size -currentSize;
			msg->message->writeBytesChar((char*)data,currentSize,size-currentSize);
			msg->package_num = currentNum;
			currentNum+=1;

		}
		else
		{
			msg->message->writeBytesChar((char*)data,currentSize,3000);
			currentSize+=3000;
			msg->size =3000;
			msg->package_num = currentNum;
			currentNum+=1;
		}
		msgCollecter->push_back(msg);
	}
	if(currentNum!=total-1)
	{
		//报错
		std::cout<<"Error: Message total is wrong"<<std::endl;

	} 

}
Exemple #3
0
/*
  \brief   crc interface
  \return  1: CRC OK, 0: CRC check failure
*/
int
SbrCrcCheck (HANDLE_BIT_BUFFER hBitBuf,
             long NrBits)
{
  int crcResult = 1;
  BIT_BUFFER BitBufferCRC;
  unsigned long NrCrcBits;
  unsigned long crcCheckResult;
  long NrBitsAvailable;
  unsigned long crcCheckSum;

  FLC_sub_start("SbrCrcCheck");

  MOVE(1); /* counting previous operation */

  FUNC(2);
  crcCheckSum = getbits (hBitBuf, SI_SBR_CRC_BITS);

  PTR_INIT(1); FUNC(2);
  CopyBitbufferState (hBitBuf, &BitBufferCRC);


  PTR_INIT(1); FUNC(1);
  NrBitsAvailable = GetNrBitsAvailable(&BitBufferCRC);

  BRANCH(1);
  if (NrBitsAvailable <= 0){
    FLC_sub_end();
    return 0;
  }

  FUNC(2);
  NrCrcBits = min (NrBits, NrBitsAvailable);

  PTR_INIT(1); FUNC(2);
  crcCheckResult = getCrc (&BitBufferCRC, NrCrcBits);


  ADD(1); BRANCH(1);
  if (crcCheckResult != crcCheckSum) {
    MOVE(1);
    crcResult = 0;
  }

  FLC_sub_end();

  return crcResult;
}
/**
 * Save the key data in a JSON like format. The filename is specified in
 * constructor YubikoOtpKeyConfig::YubikoOtpKeyConfig(const string& )
 */
void YubikoOtpKeyConfig::save() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::save");
	const string myOutFile = checkFileName(true);
	ptree myTree;
	myTree.put(K_NM_DOC_PRIV_ID /*--->*/, getPrivateId());
	myTree.put(K_NM_DOC_PUB_ID /*---->*/, getPublicId());
	myTree.put(K_NM_DOC_SEC_KEY /*--->*/, getSecretKey());
	myTree.put(K_NM_DOC_TIMESTAMP /*->*/, getTimestamp().tstp_int);
	myTree.put(K_NM_DOC_SES_CNTR /*-->*/, getCounter());
	myTree.put(K_NM_DOC_CRC /*------->*/, getCrc());
	myTree.put(K_NM_DOC_RANDOM /*---->*/, getRandom());
	myTree.put(K_NM_DOC_USE_CNTR /*-->*/, getUseCounter());
	myTree.put(K_NM_DOC_DESC /*------>*/, getDescription());
	myTree.put(K_NM_DOC_SYS_USER /*-->*/, getSysUser());
	myTree.put(K_NM_DOC_VERS /*------>*/, K_VL_VERS);
	write_json(myOutFile, myTree);
	itsChangedFlag = false;
}
Exemple #5
0
void processDirectory(const QString &dir_old,
                      const QString &dir_new,
                      const QString &dir_result,
                      const QStringList &ignoreMasks)
{
  QDir qdir(dir_new, "", QDir::Name | QDir::IgnoreCase,
            QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);

  QFileInfoList files = qdir.entryInfoList();
  for (int i = 0; i < files.count(); ++i)
  {
    //qDebug() << files.at(i).absoluteFilePath();
    QFileInfo fi = files.at(i);

    // check for ignores
    bool ignore_this_file = false;
    for (int k = 0; k < ignoreMasks.size(); ++k)
    {
      QRegExp rx(ignoreMasks.at(k));
      rx.setPatternSyntax(QRegExp::Wildcard);
      if (rx.exactMatch(fi.fileName()))
      {
        ignore_this_file = true;
        break;
      }
    }
    if (ignore_this_file)
      continue;

    if (fi.isFile())
    {
      QDir qdir_old(dir_old);
      if(!qdir_old.exists(fi.fileName()))
      {
        CopyFile(dir_result, fi.absoluteFilePath());
      }
      else  // compare crc, if changed then copy
      {

        quint16 crc_new = getCrc(fi.absoluteFilePath());
        quint16 crc_old = getCrc(qdir_old.absoluteFilePath(fi.fileName()));
        log(QString("Comparing crc %1 = %2\n").arg(crc_old).arg(crc_new));
        if (crc_new == 0 || crc_old == 0)
          return;

        if (crc_new != crc_old)
        {
          CopyFile(dir_result, fi.absoluteFilePath());
        }
      }
    }
    else if (fi.isDir())
    {
      processDirectory(dir_old + "/" + fi.fileName(),
                       dir_new + "/" + fi.fileName(),
                       dir_result + "/" + fi.fileName(),
                       ignoreMasks);
      //*/
    }
  }
}