/
bcrypter.vdl.go
493 lines (456 loc) · 12.8 KB
/
bcrypter.vdl.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file was auto-generated by the vanadium vdl tool.
// Package: bcrypter
//nolint:golint
package bcrypter
import (
"v.io/v23/context"
"v.io/v23/i18n"
"v.io/v23/security"
"v.io/v23/vdl"
"v.io/v23/verror"
)
var _ = initializeVDL() // Must be first; see initializeVDL comments for details.
//////////////////////////////////////////////////
// Type definitions
// WireCiphertext represents the wire format of the ciphertext
// generated by a Crypter.
type WireCiphertext struct {
// PatternId is an identifier of the blessing pattern that this
// ciphertext is for. It is represented by a 16 byte truncated
// SHA256 hash of the pattern.
PatternId string
// Bytes is a map from an identifier of the public IBE params to
// the ciphertext bytes that were generated using those params.
//
// The params identifier is a 16 byte truncated SHA256 hash
// of the marshaled form of the IBE params.
Bytes map[string][]byte
}
func (WireCiphertext) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/lib/security/bcrypter.WireCiphertext"`
}) {
}
func (x WireCiphertext) VDLIsZero() bool { //nolint:gocyclo
if x.PatternId != "" {
return false
}
if len(x.Bytes) != 0 {
return false
}
return true
}
func (x WireCiphertext) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct1); err != nil {
return err
}
if x.PatternId != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.PatternId); err != nil {
return err
}
}
if len(x.Bytes) != 0 {
if err := enc.NextField(1); err != nil {
return err
}
if err := vdlWriteAnonMap1(enc, x.Bytes); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonMap1(enc vdl.Encoder, x map[string][]byte) error {
if err := enc.StartValue(vdlTypeMap2); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for key, elem := range x {
if err := enc.NextEntryValueString(vdl.StringType, key); err != nil {
return err
}
if err := enc.WriteValueBytes(vdlTypeList3, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *WireCiphertext) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = WireCiphertext{}
if err := dec.StartValue(vdlTypeStruct1); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct1 {
index = vdlTypeStruct1.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.PatternId = value
}
case 1:
if err := vdlReadAnonMap1(dec, &x.Bytes); err != nil {
return err
}
}
}
}
func vdlReadAnonMap1(dec vdl.Decoder, x *map[string][]byte) error {
if err := dec.StartValue(vdlTypeMap2); err != nil {
return err
}
var tmpMap map[string][]byte
if len := dec.LenHint(); len > 0 {
tmpMap = make(map[string][]byte, len)
}
for {
switch done, key, err := dec.NextEntryValueString(); {
case err != nil:
return err
case done:
*x = tmpMap
return dec.FinishValue()
default:
var elem []byte
if err := dec.ReadValueBytes(-1, &elem); err != nil {
return err
}
if tmpMap == nil {
tmpMap = make(map[string][]byte)
}
tmpMap[key] = elem
}
}
}
// WireParams represents the wire format of the public parameters
// of an identity provider (aka Root).
type WireParams struct {
// Blessing is the blessing name of the identity provider. The identity
// provider can extract private keys for blessings that are extensions
// of this blessing name.
Blessing string
// Params is the marshaled form of the public IBE params of the
// the identity provider.
Params []byte
}
func (WireParams) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/lib/security/bcrypter.WireParams"`
}) {
}
func (x WireParams) VDLIsZero() bool { //nolint:gocyclo
if x.Blessing != "" {
return false
}
if len(x.Params) != 0 {
return false
}
return true
}
func (x WireParams) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct4); err != nil {
return err
}
if x.Blessing != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Blessing); err != nil {
return err
}
}
if len(x.Params) != 0 {
if err := enc.NextFieldValueBytes(1, vdlTypeList3, x.Params); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *WireParams) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = WireParams{}
if err := dec.StartValue(vdlTypeStruct4); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct4 {
index = vdlTypeStruct4.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Blessing = value
}
case 1:
if err := dec.ReadValueBytes(-1, &x.Params); err != nil {
return err
}
}
}
}
// WirePrivateKey represents the wire format of the private key corresponding
// to a blessing.
type WirePrivateKey struct {
// Blessing is the blessing for which this private key was extracted for.
Blessing string
// Params are the public parameters of the identity provider that extracted
// this private key.
Params WireParams
// Keys contain the extracted IBE private keys for each pattern that is
// matched by the blessing and is an extension of the identity provider's
// name. The keys are enumerated in increasing order of the lengths of the
// corresponding patterns.
//
// For example, if the blessing is "google:u:alice:phone" and the identity
// provider's name is "google:u" then the keys are extracted for the patterns
// - "google:u"
// - "google:u:alice"
// - "google:u:alice:phone"
// - "google:u:alice:phone:$"
//
// The private keys are listed in increasing order of the lengths of the
// corresponding patterns.
Keys [][]byte
}
func (WirePrivateKey) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/lib/security/bcrypter.WirePrivateKey"`
}) {
}
func (x WirePrivateKey) VDLIsZero() bool { //nolint:gocyclo
if x.Blessing != "" {
return false
}
if !x.Params.VDLIsZero() {
return false
}
if len(x.Keys) != 0 {
return false
}
return true
}
func (x WirePrivateKey) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct5); err != nil {
return err
}
if x.Blessing != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Blessing); err != nil {
return err
}
}
if !x.Params.VDLIsZero() {
if err := enc.NextField(1); err != nil {
return err
}
if err := x.Params.VDLWrite(enc); err != nil {
return err
}
}
if len(x.Keys) != 0 {
if err := enc.NextField(2); err != nil {
return err
}
if err := vdlWriteAnonList2(enc, x.Keys); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonList2(enc vdl.Encoder, x [][]byte) error {
if err := enc.StartValue(vdlTypeList6); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for _, elem := range x {
if err := enc.NextEntryValueBytes(vdlTypeList3, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *WirePrivateKey) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = WirePrivateKey{}
if err := dec.StartValue(vdlTypeStruct5); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct5 {
index = vdlTypeStruct5.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Blessing = value
}
case 1:
if err := x.Params.VDLRead(dec); err != nil {
return err
}
case 2:
if err := vdlReadAnonList2(dec, &x.Keys); err != nil {
return err
}
}
}
}
func vdlReadAnonList2(dec vdl.Decoder, x *[][]byte) error {
if err := dec.StartValue(vdlTypeList6); err != nil {
return err
}
if len := dec.LenHint(); len > 0 {
*x = make([][]byte, 0, len)
} else {
*x = nil
}
for {
switch done, err := dec.NextEntry(); {
case err != nil:
return err
case done:
return dec.FinishValue()
default:
var elem []byte
if err := dec.ReadValueBytes(-1, &elem); err != nil {
return err
}
*x = append(*x, elem)
}
}
}
//////////////////////////////////////////////////
// Error definitions
var (
ErrInternal = verror.Register("v.io/x/ref/lib/security/bcrypter.Internal", verror.NoRetry, "{1:}{2:} internal error: {3}")
ErrNoParams = verror.Register("v.io/x/ref/lib/security/bcrypter.NoParams", verror.NoRetry, "{1:}{2:} no public parameters available for encrypting for pattern: {3}")
ErrPrivateKeyNotFound = verror.Register("v.io/x/ref/lib/security/bcrypter.PrivateKeyNotFound", verror.NoRetry, "{1:}{2:} no private key found for decrypting ciphertext")
ErrInvalidPrivateKey = verror.Register("v.io/x/ref/lib/security/bcrypter.InvalidPrivateKey", verror.NoRetry, "{1:}{2:} private key is invalid: {3}")
)
// NewErrInternal returns an error with the ErrInternal ID.
func NewErrInternal(ctx *context.T, err error) error {
return verror.New(ErrInternal, ctx, err)
}
// NewErrNoParams returns an error with the ErrNoParams ID.
func NewErrNoParams(ctx *context.T, pattern security.BlessingPattern) error {
return verror.New(ErrNoParams, ctx, pattern)
}
// NewErrPrivateKeyNotFound returns an error with the ErrPrivateKeyNotFound ID.
func NewErrPrivateKeyNotFound(ctx *context.T) error {
return verror.New(ErrPrivateKeyNotFound, ctx)
}
// NewErrInvalidPrivateKey returns an error with the ErrInvalidPrivateKey ID.
func NewErrInvalidPrivateKey(ctx *context.T, err error) error {
return verror.New(ErrInvalidPrivateKey, ctx, err)
}
// Hold type definitions in package-level variables, for better performance.
//nolint:unused
var (
vdlTypeStruct1 *vdl.Type
vdlTypeMap2 *vdl.Type
vdlTypeList3 *vdl.Type
vdlTypeStruct4 *vdl.Type
vdlTypeStruct5 *vdl.Type
vdlTypeList6 *vdl.Type
)
var initializeVDLCalled bool
// initializeVDL performs vdl initialization. It is safe to call multiple times.
// If you have an init ordering issue, just insert the following line verbatim
// into your source files in this package, right after the "package foo" clause:
//
// var _ = initializeVDL()
//
// The purpose of this function is to ensure that vdl initialization occurs in
// the right order, and very early in the init sequence. In particular, vdl
// registration and package variable initialization needs to occur before
// functions like vdl.TypeOf will work properly.
//
// This function returns a dummy value, so that it can be used to initialize the
// first var in the file, to take advantage of Go's defined init order.
func initializeVDL() struct{} {
if initializeVDLCalled {
return struct{}{}
}
initializeVDLCalled = true
// Register types.
vdl.Register((*WireCiphertext)(nil))
vdl.Register((*WireParams)(nil))
vdl.Register((*WirePrivateKey)(nil))
// Initialize type definitions.
vdlTypeStruct1 = vdl.TypeOf((*WireCiphertext)(nil)).Elem()
vdlTypeMap2 = vdl.TypeOf((*map[string][]byte)(nil))
vdlTypeList3 = vdl.TypeOf((*[]byte)(nil))
vdlTypeStruct4 = vdl.TypeOf((*WireParams)(nil)).Elem()
vdlTypeStruct5 = vdl.TypeOf((*WirePrivateKey)(nil)).Elem()
vdlTypeList6 = vdl.TypeOf((*[][]byte)(nil))
// Set error format strings.
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrInternal.ID), "{1:}{2:} internal error: {3}")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrNoParams.ID), "{1:}{2:} no public parameters available for encrypting for pattern: {3}")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrPrivateKeyNotFound.ID), "{1:}{2:} no private key found for decrypting ciphertext")
i18n.Cat().SetWithBase(i18n.LangID("en"), i18n.MsgID(ErrInvalidPrivateKey.ID), "{1:}{2:} private key is invalid: {3}")
return struct{}{}
}