func splitBlock(b *block, n int) (*block, *block) {
	if len(b.data) <= n {
		return b, nil
	}
	bb := newBlock()
	bb.resize(len(b.data) - n)
	copy(bb.data, b.data[n:])
	b.data = b.data[0:n]
	return b, bb
}
splitBlock splits a block after the first n bytes,
returning a block with those n bytes and a
block with the remainder.  the latter may be nil.
package vhost
import (
	"bytes"
	"errors"
	"io"
	"net"
	"strconv"
)
const (
	maxPlaintext    = 16384         
	maxCiphertext   = 16384 + 2048  
	recordHeaderLen = 5             
	maxHandshake    = 65536         
)
type alert uint8
const (
	alertUnexpectedMessage alert = 10
	alertRecordOverflow    alert = 22
	alertInternalError     alert = 80
)
var alertText = map[alert]string{
	alertUnexpectedMessage: "unexpected message",
	alertRecordOverflow:    "record overflow",
	alertInternalError:     "internal error",
}
func (e alert) String() string {
	s, ok := alertText[e]
	if ok {
		return s
	}
	return "alert(" + strconv.Itoa(int(e)) + ")"
}
func (e alert) Error() string {
	return e.String()
}
type recordType uint8
const (
	recordTypeHandshake recordType = 22
)
const (
	typeClientHello uint8 = 1
)
var (
	extensionServerName      uint16 = 0
	extensionStatusRequest   uint16 = 5
	extensionSupportedCurves uint16 = 10
	extensionSupportedPoints uint16 = 11
	extensionSessionTicket   uint16 = 35
	extensionNextProtoNeg    uint16 = 13172  
)
const (
	statusTypeOCSP uint8 = 1
)
type TLSConn struct {
	*sharedConn
	ClientHelloMsg *ClientHelloMsg
}
func TLS(conn net.Conn) (tlsConn *TLSConn, err error) {
	c, rd := newShared(conn)
	tlsConn = &TLSConn{sharedConn: c}
	if tlsConn.ClientHelloMsg, err = readClientHello(rd); err != nil {
		return
	}
	return
}
func (c *TLSConn) Host() string {
	if c.ClientHelloMsg == nil {
		return ""
	}
	return c.ClientHelloMsg.ServerName
}
func (c *TLSConn) Free() {
	c.ClientHelloMsg = nil
}
type block struct {
	data []byte
	off  int  
}
func (b *block) resize(n int) {
	if n > cap(b.data) {
		b.reserve(n)
	}
	b.data = b.data[0:n]
}
func (b *block) reserve(n int) {
	if cap(b.data) >= n {
		return
	}
	m := cap(b.data)
	if m == 0 {
		m = 1024
	}
	for m < n {
		m *= 2
	}
	data := make([]byte, len(b.data), m)
	copy(data, b.data)
	b.data = data
}
func (b *block) readFromUntil(r io.Reader, n int) error {
	if len(b.data) >= n {
		return nil
	}
	b.reserve(n)
	for {
		m, err := r.Read(b.data[len(b.data):cap(b.data)])
		b.data = b.data[0 : len(b.data)+m]
		if len(b.data) >= n {
			break
		}
		if err != nil {
			return err
		}
	}
	return nil
}
func (b *block) Read(p []byte) (n int, err error) {
	n = copy(p, b.data[b.off:])
	b.off += n
	return
}
func newBlock() *block {
	return new(block)
}