3个回答
推荐于2016-02-15
展开全部
#include "asn.h"
#include "misc.h"
#include <assert.h>unsigned int DERLengthEncode(unsigned int length, byte *output)
{
unsigned int i=0;
if (length <= 0x7f)
{
output[i++] = byte(length);
}
else
{
output[i++] = byte(BytePrecision(length) | 0x80);
for (int j=BytePrecision(length); j; --j)
{
output[i++] = byte (length >> (j-1)*8);
}
}
return i;
}unsigned int DERLengthEncode(unsigned int length, BufferedTransformation &bt)
{
byte buf[10]; // should be more than enough
unsigned int i = DERLengthEncode(length, buf);
bt.Put(buf, i);
return i;
}boolean BERLengthDecode(BufferedTransformation &bt, unsigned int &length)
{
byte b; if (!bt.Get(b))
BERDecodeError(); if (!(b & 0x80))
length = b;
else
{
unsigned int lengthBytes = b & 0x7f;
if (bt.MaxRetrieveable() < lengthBytes)
BERDecodeError(); bt.Get(b);
while (!b && lengthBytes>1)
{
bt.Get(b);
lengthBytes--;
} switch (lengthBytes)
{
case 0:
return FALSE; // indefinite length
case 1:
length = b;
break;
case 2:
length = b << 8;
length |= (bt.Get(b), b);
break;
default:
BERDecodeError();
}
}
return TRUE;
}BERSequenceDecoder::BERSequenceDecoder(BufferedTransformation &inQueue)
: inQueue(inQueue)
{
byte b;
if (!inQueue.Get(b) || b != (SEQUENCE | CONSTRUCTED))
BERDecodeError(); definiteLength = BERLengthDecode(inQueue, length);
}BERSequenceDecoder::~BERSequenceDecoder()
{
if (!definiteLength)
{ // remove end-of-content octects
word16 i;
if (!inQueue.GetShort(i) || (i!=0))
BERDecodeError();
}
}DERSequenceEncoder::DERSequenceEncoder(BufferedTransformation &outQueue)
: outQueue(outQueue)
{
}DERSequenceEncoder::~DERSequenceEncoder()
{
unsigned int length = (unsigned int)CurrentSize();
outQueue.Put(SEQUENCE | CONSTRUCTED);
DERLengthEncode(length, outQueue);
TransferTo(outQueue);
}
#include "misc.h"
#include <assert.h>unsigned int DERLengthEncode(unsigned int length, byte *output)
{
unsigned int i=0;
if (length <= 0x7f)
{
output[i++] = byte(length);
}
else
{
output[i++] = byte(BytePrecision(length) | 0x80);
for (int j=BytePrecision(length); j; --j)
{
output[i++] = byte (length >> (j-1)*8);
}
}
return i;
}unsigned int DERLengthEncode(unsigned int length, BufferedTransformation &bt)
{
byte buf[10]; // should be more than enough
unsigned int i = DERLengthEncode(length, buf);
bt.Put(buf, i);
return i;
}boolean BERLengthDecode(BufferedTransformation &bt, unsigned int &length)
{
byte b; if (!bt.Get(b))
BERDecodeError(); if (!(b & 0x80))
length = b;
else
{
unsigned int lengthBytes = b & 0x7f;
if (bt.MaxRetrieveable() < lengthBytes)
BERDecodeError(); bt.Get(b);
while (!b && lengthBytes>1)
{
bt.Get(b);
lengthBytes--;
} switch (lengthBytes)
{
case 0:
return FALSE; // indefinite length
case 1:
length = b;
break;
case 2:
length = b << 8;
length |= (bt.Get(b), b);
break;
default:
BERDecodeError();
}
}
return TRUE;
}BERSequenceDecoder::BERSequenceDecoder(BufferedTransformation &inQueue)
: inQueue(inQueue)
{
byte b;
if (!inQueue.Get(b) || b != (SEQUENCE | CONSTRUCTED))
BERDecodeError(); definiteLength = BERLengthDecode(inQueue, length);
}BERSequenceDecoder::~BERSequenceDecoder()
{
if (!definiteLength)
{ // remove end-of-content octects
word16 i;
if (!inQueue.GetShort(i) || (i!=0))
BERDecodeError();
}
}DERSequenceEncoder::DERSequenceEncoder(BufferedTransformation &outQueue)
: outQueue(outQueue)
{
}DERSequenceEncoder::~DERSequenceEncoder()
{
unsigned int length = (unsigned int)CurrentSize();
outQueue.Put(SEQUENCE | CONSTRUCTED);
DERLengthEncode(length, outQueue);
TransferTo(outQueue);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-23
展开全部
printf不行吗、?然后exit(0);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-23
展开全部
做个死循环 do{}while(getchar()!='Q')应该可以的额
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询