This file is indexed.

/usr/share/gocode/src/github.com/twstrike/otr3/tlv.go is in golang-github-twstrike-otr3-dev 0.0~git20161015.0.744856d-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package otr3

import "bytes"

const tlvHeaderLength = 4

const (
	tlvTypePadding           = uint16(0x00)
	tlvTypeDisconnected      = uint16(0x01)
	tlvTypeSMP1              = uint16(0x02)
	tlvTypeSMP2              = uint16(0x03)
	tlvTypeSMP3              = uint16(0x04)
	tlvTypeSMP4              = uint16(0x05)
	tlvTypeSMPAbort          = uint16(0x06)
	tlvTypeSMP1WithQuestion  = uint16(0x07)
	tlvTypeExtraSymmetricKey = uint16(0x08)
)

type tlvHandler func(*Conversation, tlv, dataMessageExtra) (*tlv, error)

var tlvHandlers = make([]tlvHandler, 9)

func initTLVHandlers() {
	tlvHandlers[tlvTypePadding] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processPaddingTLV(t, x)
	}
	tlvHandlers[tlvTypeDisconnected] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processDisconnectedTLV(t, x)
	}
	tlvHandlers[tlvTypeSMP1] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeSMP2] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeSMP3] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeSMP4] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeSMPAbort] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeSMP1WithQuestion] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processSMPTLV(t, x)
	}
	tlvHandlers[tlvTypeExtraSymmetricKey] = func(c *Conversation, t tlv, x dataMessageExtra) (*tlv, error) {
		return c.processExtraSymmetricKeyTLV(t, x)
	}
}

func messageHandlerForTLV(t tlv) (tlvHandler, error) {
	if t.tlvType >= uint16(len(tlvHandlers)) {
		return nil, newOtrError("unexpected TLV type")
	}
	return tlvHandlers[t.tlvType], nil
}

type tlv struct {
	tlvType   uint16
	tlvLength uint16
	tlvValue  []byte
}

func (c tlv) serialize() []byte {
	out := appendShort([]byte{}, c.tlvType)
	out = appendShort(out, c.tlvLength)
	return append(out, c.tlvValue...)
}

func (c *tlv) deserialize(tlvsBytes []byte) error {
	var ok bool
	tlvsBytes, c.tlvType, ok = extractShort(tlvsBytes)
	if !ok {
		return newOtrError("wrong tlv type")
	}
	tlvsBytes, c.tlvLength, ok = extractShort(tlvsBytes)
	if !ok {
		return newOtrError("wrong tlv length")
	}
	if len(tlvsBytes) < int(c.tlvLength) {
		return newOtrError("wrong tlv value")
	}
	c.tlvValue = tlvsBytes[:int(c.tlvLength)]
	return nil
}

func (c tlv) isSMPMessage() bool {
	return c.tlvType >= tlvTypeSMP1 && c.tlvType <= tlvTypeSMP1WithQuestion
}

func (c tlv) smpMessage() (smpMessage, bool) {
	switch c.tlvType {
	case tlvTypeSMP1:
		return toSmpMessage1(c)
	case tlvTypeSMP1WithQuestion:
		return toSmpMessage1Q(c)
	case tlvTypeSMP2:
		return toSmpMessage2(c)
	case tlvTypeSMP3:
		return toSmpMessage3(c)
	case tlvTypeSMP4:
		return toSmpMessage4(c)
	case tlvTypeSMPAbort:
		return toSmpMessageAbort(c)
	}

	return nil, false
}

func toSmpMessage1(t tlv) (msg smp1Message, ok bool) {
	_, mpis, ok := extractMPIs(t.tlvValue)
	if !ok || len(mpis) < 6 {
		return msg, false
	}
	msg.g2a = mpis[0]
	msg.c2 = mpis[1]
	msg.d2 = mpis[2]
	msg.g3a = mpis[3]
	msg.c3 = mpis[4]
	msg.d3 = mpis[5]
	return msg, true
}

func toSmpMessage1Q(t tlv) (msg smp1Message, ok bool) {
	nulPos := bytes.IndexByte(t.tlvValue, 0)
	if nulPos == -1 {
		return msg, false
	}
	question := string(t.tlvValue[:nulPos])
	t.tlvValue = t.tlvValue[(nulPos + 1):]
	msg, ok = toSmpMessage1(t)
	msg.hasQuestion = true
	msg.question = question
	return msg, ok
}

func toSmpMessage2(t tlv) (msg smp2Message, ok bool) {
	_, mpis, ok := extractMPIs(t.tlvValue)
	if !ok || len(mpis) < 11 {
		return msg, false
	}
	msg.g2b = mpis[0]
	msg.c2 = mpis[1]
	msg.d2 = mpis[2]
	msg.g3b = mpis[3]
	msg.c3 = mpis[4]
	msg.d3 = mpis[5]
	msg.pb = mpis[6]
	msg.qb = mpis[7]
	msg.cp = mpis[8]
	msg.d5 = mpis[9]
	msg.d6 = mpis[10]
	return msg, true
}

func toSmpMessage3(t tlv) (msg smp3Message, ok bool) {
	_, mpis, ok := extractMPIs(t.tlvValue)
	if !ok || len(mpis) < 8 {
		return msg, false
	}
	msg.pa = mpis[0]
	msg.qa = mpis[1]
	msg.cp = mpis[2]
	msg.d5 = mpis[3]
	msg.d6 = mpis[4]
	msg.ra = mpis[5]
	msg.cr = mpis[6]
	msg.d7 = mpis[7]
	return msg, true
}

func toSmpMessage4(t tlv) (msg smp4Message, ok bool) {
	_, mpis, ok := extractMPIs(t.tlvValue)
	if !ok || len(mpis) < 3 {
		return msg, false
	}
	msg.rb = mpis[0]
	msg.cr = mpis[1]
	msg.d7 = mpis[2]
	return msg, true
}

func toSmpMessageAbort(t tlv) (msg smpMessageAbort, ok bool) {
	return msg, true
}