Exemple #1
0
        static void EncodeRecord_internal(TlsProtocolCode protocol, ContentType contentType, CryptoParameters crypto, IBufferOffsetSize buffer, TlsStream output,
                                          int fragmentSize = MAX_FRAGMENT_SIZE)
        {
            var maxExtraBytes = crypto != null ? crypto.MaxExtraEncryptedBytes : 0;

            var offset    = buffer.Offset;
            var remaining = buffer.Size;

                        #if !INSTRUMENTATION
            fragmentSize = MAX_FRAGMENT_SIZE;
                        #endif

            do
            {
                BufferOffsetSize fragment;

                var encryptedSize = crypto != null?crypto.GetEncryptedSize(remaining) : remaining;

                if (encryptedSize <= fragmentSize)
                {
                    fragment = new BufferOffsetSize(buffer.Buffer, offset, remaining);
                }
                else
                {
                    fragment      = new BufferOffsetSize(buffer.Buffer, offset, fragmentSize - maxExtraBytes);
                    encryptedSize = crypto != null?crypto.GetEncryptedSize(fragment.Size) : fragment.Size;
                }

                // Write tls message
                output.Write((byte)contentType);
                output.Write((short)protocol);
                output.Write((short)encryptedSize);

                if (crypto != null)
                {
                    output.MakeRoom(encryptedSize);
                    var ret = crypto.Encrypt(contentType, fragment, output.GetRemaining());
                    output.Position += ret;
                }
                else
                {
                    output.Write(fragment.Buffer, fragment.Offset, fragment.Size);
                }

                offset    += fragment.Size;
                remaining -= fragment.Size;
            } while (remaining > 0);
        }
Exemple #2
0
 public int GetEncryptedSize(int size)
 {
     return(crypto.GetEncryptedSize(size));
 }
Exemple #3
0
		static void EncodeRecord_internal (TlsProtocolCode protocol, ContentType contentType, CryptoParameters crypto, IBufferOffsetSize buffer, TlsStream output,
			int fragmentSize = MAX_FRAGMENT_SIZE)
		{
			var maxExtraBytes = crypto != null ? crypto.MaxExtraEncryptedBytes : 0;

			var offset = buffer.Offset;
			var remaining = buffer.Size;

			#if !INSTRUMENTATION
			fragmentSize = MAX_FRAGMENT_SIZE;
			#endif

			do {
				BufferOffsetSize fragment;

				var encryptedSize = crypto != null ? crypto.GetEncryptedSize (remaining) : remaining;
				if (encryptedSize <= fragmentSize)
					fragment = new BufferOffsetSize (buffer.Buffer, offset, remaining);
				else {
					fragment = new BufferOffsetSize (buffer.Buffer, offset, fragmentSize - maxExtraBytes);
					encryptedSize = crypto != null ? crypto.GetEncryptedSize (fragment.Size) : fragment.Size;
				}

				// Write tls message
				output.Write ((byte)contentType);
				output.Write ((short)protocol);
				output.Write ((short)encryptedSize);

				if (crypto != null) {
					output.MakeRoom (encryptedSize);
					var ret = crypto.Encrypt (contentType, fragment, output.GetRemaining ());
					output.Position += ret;
				} else {
					output.Write (fragment.Buffer, fragment.Offset, fragment.Size);
				}

				offset += fragment.Size;
				remaining -= fragment.Size;
			} while (remaining > 0);
		}