@@ -134,6 +134,22 @@ func (msg *MessageInitiation) unmarshal(b []byte) error {
134
134
return nil
135
135
}
136
136
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
+
137
153
func (msg * MessageResponse ) unmarshal (b []byte ) error {
138
154
if len (b ) != MessageResponseSize {
139
155
return errMessageLengthMismatch
@@ -150,6 +166,22 @@ func (msg *MessageResponse) unmarshal(b []byte) error {
150
166
return nil
151
167
}
152
168
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
+
153
185
func (msg * MessageCookieReply ) unmarshal (b []byte ) error {
154
186
if len (b ) != MessageCookieReplySize {
155
187
return errMessageLengthMismatch
@@ -163,6 +195,19 @@ func (msg *MessageCookieReply) unmarshal(b []byte) error {
163
195
return nil
164
196
}
165
197
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
+
166
211
type Handshake struct {
167
212
state handshakeState
168
213
mutex sync.RWMutex
0 commit comments