@@ -106,7 +106,7 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
106
106
}
107
107
108
108
// Extract the payload and exit with a nil message if it is invalid.
109
- payloadType , payload , err := o .extractPayload (payloads )
109
+ source , payload , err := o .extractPayload (payloads )
110
110
if sender == 0 {
111
111
if err != nil {
112
112
sender = i + 1
@@ -118,7 +118,7 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
118
118
119
119
// If we are at the node that is the source of the error, we can now
120
120
// save the message in our return variable.
121
- if payloadType == payloadFinal {
121
+ if source == payloadErrorNode {
122
122
sender = i + 1
123
123
msg = message
124
124
}
@@ -149,11 +149,6 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
149
149
}, nil
150
150
}
151
151
152
- const (
153
- payloadFinal = 1
154
- payloadIntermediate = 0
155
- )
156
-
157
152
func (o * OnionAttributableErrorDecrypter ) shiftHmacsLeft (hmacs []byte ) {
158
153
srcIdx := o .maxHops
159
154
destIdx := 1
@@ -174,21 +169,21 @@ func (o *OnionAttributableErrorDecrypter) shiftPayloadsLeft(payloads []byte) {
174
169
copy (payloads , payloads [o .payloadLen :o .maxHops * o .payloadLen ])
175
170
}
176
171
177
- func ( o * OnionAttributableErrorDecrypter ) extractPayload ( payloads [] byte ) (
178
- PayloadType , [] byte , error ) {
179
-
180
- var payloadType PayloadType
172
+ // extractPayload extracts the payload and payload origin information from the
173
+ // given byte slice.
174
+ func ( o * OnionAttributableErrorDecrypter ) extractPayload ( payloadBytes [] byte ) (
175
+ payloadSource , [] byte , error ) {
181
176
182
- switch payloads [0 ] {
183
- case payloadFinal , payloadIntermediate :
184
- payloadType = PayloadType (payloads [0 ])
177
+ source := payloadSource (payloadBytes [0 ])
185
178
186
- default :
187
- return 0 , nil , errors .New ("invalid payload type" )
179
+ // Validate source indicator.
180
+ if source != payloadErrorNode && source != payloadIntermediateNode {
181
+ return 0 , nil , errors .New ("invalid payload source indicator" )
188
182
}
189
183
184
+ // Extract payload.
190
185
payload := make ([]byte , o .payloadDataLen )
191
- copy (payload , payloads [1 :o .payloadLen ])
186
+ copy (payload , payloadBytes [1 :o .payloadLen ])
192
187
193
- return payloadType , payload , nil
188
+ return source , payload , nil
194
189
}
0 commit comments