word32 EncodeDSA_Signature(const Integer& r, const Integer& s, byte* output)
{
    word32 rSz = r.ByteCount();
    word32 sSz = s.ByteCount();

    byte rLen[MAX_LENGTH_SZ + 1];
    byte sLen[MAX_LENGTH_SZ + 1];

    rLen[0] = INTEGER;
    sLen[0] = INTEGER;

    word32 rLenSz = SetLength(rSz, &rLen[1]) + 1;
    word32 sLenSz = SetLength(sSz, &sLen[1]) + 1;

    byte seqArray[MAX_SEQ_SZ];

    word32 seqSz = SetSequence(rLenSz + rSz + sLenSz + sSz, seqArray);
    
    // seq
    memcpy(output, seqArray, seqSz);
    // r
    memcpy(output + seqSz, rLen, rLenSz);
    r.Encode(output + seqSz + rLenSz, rSz);
    // s
    memcpy(output + seqSz + rLenSz + rSz, sLen, sLenSz);
    s.Encode(output + seqSz + rLenSz + rSz + sLenSz, sSz);

    return seqSz + rLenSz + rSz + sLenSz + sSz;
}
Ejemplo n.º 2
0
void vec_GF2::SetMaxLength(long n)
{
   long oldlen = length();
   if (n > oldlen) {
      SetLength(n);
      SetLength(oldlen);
   }
}
Ejemplo n.º 3
0
//	AI MOVE
void	cMobKnight::AI_StatusMove	( D3DXVECTOR3 Pos )
{
	D3DXVec3Normalize( &m_vMonster_dir, &m_vMonster_dir );
	m_vMonster_dir *= m_Velocity;
	if( SetLength( Pos ) < 200.0f && SetLength( Pos ) > 23.0f && m_Status.ActionCansle == true )
	{
		MOVE();
		m_vPos.x += ( m_vMonster_dir.x );
		m_vPos.z += ( m_vMonster_dir.z );
	}
}
Ejemplo n.º 4
0
  void OBBond::SetLength(double length)
  {
    OBAtom *atom1 = GetBeginAtom();
    OBAtom *atom2 = GetEndAtom();

    //split the length difference in half, and modify the bond twice
    double firstLength = length + ((GetLength() - length) / 2);

    SetLength(atom1, firstLength);
    SetLength(atom2, length);
  }
Ejemplo n.º 5
0
Archivo: GText.cpp Proyecto: FEI17N/Lgi
bool TextDocument::Load(char *File)
{
	bool Status = FALSE;

	if (Open(File, O_READ))
	{
		int FileSize = F.GetSize();
		if (SetLength(FileSize))
		{
			F.Read(Data, FileSize);
			
			CrLf = FALSE;

			char *In = Data, *Out = Data;
			int Size = 0;
			for (int i=0; i<FileSize; i++, In++)
			{
				if (*In != '\r')
				{
					*Out++ = *In;
					Size++;
				}
				else
				{
					if (In[1] != '\n')
					{
						// Macintrash file
						*Out++ = '\n';
						Size++;
					}
					else
					{
						CrLf = TRUE;
					}
				}
			}

			Status = SetLength(Size);
			Data[Length] = 0;
			Lines = max(CountLines(Data), 1);
		}

		F.Close();
		Dirty = FALSE;
	}

	return Status;
}
Ejemplo n.º 6
0
void customOptionList::SetValue(int i, const char *format, ...)
{
	if(i >= length) SetLength(i+1);

	if(i >= 0 && i < length)
	{
		char *tmp=0;
		va_list va;
		va_start(va, format);
		vasprintf(&tmp, format, va);
		va_end(va);

		if(tmp)
		{
			if(value[i] && !strcmp(tmp, value[i]))
				free(tmp);
			else
			{
				free(value[i]);
				value[i] = tmp;
				changed = true;
			}
		}
	}
}
Ejemplo n.º 7
0
// writes ae desc data out to the stream
void CNewHandleStream::WriteAEDescData(
	const AEDesc	&inDesc)
{
	Size			byteCount=::AEGetDescDataSize(&inDesc);
	
	ExceptionCode	err = noErr;
	SInt32			endOfWrite = GetMarker() + byteCount;

	if (endOfWrite > GetLength()) {		// Need to grow Handle

		try {
			SetLength(endOfWrite);
		}

		catch (ExceptionCode inErr) {	// Grow failed. Write only what fits.
			byteCount = GetLength() - GetMarker();
			err = inErr;
		}

		catch (const LException& inException) {
			byteCount = GetLength() - GetMarker();
			err = inException.GetErrorCode();
		}
	}
										// Copy bytes into Handle
	if (byteCount > 0) {				//   Byte count will be zero if
										//   mDataH is nil
//		::BlockMoveData(inBuffer, *mDataH + GetMarker(), ioByteCount);
		UHandleLocker		locked(mDataH);
		err=::AEGetDescData(&inDesc,*mDataH + GetMarker(), byteCount);
		SetMarker(byteCount, streamFrom_Marker);
	}

	ThrowIfOSErr_(err);
}
Ejemplo n.º 8
0
//	시야 체크
void cMobKnight::SetLook( D3DXVECTOR3 Player_Pos )
{
	//	스테이터스가 DIE 상태일 경우
	if( m_Status.m_Status == STATUS_DIE )
	{
		m_cMobKnightController.SetRangeNoLoop(m_Status.StartFrame,
			m_Status.EndFrame,
			m_Status.StartFrame,
			m_Status.EndFrame,
			m_Status.PlayTime );
		return;
	}

	D3DXVECTOR3 vCross, m_vMonster_NewDir;

	m_vMonster_dir = ( Player_Pos - m_vPos );						//	적이 플레이어를 바라보는 방향

	D3DXVec3Normalize( &m_vMonster_NewDir, &m_vMonster_dir );		//	그 방향 정규화
	D3DXVec3Normalize( &m_vLook, &m_vLook);							//	현재 방향 정규화

	D3DXVec3Cross( &vCross, &m_vMonster_NewDir, &m_vLook );			//	적이 플레이어 바라보는 방향과 원래 방향으로 외적
	m_fDot	=	D3DXVec3Dot( &m_vMonster_NewDir, &m_vLook );
	m_fLen	=	D3DXVec3Length( &vCross );

	//	플레이어와 몬스터의 거리가 210.0f 안이고 몬스터가 현재 움직일 수 있는 상태일 경우
	if( SetLength( Player_Pos ) < 210.0f && m_Status.ActionCansle == true )
	{
		if( m_fDot < 0.99f )
		{
			m_fangle -= vCross.y*0.2f;			//	외적한 벡터의 y 마큼 회전 시킴
			yaw( -vCross.y*0.2f );
		}
	}

}
Ejemplo n.º 9
0
int CGString::ReadZ( CFile * pFile, int iLenMax )
{
	//@------------------------------------------------------------------------
	// PURPOSE:
	//  Read in a new string from an open MMSYSTEM file.
	// ARGS:
	//  hmmio = the open file.
	//  iLen = The length of the string to read. NOT THE NULL !
	// RETURN:
	//  <= 0 = error or no valid string.
	//  length of the string.
	//@------------------------------------------------------------------------

	if ( ! SetLength( iLenMax ))
		return( -1 );

	if ( pFile->Read( m_pchData, iLenMax ) != (DWORD) iLenMax )
		return( -1 );

	//
	// Make sure it is null terminated.
	//
	m_pchData[ iLenMax ] = '\0';
	return( iLenMax );
}
Ejemplo n.º 10
0
void CUtlString::TrimRight( const char *szTargets )
{
	const int nLastCharIndex = Length() - 1;
	int i;

	for( i = nLastCharIndex; i > 0; i-- )
	{
		bool bWhitespace = false;

		for( int j = 0; szTargets[j] != 0; j++ )
		{
			if ( m_pString[i] == szTargets[j] )
			{
				bWhitespace = true;
				break;
			}
		}

		if ( !bWhitespace )
		{
			break;
		}
	}

	// We have some whitespace to remove
	if ( i < nLastCharIndex )
	{
		m_pString[i + 1] = 0;
		SetLength( i + 2 );
	}
}
Ejemplo n.º 11
0
void CUtlString::TrimLeft( const char *szTargets )
{
	int i;

	if ( IsEmpty() )
	{
		return;
	}

	for( i = 0; m_pString[i] != 0; i++ )
	{
		bool bWhitespace = false;

		for( int j = 0; szTargets[j] != 0; j++ )
		{
			if ( m_pString[i] == szTargets[j] )
			{
				bWhitespace = true;
				break;
			}
		}

		if ( !bWhitespace )
		{
			break;
		}
	}

	// We have some whitespace to remove
	if ( i > 0 )
	{
		memcpy( m_pString, &m_pString[i], Length() - i );
		SetLength( Length() - i );
	}
}
Ejemplo n.º 12
0
void CHttpString::SetData(CString strData){
	int nLeft = str.Find("\r\n\r\n");
	str.Delete(nLeft + 4,str.GetLength() - nLeft - 4);
	str = str + strData;
	SetLength(strData.GetLength());
	return;
}
Ejemplo n.º 13
0
/**
*  @brief
*    Calculates a normalized projection vector
*/
Vector4 &Vector4::GetProjection(const Vector4 &vX, const Vector4 &vN)
{
	*this = vX + vN*(-vN.DotProduct(vX)/vN.DotProduct(vN));
	SetLength(1.0f);

	return *this;
}
Ejemplo n.º 14
0
bool ON_wString::UrlDecode()
{
  CopyArray();

  bool rc = true;
  wchar_t c;
  wchar_t* s0 = Array();
  if ( !s0 )
    return true;
  wchar_t* s1 = s0;
  //const wchar_t* debg = s1;
  int i;
  for (i = Length(); i > 0; i-- )
  {
    c = *s0++;
    if (0==c)
      break;
    if (i >= 3 && '%' == c && UrlDecodeHelper(s0) )
    {
      s0++;
      *s1++ = *s0++;
      i -= 2;
    }
    else
    {
      *s1++ = c;
      if (rc)
        rc = IsValidUrlChar(c);
    }
  }
  *s1 = 0;
  SetLength(s1 - Array());
  return rc;
}
void
nsACString::StripChars(const char *aSet)
{
  nsCString copy(*this);

  const char_type *source, *sourceEnd;
  copy.BeginReading(&source, &sourceEnd);

  char_type *dest;
  BeginWriting(&dest);
  if (!dest)
    return;

  char_type *curDest = dest;

  for (; source < sourceEnd; ++source) {
    const char *test;
    for (test = aSet; *test; ++test) {
      if (*source == char_type(*test))
        break;
    }

    if (!*test) {
      // not stripped, copy this char
      *curDest = *source;
      ++curDest;
    }
  }

  SetLength(curDest - dest);
}
Ejemplo n.º 16
0
int TString::cat_vprintf( const char* format, va_list args )
{
    int currentlen = Length();
    int len = vsnprintf( NULL, 0, format, args );
    SetLength( len + currentlen );
    return vsprintf( c_str() + currentlen, format, args );
}
Ejemplo n.º 17
0
Thruster::Thruster(GLdouble Length, GLdouble Radiust) {
  SetLength(Length);
  radiust = Radiust;
  inner = new Circle(32, radiust*0.6f);
  outer = new Circle(32, radiust);
  update_i = 0;
}
Ejemplo n.º 18
0
void ChannelMaskTlv::SetChannelMask(uint32_t aChannelMask)
{
    uint8_t           length = 0;
    ChannelMaskEntry *entry;

    entry = static_cast<ChannelMaskEntry *>(GetFirstEntry());

#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
    if (aChannelMask & OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK)
    {
        assert(entry != NULL);
        entry->Init();
        entry->SetChannelPage(OT_RADIO_CHANNEL_PAGE_2);
        entry->SetMask(aChannelMask & OT_RADIO_915MHZ_OQPSK_CHANNEL_MASK);

        length += sizeof(MeshCoP::ChannelMaskEntry);

        entry = static_cast<MeshCoP::ChannelMaskEntry *>(entry->GetNext());
    }
#endif

#if OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
    if (aChannelMask & OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK)
    {
        assert(entry != NULL);
        entry->Init();
        entry->SetChannelPage(OT_RADIO_CHANNEL_PAGE_0);
        entry->SetMask(aChannelMask & OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MASK);

        length += sizeof(MeshCoP::ChannelMaskEntry);
    }
#endif

    SetLength(length);
}
Ejemplo n.º 19
0
XBOOL XXVar::SetString(XPCTSTR strBuf, int l)
{
	if(nType!=XODT_STRING||nStringType!=STRING_REF)
	{
		Release();
		int nl=(l<<1)+sizeof(XSTRINGDATA)+1;
		if(nl<64) nl=64;
		XSTRINGDATA*pData=AllocBuffer(nl);
		if(pData==XNULL) 
			return XFALSE;
		strTxt=(XPTSTR)(pData+1);
		strTxt[l]=0;	
	}
	else 
	{
		if(!SetLength(l)) return XFALSE;
	}
	if(strBuf)
	{
		l=XMIN(l,(int)XString8::SafeStrlen(strBuf));
		XGlobal::Memcpy(strTxt,(void*)strBuf,l);
		strTxt[l]=0;
	}
	else l=0;
	GetData()->nLength=l;
	nType=XODT_STRING;
	nStringType=STRING_REF;
	return XTRUE;
}
Ejemplo n.º 20
0
void vec_GF2::FixLength(long n)
{
   if (MaxLength() > 0 || fixed()) LogicError("can't fix this vector");

   SetLength(n);
   _maxlen |= 1;
}
Ejemplo n.º 21
0
void Message::SetToken(const uint8_t *aToken, uint8_t aTokenLength)
{
    GetHelpData().mHeader.mVersionTypeToken = (GetHelpData().mHeader.mVersionTypeToken & ~kTokenLengthMask) |
                                              ((aTokenLength << kTokenLengthOffset) & kTokenLengthMask);
    memcpy(GetHelpData().mHeader.mToken, aToken, aTokenLength);
    GetHelpData().mHeaderLength += aTokenLength;
    SetLength(GetHelpData().mHeaderLength);
}
Ejemplo n.º 22
0
bool IStream::ReserveLeftSize(size_t size)
{
	if (size < LeftLength())
	{
		return true;
	}
	return SetLength(Position() + size);
}
Ejemplo n.º 23
0
bool IStream::ReserveSize(size_t size)
{
	if (size <= Length())
	{
		return true;
	}
	return SetLength(size);
}
Ejemplo n.º 24
0
// Push element to beginning of the array
global func ArrayUnshift(array &arr, elem) {
	var i=0, len = GetLength(arr);
	SetLength(arr, len + 1);
	while (i++ < len) {
		arr[i] = arr[i-1];
	}
	arr[0] = elem;
}
Ejemplo n.º 25
0
void CGString::Copy( LPCTSTR pszStr )
{
	if (( pszStr != m_pchData ) && pszStr )
	{
		SetLength(strlen(pszStr));
		strcpy(m_pchData, pszStr);
	}
}
Ejemplo n.º 26
0
void RT_MSG::Copy(const void * fromThisMemory, const unsigned int dataLength)
{
	SetLength(dataLength);
	if(dataLength > 0)
	{
		memcpy(GetDataAddress(),fromThisMemory,dataLength);
	}
}
Ejemplo n.º 27
0
void EbmlComposer::GenerateHeader()
{
  // Write the EBML header.
  EbmlGlobal ebml;
  // The WEbM header default size usually smaller than 1k.
  auto buffer = MakeUnique<uint8_t[]>(DEFAULT_HEADER_SIZE +
                                      mCodecPrivateData.Length());
  ebml.buf = buffer.get();
  ebml.offset = 0;
  writeHeader(&ebml);
  {
    EbmlLoc segEbmlLoc, ebmlLocseg, ebmlLoc;
    Ebml_StartSubElement(&ebml, &segEbmlLoc, Segment);
    {
      Ebml_StartSubElement(&ebml, &ebmlLocseg, SeekHead);
      // Todo: We don't know the exact sizes of encoded data and
      // ignore this section.
      Ebml_EndSubElement(&ebml, &ebmlLocseg);
      writeSegmentInformation(&ebml, &ebmlLoc, TIME_CODE_SCALE, 0);
      {
        EbmlLoc trackLoc;
        Ebml_StartSubElement(&ebml, &trackLoc, Tracks);
        {
          // Video
          if (mWidth > 0 && mHeight > 0) {
            writeVideoTrack(&ebml, 0x1, 0, "V_VP8",
                            mWidth, mHeight,
                            mDisplayWidth, mDisplayHeight, mFrameRate);
          }
          // Audio
          if (mCodecPrivateData.Length() > 0) {
            // Extract the pre-skip from mCodecPrivateData
            // then convert it to nanoseconds.
            // Details in OpusTrackEncoder.cpp.
            mCodecDelay =
              (uint64_t)LittleEndian::readUint16(mCodecPrivateData.Elements() + 10)
              * PR_NSEC_PER_SEC / 48000;
            // Fixed 80ms, convert into nanoseconds.
            uint64_t seekPreRoll = 80 * PR_NSEC_PER_MSEC;
            writeAudioTrack(&ebml, 0x2, 0x0, "A_OPUS", mSampleFreq,
                            mChannels, mCodecDelay, seekPreRoll,
                            mCodecPrivateData.Elements(),
                            mCodecPrivateData.Length());
          }
        }
        Ebml_EndSubElement(&ebml, &trackLoc);
      }
    }
    // The Recording length is unknown and
    // ignore write the whole Segment element size
  }
  MOZ_ASSERT(ebml.offset <= DEFAULT_HEADER_SIZE + mCodecPrivateData.Length(),
             "write more data > EBML_BUFFER_SIZE");
  auto block = mClusterBuffs.AppendElement();
  block->SetLength(ebml.offset);
  memcpy(block->Elements(), ebml.buf, ebml.offset);
  mFlushState |= FLUSH_METADATA;
}
Ejemplo n.º 28
0
//-----------------------------------------------------------------------------
EStatus BaseArray::SetMinLength (INT  iLengthIn)
  {
  // Make sure the lenght of the array is at least iLengthIn
  if (iLengthIn > Length ())
    {
    return (SetLength (iLengthIn));
    };
  return (EStatus::kSuccess);
  };
Ejemplo n.º 29
0
global func AddArray(array &aSource, array &aDestination)
{
  var s = GetLength(aSource);
  var d = GetLength(aDestination);
  SetLength(aDestination,d+s); 

  for(var j = 0; j < s; j++)
    aDestination[d+j] = aSource[j];
}
Ejemplo n.º 30
0
void RT_MSG::CopyMore(const void * fromThisMemory,unsigned int dataLength)
{
	unsigned int pos = GetLength();
	if(dataLength>0)
	{
		SetLength(GetLength()+dataLength);
		memcpy(&GetDataAddress()[pos],fromThisMemory,dataLength);
	}
}