diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2020-07-22 04:40:55 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2020-07-22 04:40:55 +0200 |
commit | 58da9ac6e691a8c660eb8ca838a154e11da0db68 (patch) | |
tree | a1bbda04c6d0621ce0fc20779276620f1820190b /binapi/tls_openssl/tls_openssl.ba.go | |
parent | a155cd438c6558da266c1c5931361ea088b35653 (diff) |
Fix binapigen decoding and minor improvements
- fixed allocating byte slices before copying decoded data
- simplified encoding functions
- several minor improvements
Change-Id: I6669424b89eb86333805cb1b57e4551169980cc2
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'binapi/tls_openssl/tls_openssl.ba.go')
-rw-r--r-- | binapi/tls_openssl/tls_openssl.ba.go | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/binapi/tls_openssl/tls_openssl.ba.go b/binapi/tls_openssl/tls_openssl.ba.go index b4293fd..938a9df 100644 --- a/binapi/tls_openssl/tls_openssl.ba.go +++ b/binapi/tls_openssl/tls_openssl.ba.go @@ -43,11 +43,10 @@ func (*TLSOpensslSetEngine) GetMessageType() api.MessageType { return api.RequestMessage } -func (m *TLSOpensslSetEngine) Size() int { +func (m *TLSOpensslSetEngine) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.AsyncEnable size += 1 * 64 // m.Engine size += 1 * 64 // m.Algorithm @@ -55,24 +54,25 @@ func (m *TLSOpensslSetEngine) Size() int { return size } func (m *TLSOpensslSetEngine) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } - buf.EncodeUint32(uint32(m.AsyncEnable)) - buf.EncodeBytes(m.Engine[:], 64) - buf.EncodeBytes(m.Algorithm[:], 64) - buf.EncodeBytes(m.Ciphers[:], 64) + buf := codec.NewBuffer(b) + buf.EncodeUint32(m.AsyncEnable) + buf.EncodeBytes(m.Engine, 64) + buf.EncodeBytes(m.Algorithm, 64) + buf.EncodeBytes(m.Ciphers, 64) return buf.Bytes(), nil } func (m *TLSOpensslSetEngine) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) m.AsyncEnable = buf.DecodeUint32() - copy(m.Engine[:], buf.DecodeBytes(64)) - copy(m.Algorithm[:], buf.DecodeBytes(64)) - copy(m.Ciphers[:], buf.DecodeBytes(64)) + m.Engine = make([]byte, 64) + copy(m.Engine, buf.DecodeBytes(len(m.Engine))) + m.Algorithm = make([]byte, 64) + copy(m.Algorithm, buf.DecodeBytes(len(m.Algorithm))) + m.Ciphers = make([]byte, 64) + copy(m.Ciphers, buf.DecodeBytes(len(m.Ciphers))) return nil } @@ -88,27 +88,24 @@ func (*TLSOpensslSetEngineReply) GetMessageType() api.MessageType { return api.ReplyMessage } -func (m *TLSOpensslSetEngineReply) Size() int { +func (m *TLSOpensslSetEngineReply) Size() (size int) { if m == nil { return 0 } - var size int size += 4 // m.Retval return size } func (m *TLSOpensslSetEngineReply) Marshal(b []byte) ([]byte, error) { - var buf *codec.Buffer if b == nil { - buf = codec.NewBuffer(make([]byte, m.Size())) - } else { - buf = codec.NewBuffer(b) + b = make([]byte, m.Size()) } - buf.EncodeUint32(uint32(m.Retval)) + buf := codec.NewBuffer(b) + buf.EncodeInt32(m.Retval) return buf.Bytes(), nil } func (m *TLSOpensslSetEngineReply) Unmarshal(b []byte) error { buf := codec.NewBuffer(b) - m.Retval = int32(buf.DecodeUint32()) + m.Retval = buf.DecodeInt32() return nil } |