summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/tls/record_write.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/crypto/tls/record_write.go')
-rw-r--r--src/pkg/crypto/tls/record_write.go132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/pkg/crypto/tls/record_write.go b/src/pkg/crypto/tls/record_write.go
index f55a214c3..5f3fb5b16 100644
--- a/src/pkg/crypto/tls/record_write.go
+++ b/src/pkg/crypto/tls/record_write.go
@@ -5,9 +5,9 @@
package tls
import (
- "fmt";
- "hash";
- "io";
+ "fmt"
+ "hash"
+ "io"
)
// writerEnableApplicationData is a message which instructs recordWriter to
@@ -17,14 +17,14 @@ type writerEnableApplicationData struct{}
// writerChangeCipherSpec updates the encryption and MAC functions and resets
// the sequence count.
type writerChangeCipherSpec struct {
- encryptor encryptor;
- mac hash.Hash;
+ encryptor encryptor
+ mac hash.Hash
}
// writerSetVersion sets the version number bytes that we included in the
// record header for future records.
type writerSetVersion struct {
- major, minor uint8;
+ major, minor uint8
}
// A recordWriter accepts messages from the handshake processor and
@@ -32,37 +32,37 @@ type writerSetVersion struct {
// writing. It doesn't read from the application data channel until the
// handshake processor has signaled that the handshake is complete.
type recordWriter struct {
- writer io.Writer;
- encryptor encryptor;
- mac hash.Hash;
- seqNum uint64;
- major, minor uint8;
- shutdown bool;
- appChan <-chan []byte;
- controlChan <-chan interface{};
- header [13]byte;
+ writer io.Writer
+ encryptor encryptor
+ mac hash.Hash
+ seqNum uint64
+ major, minor uint8
+ shutdown bool
+ appChan <-chan []byte
+ controlChan <-chan interface{}
+ header [13]byte
}
func (w *recordWriter) loop(writer io.Writer, appChan <-chan []byte, controlChan <-chan interface{}) {
- w.writer = writer;
- w.encryptor = nop{};
- w.mac = nop{};
- w.appChan = appChan;
- w.controlChan = controlChan;
+ w.writer = writer
+ w.encryptor = nop{}
+ w.mac = nop{}
+ w.appChan = appChan
+ w.controlChan = controlChan
for !w.shutdown {
- msg := <-controlChan;
+ msg := <-controlChan
if _, ok := msg.(writerEnableApplicationData); ok {
break
}
- w.processControlMessage(msg);
+ w.processControlMessage(msg)
}
for !w.shutdown {
// Always process control messages first.
if controlMsg, ok := <-controlChan; ok {
- w.processControlMessage(controlMsg);
- continue;
+ w.processControlMessage(controlMsg)
+ continue
}
select {
@@ -89,58 +89,58 @@ func (w *recordWriter) loop(writer io.Writer, appChan <-chan []byte, controlChan
// fillMACHeader generates a MAC header. See RFC 4346, section 6.2.3.1.
func fillMACHeader(header *[13]byte, seqNum uint64, length int, r *record) {
- header[0] = uint8(seqNum >> 56);
- header[1] = uint8(seqNum >> 48);
- header[2] = uint8(seqNum >> 40);
- header[3] = uint8(seqNum >> 32);
- header[4] = uint8(seqNum >> 24);
- header[5] = uint8(seqNum >> 16);
- header[6] = uint8(seqNum >> 8);
- header[7] = uint8(seqNum);
- header[8] = uint8(r.contentType);
- header[9] = r.major;
- header[10] = r.minor;
- header[11] = uint8(length >> 8);
- header[12] = uint8(length);
+ header[0] = uint8(seqNum >> 56)
+ header[1] = uint8(seqNum >> 48)
+ header[2] = uint8(seqNum >> 40)
+ header[3] = uint8(seqNum >> 32)
+ header[4] = uint8(seqNum >> 24)
+ header[5] = uint8(seqNum >> 16)
+ header[6] = uint8(seqNum >> 8)
+ header[7] = uint8(seqNum)
+ header[8] = uint8(r.contentType)
+ header[9] = r.major
+ header[10] = r.minor
+ header[11] = uint8(length >> 8)
+ header[12] = uint8(length)
}
func (w *recordWriter) writeRecord(r *record) {
- w.mac.Reset();
+ w.mac.Reset()
- fillMACHeader(&w.header, w.seqNum, len(r.payload), r);
+ fillMACHeader(&w.header, w.seqNum, len(r.payload), r)
- w.mac.Write(w.header[0:13]);
- w.mac.Write(r.payload);
- macBytes := w.mac.Sum();
+ w.mac.Write(w.header[0:13])
+ w.mac.Write(r.payload)
+ macBytes := w.mac.Sum()
- w.encryptor.XORKeyStream(r.payload);
- w.encryptor.XORKeyStream(macBytes);
+ w.encryptor.XORKeyStream(r.payload)
+ w.encryptor.XORKeyStream(macBytes)
- length := len(r.payload) + len(macBytes);
- w.header[11] = uint8(length >> 8);
- w.header[12] = uint8(length);
- w.writer.Write(w.header[8:13]);
- w.writer.Write(r.payload);
- w.writer.Write(macBytes);
+ length := len(r.payload) + len(macBytes)
+ w.header[11] = uint8(length >> 8)
+ w.header[12] = uint8(length)
+ w.writer.Write(w.header[8:13])
+ w.writer.Write(r.payload)
+ w.writer.Write(macBytes)
- w.seqNum++;
+ w.seqNum++
}
func (w *recordWriter) processControlMessage(controlMsg interface{}) {
if controlMsg == nil {
- w.shutdown = true;
- return;
+ w.shutdown = true
+ return
}
switch msg := controlMsg.(type) {
case writerChangeCipherSpec:
- w.writeRecord(&record{recordTypeChangeCipherSpec, w.major, w.minor, []byte{0x01}});
- w.encryptor = msg.encryptor;
- w.mac = msg.mac;
- w.seqNum = 0;
+ w.writeRecord(&record{recordTypeChangeCipherSpec, w.major, w.minor, []byte{0x01}})
+ w.encryptor = msg.encryptor
+ w.mac = msg.mac
+ w.seqNum = 0
case writerSetVersion:
- w.major = msg.major;
- w.minor = msg.minor;
+ w.major = msg.major
+ w.minor = msg.minor
case alert:
w.writeRecord(&record{recordTypeAlert, w.major, w.minor, []byte{byte(msg.level), byte(msg.error)}})
case handshakeMessage:
@@ -153,18 +153,18 @@ func (w *recordWriter) processControlMessage(controlMsg interface{}) {
func (w *recordWriter) processAppMessage(appMsg []byte) {
if closed(w.appChan) {
- w.writeRecord(&record{recordTypeApplicationData, w.major, w.minor, []byte{byte(alertCloseNotify)}});
- w.shutdown = true;
- return;
+ w.writeRecord(&record{recordTypeApplicationData, w.major, w.minor, []byte{byte(alertCloseNotify)}})
+ w.shutdown = true
+ return
}
- var done int;
+ var done int
for done < len(appMsg) {
- todo := len(appMsg);
+ todo := len(appMsg)
if todo > maxTLSPlaintext {
todo = maxTLSPlaintext
}
- w.writeRecord(&record{recordTypeApplicationData, w.major, w.minor, appMsg[done : done+todo]});
- done += todo;
+ w.writeRecord(&record{recordTypeApplicationData, w.major, w.minor, appMsg[done : done+todo]})
+ done += todo
}
}