runner: Rewrite some more parsers.

These were easy.

Change-Id: I5fc764b83d641b08b58ccbff36dbd28cb66efed0
Reviewed-on: https://boringssl-review.googlesource.com/23564
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-11-29 19:11:36 -05:00 committed by CQ bot account: commit-bot@chromium.org
parent c5c31abe2b
commit fb535892e5

View File

@ -1604,16 +1604,11 @@ func (m *serverKeyExchangeMsg) marshal() []byte {
if m.raw != nil { if m.raw != nil {
return m.raw return m.raw
} }
length := len(m.key) msg := newByteBuilder()
x := make([]byte, length+4) msg.addU8(typeServerKeyExchange)
x[0] = typeServerKeyExchange msg.addU24LengthPrefixed().addBytes(m.key)
x[1] = uint8(length >> 16) m.raw = msg.finish()
x[2] = uint8(length >> 8) return m.raw
x[3] = uint8(length)
copy(x[4:], m.key)
m.raw = x
return x
} }
func (m *serverKeyExchangeMsg) unmarshal(data []byte) bool { func (m *serverKeyExchangeMsg) unmarshal(data []byte) bool {
@ -1638,19 +1633,12 @@ func (m *certificateStatusMsg) marshal() []byte {
var x []byte var x []byte
if m.statusType == statusTypeOCSP { if m.statusType == statusTypeOCSP {
x = make([]byte, 4+4+len(m.response)) msg := newByteBuilder()
x[0] = typeCertificateStatus msg.addU8(typeCertificateStatus)
l := len(m.response) + 4 body := msg.addU24LengthPrefixed()
x[1] = byte(l >> 16) body.addU8(statusTypeOCSP)
x[2] = byte(l >> 8) body.addU24LengthPrefixed().addBytes(m.response)
x[3] = byte(l) x = msg.finish()
x[4] = statusTypeOCSP
l -= 4
x[5] = byte(l >> 16)
x[6] = byte(l >> 8)
x[7] = byte(l)
copy(x[8:], m.response)
} else { } else {
x = []byte{typeCertificateStatus, 0, 0, 1, m.statusType} x = []byte{typeCertificateStatus, 0, 0, 1, m.statusType}
} }
@ -1661,22 +1649,13 @@ func (m *certificateStatusMsg) marshal() []byte {
func (m *certificateStatusMsg) unmarshal(data []byte) bool { func (m *certificateStatusMsg) unmarshal(data []byte) bool {
m.raw = data m.raw = data
if len(data) < 5 { reader := byteReader(data[4:])
if !reader.readU8(&m.statusType) ||
m.statusType != statusTypeOCSP ||
!reader.readU24LengthPrefixedBytes(&m.response) ||
len(reader) != 0 {
return false return false
} }
m.statusType = data[4]
m.response = nil
if m.statusType == statusTypeOCSP {
if len(data) < 8 {
return false
}
respLen := uint32(data[5])<<16 | uint32(data[6])<<8 | uint32(data[7])
if uint32(len(data)) != 4+4+respLen {
return false
}
m.response = data[8:]
}
return true return true
} }
@ -1701,16 +1680,11 @@ func (m *clientKeyExchangeMsg) marshal() []byte {
if m.raw != nil { if m.raw != nil {
return m.raw return m.raw
} }
length := len(m.ciphertext) msg := newByteBuilder()
x := make([]byte, length+4) msg.addU8(typeClientKeyExchange)
x[0] = typeClientKeyExchange msg.addU24LengthPrefixed().addBytes(m.ciphertext)
x[1] = uint8(length >> 16) m.raw = msg.finish()
x[2] = uint8(length >> 8) return m.raw
x[3] = uint8(length)
copy(x[4:], m.ciphertext)
m.raw = x
return x
} }
func (m *clientKeyExchangeMsg) unmarshal(data []byte) bool { func (m *clientKeyExchangeMsg) unmarshal(data []byte) bool {
@ -1731,17 +1705,16 @@ type finishedMsg struct {
verifyData []byte verifyData []byte
} }
func (m *finishedMsg) marshal() (x []byte) { func (m *finishedMsg) marshal() []byte {
if m.raw != nil { if m.raw != nil {
return m.raw return m.raw
} }
x = make([]byte, 4+len(m.verifyData)) msg := newByteBuilder()
x[0] = typeFinished msg.addU8(typeFinished)
x[3] = byte(len(m.verifyData)) msg.addU24LengthPrefixed().addBytes(m.verifyData)
copy(x[4:], m.verifyData) m.raw = msg.finish()
m.raw = x return m.raw
return
} }
func (m *finishedMsg) unmarshal(data []byte) bool { func (m *finishedMsg) unmarshal(data []byte) bool {
@ -1762,52 +1735,38 @@ func (m *nextProtoMsg) marshal() []byte {
if m.raw != nil { if m.raw != nil {
return m.raw return m.raw
} }
l := len(m.proto)
if l > 255 {
l = 255
}
padding := 32 - (l+2)%32 padding := 32 - (len(m.proto)+2)%32
length := l + padding + 2
x := make([]byte, length+4)
x[0] = typeNextProtocol
x[1] = uint8(length >> 16)
x[2] = uint8(length >> 8)
x[3] = uint8(length)
y := x[4:] msg := newByteBuilder()
y[0] = byte(l) msg.addU8(typeNextProtocol)
copy(y[1:], []byte(m.proto[0:l])) body := msg.addU24LengthPrefixed()
y = y[1+l:] body.addU8LengthPrefixed().addBytes([]byte(m.proto))
y[0] = byte(padding) body.addU8LengthPrefixed().addBytes(make([]byte, padding))
m.raw = msg.finish()
m.raw = x return m.raw
return x
} }
func (m *nextProtoMsg) unmarshal(data []byte) bool { func (m *nextProtoMsg) unmarshal(data []byte) bool {
m.raw = data m.raw = data
reader := byteReader(data[4:])
var proto, padding []byte
if !reader.readU8LengthPrefixedBytes(&proto) ||
!reader.readU8LengthPrefixedBytes(&padding) ||
len(reader) != 0 {
return false
}
m.proto = string(proto)
if len(data) < 5 { // Padding is not meant to be checked normally, but as this is a testing
// implementation, we check the padding is as expected.
if len(padding) != 32-(len(m.proto)+2)%32 {
return false return false
} }
data = data[4:] for _, v := range padding {
protoLen := int(data[0]) if v != 0 {
data = data[1:]
if len(data) < protoLen {
return false return false
} }
m.proto = string(data[0:protoLen])
data = data[protoLen:]
if len(data) < 1 {
return false
}
paddingLen := int(data[0])
data = data[1:]
if len(data) != paddingLen {
return false
} }
return true return true