コード例 #1
0
AsnLen AsnBits::EncodeWithSizeConstraint (AsnBufBits &b)const
{
	AsnLen len = 0;
    int numSizeConstraints;
    const SizeConstraint* sizeConstraints = SizeConstraints(numSizeConstraints);
	int iSCLowerBound = sizeConstraints[0].lowerBound;
	int iSCUpperBound = iSCLowerBound;
	int minBitsNeeded = 0;
	int minBytesNeeded = 0;
	long Range = FindSizeConstraintBounds(iSCLowerBound, iSCUpperBound);
	long tempRange = Range - 1;
	long size = bitLen;
	unsigned char* temp = NULL;
	long tempLength = 0;
	unsigned char* pStr = new unsigned char[1];

	while(tempRange > 0)
	{
		tempRange -= (long)(1 << minBitsNeeded);
		minBitsNeeded += 1;
	}

	if(Range > 1)
	{
		if( (iSCUpperBound > 16) && b.IsAligned())
		{
			len += b.OctetAlignWrite();
		}

        if(size > iSCUpperBound)
        {
            size = iSCUpperBound;
        }

        if(size < iSCLowerBound)
        {
            size = iSCLowerBound;
        }

		minBytesNeeded = minBitsNeeded / 8;
		minBitsNeeded = minBitsNeeded % 8;
		size -= iSCLowerBound;

		if(minBytesNeeded > 0)
		{
			pStr[0] = (unsigned char)(size >> minBitsNeeded);
			len += b.PutBits(pStr, 8);
		}

		pStr[0] = (unsigned char)size;
		pStr[0] <<= 8 - minBitsNeeded;
		len += b.PutBits(pStr, minBitsNeeded);
	}
コード例 #2
0
ファイル: asn-stringtype.cpp プロジェクト: esnacc/esnacc-ng
AsnLen AsnString::EncodeWithSizeConstraint(AsnBufBits &b)const
{
    FUNC("AsnString::EncodeWithSizeConstraint");

    AsnLen len = 0;
    int B = numBits();
    int B2 = findB2(B);
    int numSizeConstraints;
    const SizeConstraint* sizeConstraints = SizeConstraints(numSizeConstraints);
    int iSCLowerBound = sizeConstraints[0].lowerBound;
    int iSCUpperBound = iSCLowerBound;
    int minBitsNeeded = 0;
    int minBytesNeeded = 0;
    long Range = FindSizeConstraintBounds(iSCLowerBound, iSCUpperBound);
    long tempRange = Range - 1;
    long size = length();
    long count = 0;
    unsigned char* pStr = new unsigned char[1];

    while(tempRange > 0)
    {
        tempRange -= (long)(1 << minBitsNeeded);
        minBitsNeeded += 1;
    }

    if(size < iSCLowerBound || size > iSCUpperBound)
    {
        delete [] pStr;
        throw EXCEPT("String size not withing restricted bounds", RESTRICTED_TYPE_ERROR);
    }


    if(Range > 1)
    {
        if( ((iSCUpperBound * B2) > 16) && b.IsAligned())
        {
            len += b.OctetAlignWrite();
        }

        minBytesNeeded = minBitsNeeded / 8;
        minBitsNeeded = minBitsNeeded % 8;
        size -= iSCLowerBound;

        if(minBytesNeeded > 0)
        {
            pStr[0] = (unsigned char)(size >> minBitsNeeded);
            len += b.PutBits(pStr, 8);
        }

        pStr[0] = (unsigned char)size;
        pStr[0] <<= 8 - minBitsNeeded;
        len += b.PutBits(pStr, minBitsNeeded);
    }
コード例 #3
0
AsnLen AsnBits::EncodeGeneral(AsnBufBits &b)const
{
	AsnLen len = 0;
	unsigned long l_64kFrag = l_16k * 4;
	unsigned long count = 0;
	unsigned long x = 0;
	unsigned long tempLen = encLen();
	unsigned char ch = 0x00;
	unsigned char *c = NULL;
	long offset = 0;

	if(tempLen >= l_16k)
	{	
		/*there is more than 16k bits of data*/
		count = (tempLen / l_64kFrag);
		
		for(x=0; x < count; x++)
		{  
			len += b.OctetAlignWrite();
			
			len += PEncLen_16kFragment(b, 4);
				
			len += b.OctetAlignWrite();
			
			len += b.PutBits((unsigned char*)&bits[offset / 8], l_64kFrag);
			
			offset += l_64kFrag;
		}

		tempLen -= count * l_64kFrag;

		count = tempLen / l_16k;

		if(count != 0)
		{  
			len += b.OctetAlignWrite();
			
			len += PEncLen_16kFragment(b, count);
		
			len += b.OctetAlignWrite();
						
			len += b.PutBits((unsigned char*)&bits[offset / 8], (count * l_16k) );

			offset += (count * l_16k);
		}
		
		tempLen -=  (l_16k * count);

		if(tempLen == 0)
		{
			ch = 0x00;
			c = &ch;
			
			len += b.OctetAlignWrite();

			len += b.PutBits(c, 8);
			
			return len;
		}
	}

	/*if there are less than 128 bits of data*/
	if(tempLen < 128)
	{
		len += b.OctetAlignWrite();

		len += PEncDefLenTo127(b, tempLen);
		
		len += b.OctetAlignWrite();

		len += b.PutBits((unsigned char*)&bits[offset / 8], tempLen);

		offset += tempLen;
	}
	else if(tempLen >= 128 && tempLen < l_16k)
	{
		len += b.OctetAlignWrite();
		/*if there is less than 16k bits of data*/
		/*and more than 127 bits of data*/
		len += PEncLen_1to16k(b, tempLen);
		
		len += b.OctetAlignWrite();
		
		len += b.PutBits((unsigned char*)&bits[offset / 8], tempLen);

		offset += tempLen;
	}

	return len;
}
コード例 #4
0
ファイル: asn-PERGeneral.cpp プロジェクト: neeraj9/esnacc-ng
_BEGIN_SNACC_NAMESPACE


AsnLen PERGeneral::EncodeGeneral(AsnBufBits &b)const
{
	AsnLen len = 0;
	unsigned long l_64kFrag = l_16k * 4;
	unsigned long count = 0;
	unsigned long x = 0;
	unsigned long y = 0;
	unsigned long tempLen = lEncLen();
	unsigned char ch = 0x00;
	unsigned char *c = NULL;
	long offset = 0;
	
	

	if(tempLen >= l_16k)
	{	
		/*there is more than 16k bytes of data*/
		count = (tempLen / l_64kFrag);
		
		for(x=0; x < count; x++)
		{  
			len += b.OctetAlignWrite();
			
			len += PEncLen_16kFragment(b, 4);
			
			len += b.OctetAlignWrite();

			for(y = 0; y < l_64kFrag; y++)
			{
				len += Interpret(b, offset);
				offset++;
			}
			
		}

		tempLen -= count * l_64kFrag;

		count = tempLen / l_16k;

		if(count != 0)
		{  
			len += b.OctetAlignWrite();
			
			len += PEncLen_16kFragment(b, count);
		
			len += b.OctetAlignWrite();

			for(y = 0; y < (l_16k * count); y++)
			{
				len += Interpret(b, offset);
				offset++;
			}
		
		}
		
		tempLen -=  (l_16k * count);

		if(tempLen == 0)
		{
			ch = 0x00;
			c = &ch;
			
			len += b.OctetAlignWrite();

			len += b.PutBits(c, 8);
			
			return len;
		}

	}

	/*if there are less than 128 bytes of data*/
	if(tempLen < 128)
	{
		len += b.OctetAlignWrite();

		len += PEncDefLenTo127(b, tempLen);
		
		len += b.OctetAlignWrite();

		for(y = 0; y < tempLen; y++)
		{
			len += Interpret(b, offset);
			offset++;
		}
		
	}
	else if(tempLen >= 128 && tempLen < l_16k)
	{
		len += b.OctetAlignWrite();
		/*if there is less than 16k bytes of data*/
		/*and more than 127 bytes of data*/
		len += PEncLen_1to16k(b, tempLen);
		
		len += b.OctetAlignWrite();

	
		for(y = 0; y < tempLen; y++)
		{
			len += Interpret(b, offset);
			offset++;
		}
		
	}

	return len;
}