@@ -134,6 +134,22 @@ func (msg *MessageInitiation) unmarshal(b []byte) error {
134134 return nil
135135}
136136
137+ func (msg * MessageInitiation ) marshal (b []byte ) error {
138+ if len (b ) != MessageInitiationSize {
139+ return errMessageLengthMismatch
140+ }
141+
142+ binary .LittleEndian .PutUint32 (b , msg .Type )
143+ binary .LittleEndian .PutUint32 (b [4 :], msg .Sender )
144+ copy (b [8 :], msg .Ephemeral [:])
145+ copy (b [8 + len (msg .Ephemeral ):], msg .Static [:])
146+ copy (b [8 + len (msg .Ephemeral )+ len (msg .Static ):], msg .Timestamp [:])
147+ copy (b [8 + len (msg .Ephemeral )+ len (msg .Static )+ len (msg .Timestamp ):], msg .MAC1 [:])
148+ copy (b [8 + len (msg .Ephemeral )+ len (msg .Static )+ len (msg .Timestamp )+ len (msg .MAC1 ):], msg .MAC2 [:])
149+
150+ return nil
151+ }
152+
137153func (msg * MessageResponse ) unmarshal (b []byte ) error {
138154 if len (b ) != MessageResponseSize {
139155 return errMessageLengthMismatch
@@ -150,6 +166,22 @@ func (msg *MessageResponse) unmarshal(b []byte) error {
150166 return nil
151167}
152168
169+ func (msg * MessageResponse ) marshal (b []byte ) error {
170+ if len (b ) != MessageResponseSize {
171+ return errMessageLengthMismatch
172+ }
173+
174+ binary .LittleEndian .PutUint32 (b , msg .Type )
175+ binary .LittleEndian .PutUint32 (b [4 :], msg .Sender )
176+ binary .LittleEndian .PutUint32 (b [8 :], msg .Receiver )
177+ copy (b [12 :], msg .Ephemeral [:])
178+ copy (b [12 + len (msg .Ephemeral ):], msg .Empty [:])
179+ copy (b [12 + len (msg .Ephemeral )+ len (msg .Empty ):], msg .MAC1 [:])
180+ copy (b [12 + len (msg .Ephemeral )+ len (msg .Empty )+ len (msg .MAC1 ):], msg .MAC2 [:])
181+
182+ return nil
183+ }
184+
153185func (msg * MessageCookieReply ) unmarshal (b []byte ) error {
154186 if len (b ) != MessageCookieReplySize {
155187 return errMessageLengthMismatch
@@ -163,6 +195,19 @@ func (msg *MessageCookieReply) unmarshal(b []byte) error {
163195 return nil
164196}
165197
198+ func (msg * MessageCookieReply ) marshal (b []byte ) error {
199+ if len (b ) != MessageCookieReplySize {
200+ return errMessageLengthMismatch
201+ }
202+
203+ binary .LittleEndian .PutUint32 (b , msg .Type )
204+ binary .LittleEndian .PutUint32 (b [4 :], msg .Receiver )
205+ copy (b [8 :], msg .Nonce [:])
206+ copy (b [8 + len (msg .Nonce ):], msg .Cookie [:])
207+
208+ return nil
209+ }
210+
166211type Handshake struct {
167212 state handshakeState
168213 mutex sync.RWMutex
0 commit comments