public void TestOutputOffset(TestContext ctx, [TestHost] IEncryptionTestHost host) { var input = GetBuffer(HelloWorldName); var output = new TlsBuffer(input.Size + host.MaxExtraEncryptedBytes + MagicDataSize); output.Write(GetBuffer(MagicDataName)); var startOffset = output.Offset; var startPos = output.Position; var startSize = output.Size; var length = host.Encrypt(input, output.GetRemaining()); ctx.Assert(length, Is.GreaterThanOrEqualTo(0), "#1"); ctx.Assert(length, Is.GreaterThanOrEqualTo(input.Size + host.MinExtraEncryptedBytes), "#2a"); ctx.Assert(length, Is.LessThanOrEqualTo(input.Size + host.MaxExtraEncryptedBytes), "#2a"); ctx.Assert(output.Offset, Is.EqualTo(startOffset), "#2b"); ctx.Assert(output.Size, Is.EqualTo(startSize), "#2c"); output.Position = 0; var magic = output.ReadBytes(MagicDataSize); ctx.Assert(magic, Is.EqualTo(GetField(MagicDataName)), "#3"); var encrypted = output.ReadBytes(length); CheckOutput(ctx, HelloWorldResult, new BufferOffsetSize(encrypted)); }
public void TestDecrypt() { var input = GetBuffer(HelloWorldResult); var output = new TlsBuffer(input.Size + MagicDataSize + MagicData2Size); output.Write(GetBuffer(MagicDataName)); output.Write(GetBuffer(MagicData2Name)); var hello = GetField(HelloWorldName); var length = Context.Decrypt(input, output.GetRemaining()); Assert.That(length, Is.EqualTo(hello.Length), "#1"); output.Position = 0; var magic = output.ReadBytes(MagicDataSize); Assert.That(magic, Is.EqualTo(GetField(MagicDataName)), "#2"); var magic2 = output.ReadBytes(MagicData2Size); Assert.That(magic2, Is.EqualTo(GetField(MagicData2Name)), "#3"); var decrypted = output.ReadBytes(length); Assert.That(decrypted, Is.EqualTo(hello), "#4"); }
public int DecryptMessage(ref MSI.IBufferOffsetSize incoming) { var buffer = new TlsBuffer(BOSWrapper.Wrap(incoming)); var retval = Context.DecryptMessage(ref buffer); incoming = BOSWrapper.Wrap(buffer.GetRemaining()); return((int)retval); }
public void TestDecrypt(TestContext ctx, [TestHost] IEncryptionTestHost host) { var input = GetBuffer(HelloWorldResult); var output = new TlsBuffer(input.Size); var hello = GetField(HelloWorldName); var length = host.Decrypt(input, output.GetRemaining()); ctx.Assert(length, Is.EqualTo(hello.Length), "#1"); output.Position = 0; var decrypted = output.ReadBytes(length); ctx.Assert(decrypted, Is.EqualTo(hello), "#4"); }
bool DecryptRecordFragment (ContentType contentType, ref TlsBuffer buffer) { var read = Session.Read; if (read == null || read.Cipher == null) return false; var output = read.Decrypt (contentType, buffer.GetRemaining ()); buffer = new TlsBuffer (output); return true; }
SecurityStatus _EncryptMessage (ref TlsBuffer incoming) { #if DEBUG_FULL if (EnableDebugging) DebugHelper.WriteRemaining ("EncryptMessage", incoming); #endif var buffer = EncodeRecord (ContentType.ApplicationData, incoming.GetRemaining ()); #if DEBUG_FULL if (EnableDebugging) DebugHelper.WriteBuffer ("EncryptMessage done", buffer); #endif incoming = new TlsBuffer (buffer); return SecurityStatus.OK; }
public int DecryptMessage (ref MSI.IBufferOffsetSize incoming) { var buffer = new TlsBuffer (BOSWrapper.Wrap (incoming)); var retval = Context.DecryptMessage (ref buffer); incoming = buffer != null ? BOSWrapper.Wrap (buffer.GetRemaining ()) : null; return (int)retval; }
public void TestDecrypt (TestContext ctx, [TestHost] IEncryptionTestHost host) { var input = GetBuffer (HelloWorldResult); var output = new TlsBuffer (input.Size + MagicDataSize + MagicData2Size); output.Write (GetBuffer (MagicDataName)); output.Write (GetBuffer (MagicData2Name)); var hello = GetField (HelloWorldName); var length = host.Decrypt (input, output.GetRemaining ()); ctx.Assert (length, Is.EqualTo (hello.Length), "#1"); output.Position = 0; var magic = output.ReadBytes (MagicDataSize); ctx.Assert (magic, Is.EqualTo (GetField (MagicDataName)), "#2"); var magic2 = output.ReadBytes (MagicData2Size); ctx.Assert (magic2, Is.EqualTo (GetField (MagicData2Name)), "#3"); var decrypted = output.ReadBytes (length); ctx.Assert (decrypted, Is.EqualTo (hello), "#4"); }
public void TestOutputOffset (TestContext ctx, [TestHost] IEncryptionTestHost host) { var input = GetBuffer (HelloWorldName); var output = new TlsBuffer (input.Size + host.MaxExtraEncryptedBytes + MagicDataSize); output.Write (GetBuffer (MagicDataName)); var startOffset = output.Offset; var startPos = output.Position; var startSize = output.Size; var length = host.Encrypt (input, output.GetRemaining ()); ctx.Assert (length, Is.GreaterThanOrEqualTo (0), "#1"); ctx.Assert (length, Is.EqualTo (input.Size + host.MinExtraEncryptedBytes), "#2a"); ctx.Assert (output.Offset, Is.EqualTo (startOffset), "#2b"); ctx.Assert (output.Size, Is.EqualTo (startSize), "#2c"); output.Position = 0; var magic = output.ReadBytes (MagicDataSize); ctx.Assert (magic, Is.EqualTo (GetField (MagicDataName)), "#3"); var encrypted = output.ReadBytes (length); CheckOutput (ctx, HelloWorldResult, new BufferOffsetSize (encrypted)); }