本文整理汇总了C#中Granados.IO.DataFragment.Init方法的典型用法代码示例。如果您正苦于以下问题:C# DataFragment.Init方法的具体用法?C# DataFragment.Init怎么用?C# DataFragment.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Granados.IO.DataFragment
的用法示例。
在下文中一共展示了DataFragment.Init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Close
public void Close(Cipher cipher, Random rnd, MAC mac, int sequence, DataFragment result)
{
if(!_is_open) throw new SSHException("internal state error");
int blocksize = cipher==null? 8 : cipher.BlockSize;
int payload_length = _writer.Length - (SEQUENCE_MARGIN + LENGTH_MARGIN + PADDING_MARGIN);
int r = 11 - payload_length % blocksize;
while(r < 4) r += blocksize;
_paddingLength = r;
_packetLength = PADDING_MARGIN + payload_length + _paddingLength;
int image_length = _packetLength + LENGTH_MARGIN;
//fill padding
for(int i=0; i<_paddingLength; i+=4)
_writer.Write(rnd.Next());
//manipulate stream
byte[] rawbuf = _writer.UnderlyingBuffer;
SSHUtil.WriteIntToByteArray(rawbuf, 0, sequence);
SSHUtil.WriteIntToByteArray(rawbuf, SEQUENCE_MARGIN, _packetLength);
rawbuf[SEQUENCE_MARGIN + LENGTH_MARGIN] = (byte)_paddingLength;
//mac
if(mac!=null) {
_mac = mac.ComputeHash(rawbuf, 0, _packetLength+LENGTH_MARGIN+SEQUENCE_MARGIN);
Array.Copy(_mac, 0, rawbuf, _packetLength+LENGTH_MARGIN+SEQUENCE_MARGIN, _mac.Length);
image_length += _mac.Length;
}
//encrypt
if(cipher!=null)
cipher.Encrypt(rawbuf, SEQUENCE_MARGIN, _packetLength+LENGTH_MARGIN, rawbuf, SEQUENCE_MARGIN);
result.Init(rawbuf, SEQUENCE_MARGIN, image_length);
_is_open = false;
}