-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbw2types.go
274 lines (257 loc) · 9.06 KB
/
bw2types.go
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package bw2bind
import (
"errors"
"fmt"
"strconv"
"strings"
"sync"
"time"
"github.com/immesys/bw2/objects"
)
// ElaborateDefault is the same as ElaboratePartial
const ElaborateDefault = ""
// ElaborateFull will copy the entire contents of every DOT in the dot chain
// into the message. This used to be useful before BW 2.1.x because it guaranteed
// that the receiver could verify the message. We now always have that guarantee
// so this is wasteful
const ElaborateFull = "full"
// ElaboratePartial will include the DOT hashes of all DOTs in the primary access
// chain in the message. This is required if the DOT chain is not published to
// the registry. This is the default elaboration option.
const ElaboratePartial = "partial"
// ElaborateNone only sends the DChain hash in the message. This will only work
// if the DChain is published to the registry.
const ElaborateNone = "none"
// PublishParams is used for Publish and Persist messages
type PublishParams struct {
// The URI you wish to publish to
URI string
// The PrimaryAccessChain hash, if you are manually specifying the chain.
// as of 2.1.x this is not recommended as it will not work unless the chain
// is published to the registry
PrimaryAccessChain string
// Tell the local router to build the chain for you, if you always set
// this value, consider using BW2Client.OverrideAutoChainTo()
AutoChain bool
// The routing objects to include in the message, this is not commonly used
RoutingObjects []objects.RoutingObject
// The payload objects to include in the message.
PayloadObjects []PayloadObject
// The expiry date of this message. Note that routers will reject messages
// that arrive after this time
Expiry *time.Time
// Same as expiry but expressed from now
ExpiryDelta *time.Duration
// The PAC elaboration level to use, defaults to ElaboratePartial
ElaboratePAC string
// By default the local router will verify the message before sending, setting
// this to true will disable this stage
DoNotVerify bool
// Do you want the message to be persist on the designated router
Persist bool
}
type SubscribeParams struct {
// The URI you wish to subscribe to
URI string
// The PrimaryAccessChain hash, if you are manually specifying the chain.
// as of 2.1.x this is not recommended as it will not work unless the chain
// is published to the registry
PrimaryAccessChain string
// Tell the local router to build the chain for you, if you always set
// this value, consider using BW2Client.OverrideAutoChainTo()
AutoChain bool
// The routing objects to include in the message, this is not commonly used
RoutingObjects []objects.RoutingObject
// The expiry date of this message. Note that routers will reject messages
// that arrive after this time. For subscribe this is essentially used
// for replay-protection in very corner-case attack vectors
Expiry *time.Time
// Same as expiry but expressed from now
ExpiryDelta *time.Duration
// The PAC elaboration level to use, defaults to ElaboratePartial
ElaboratePAC string
// By default the local router will verify the message before sending, setting
// this to true will disable this stage
DoNotVerify bool
// By default, the local router will take incoming messages and decompose
// them into PO's and RO's. If you want the message to remain packed in
// signed bosswave format, set this to true
LeavePacked bool
}
type ListParams struct {
// The URI you wish to list the children of
URI string
// The PrimaryAccessChain hash, if you are manually specifying the chain.
// as of 2.1.x this is not recommended as it will not work unless the chain
// is published to the registry
PrimaryAccessChain string
// Tell the local router to build the chain for you, if you always set
// this value, consider using BW2Client.OverrideAutoChainTo()
AutoChain bool
// The routing objects to include in the message, this is not commonly used
RoutingObjects []objects.RoutingObject
// The expiry date of this message. Note that routers will reject messages
// that arrive after this time. For subscribe this is essentially used
// for replay-protection in very corner-case attack vectors
Expiry *time.Time
// Same as expiry but expressed from now
ExpiryDelta *time.Duration
// The PAC elaboration level to use, defaults to ElaboratePartial
ElaboratePAC string
// By default the local router will verify the message before sending, setting
// this to true will disable this stage
DoNotVerify bool
}
type QueryParams struct {
// The URI you wish to query
URI string
// The PrimaryAccessChain hash, if you are manually specifying the chain.
// as of 2.1.x this is not recommended as it will not work unless the chain
// is published to the registry
PrimaryAccessChain string
// Tell the local router to build the chain for you, if you always set
// this value, consider using BW2Client.OverrideAutoChainTo()
AutoChain bool
// The routing objects to include in the message, this is not commonly used
RoutingObjects []objects.RoutingObject
// The expiry date of this message. Note that routers will reject messages
// that arrive after this time. For subscribe this is essentially used
// for replay-protection in very corner-case attack vectors
Expiry *time.Time
// Same as expiry but expressed from now
ExpiryDelta *time.Duration
// The PAC elaboration level to use, defaults to ElaboratePartial
ElaboratePAC string
// By default the local router will verify the message before sending, setting
// this to true will disable this stage
DoNotVerify bool
// By default, the local router will take incoming messages and decompose
// them into PO's and RO's. If you want the message to remain packed in
// signed bosswave format, set this to true
LeavePacked bool
}
type CreateDOTParams struct {
// Is this a permission DOT (hope not, they are not supported yet)
IsPermission bool
// The VK to grant the DOT to (from comes from BW2Client.SetEntity)
To string
// The time to live
TTL uint8
// The expiry time
Expiry *time.Time
// Same as Expiry but specified from now
ExpiryDelta *time.Duration
// The contact information of the DOT, typically "Name Surname <[email protected]>"
Contact string
// The comment information in the dot
Comment string
// The entities that are allowed to revoke this DOT
Revokers []string
// Leave the creation date out of the DOT (this is not normally used)
OmitCreationDate bool
// For Access DOTs, the URI to grant on
URI string
// For Access DOTs, the ADPS permissions e.g LPC*
AccessPermissions string
//For Permissions DOTs, don't use this yet
AppPermissions map[string]string
}
type CreateDotChainParams struct {
DOTs []string
IsPermission bool
UnElaborate bool
}
type CreateEntityParams struct {
Expiry *time.Time
ExpiryDelta *time.Duration
Contact string
Comment string
// The entities that will be allowed to revoke this entity
Revokers []string
OmitCreationDate bool
}
type BuildChainParams struct {
// The URI you wish to build a chain for
URI string
// The ADPS permissions you need (e.g. "LPC*")
Permissions string
// The VK to grant to
To string
}
type SimpleMessage struct {
From string
URI string
POs []PayloadObject
ROs []objects.RoutingObject
POErrors []error
Signature []byte
}
type SimpleChain struct {
Hash string
Permissions string
URI string
To string
Content []byte
}
// Dump a given message to the console, deconstructing it as much as possible
func (sm *SimpleMessage) Dump() {
fmt.Printf("Message from %s on %s:\n", sm.From, sm.URI)
for _, po := range sm.POs {
fmt.Println(po.TextRepresentation())
}
}
// PONumDotForm turns an integer Payload Object number into dotted quad form
func PONumDotForm(ponum int) string {
return fmt.Sprintf("%d.%d.%d.%d", ponum>>24, (ponum>>16)&0xFF, (ponum>>8)&0xFF, ponum&0xFF)
}
// PONumFromDotForm turns a dotted quad form into an integer Payload Object number
func PONumFromDotForm(dotform string) (int, error) {
parts := strings.Split(dotform, ".")
if len(parts) != 4 {
return 0, errors.New("Bad dotform")
}
rv := 0
for i := 0; i < 4; i++ {
cx, err := strconv.ParseUint(parts[i], 10, 8)
if err != nil {
return 0, err
}
rv += (int(cx)) << uint(((3 - i) * 8))
}
return rv, nil
}
// FromDotForm is a shortcut for PONumFromDotForm that panics
// if there is an error
func FromDotForm(dotform string) int {
rv, err := PONumFromDotForm(dotform)
if err != nil {
panic(err)
}
return rv
}
// GetOnePODF -Get a single Payload Object of the given Dot Form
// returns nil if there are none that match
func (sm *SimpleMessage) GetOnePODF(df string) PayloadObject {
for _, p := range sm.POs {
if p.IsTypeDF(df) {
return p
}
}
return nil
}
type View struct {
vid int
cl *BW2Client
cbz []func()
cbmu sync.Mutex
}
type InterfaceDescriptor struct {
URI string `msgpack:"uri"`
Interface string `msgpack:"iface"`
Service string `msgpack:"svc"`
Namespace string `msgpack:"namespace"`
Prefix string `msgpack:"prefix"`
Suffix string `msgpack:"suffix"`
Metadata map[string]string `msgpack:"metadata"`
v *View
}