Skip to content

Commit a8fce5c

Browse files
committed
rename payload type to source [squash]
1 parent 3b52023 commit a8fce5c

3 files changed

+32
-22
lines changed

attributable_error_crypto.go

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ import (
55
"crypto/sha256"
66
)
77

8+
type payloadSource byte
9+
10+
const (
11+
// payloadIntermediateNode is a marker to signal that this attributable
12+
// error payload is originating from a node between the payer and the error
13+
// source.
14+
payloadIntermediateNode payloadSource = 0
15+
16+
// payloadErrorNode is a marker to signal that this attributable error
17+
// payload is originating from the error source.
18+
payloadErrorNode payloadSource = 1
19+
)
20+
821
type AttributableErrorStructure struct {
922
HopCount int
1023
FixedPayloadLen int

attributable_error_decrypt.go

+13-18
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
106106
}
107107

108108
// 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)
110110
if sender == 0 {
111111
if err != nil {
112112
sender = i + 1
@@ -118,7 +118,7 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
118118

119119
// If we are at the node that is the source of the error, we can now
120120
// save the message in our return variable.
121-
if payloadType == payloadFinal {
121+
if source == payloadErrorNode {
122122
sender = i + 1
123123
msg = message
124124
}
@@ -149,11 +149,6 @@ func (o *OnionAttributableErrorDecrypter) DecryptError(encryptedData []byte) (
149149
}, nil
150150
}
151151

152-
const (
153-
payloadFinal = 1
154-
payloadIntermediate = 0
155-
)
156-
157152
func (o *OnionAttributableErrorDecrypter) shiftHmacsLeft(hmacs []byte) {
158153
srcIdx := o.maxHops
159154
destIdx := 1
@@ -174,21 +169,21 @@ func (o *OnionAttributableErrorDecrypter) shiftPayloadsLeft(payloads []byte) {
174169
copy(payloads, payloads[o.payloadLen:o.maxHops*o.payloadLen])
175170
}
176171

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) {
181176

182-
switch payloads[0] {
183-
case payloadFinal, payloadIntermediate:
184-
payloadType = PayloadType(payloads[0])
177+
source := payloadSource(payloadBytes[0])
185178

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")
188182
}
189183

184+
// Extract payload.
190185
payload := make([]byte, o.payloadDataLen)
191-
copy(payload, payloads[1:o.payloadLen])
186+
copy(payload, payloadBytes[1:o.payloadLen])
192187

193-
return payloadType, payload, nil
188+
return source, payload, nil
194189
}

attributable_error_encrypt.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (o *OnionAttributableErrorEncrypter) initializePayload(message []byte,
112112
_, payloads, _ := o.getMsgComponents(data)
113113

114114
// Signal final hops in the payload.
115-
addPayload(payloads, payloadFinal, payload)
115+
addPayload(payloads, payloadErrorNode, payload)
116116

117117
return data
118118
}
@@ -127,10 +127,12 @@ func (o *OnionAttributableErrorEncrypter) addIntermediatePayload(data []byte,
127127
o.shiftHmacsRight(hmacs)
128128

129129
// Signal intermediate hop in the payload.
130-
addPayload(payloads, payloadIntermediate, payload)
130+
addPayload(payloads, payloadIntermediateNode, payload)
131131
}
132132

133-
func addPayload(payloads []byte, payloadType PayloadType, payload []byte) {
134-
payloads[0] = byte(payloadType)
133+
func addPayload(payloads []byte, source payloadSource,
134+
payload []byte) {
135+
136+
payloads[0] = byte(source)
135137
copy(payloads[1:], payload)
136138
}

0 commit comments

Comments
 (0)