-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinterface.go
More file actions
75 lines (65 loc) · 1.59 KB
/
interface.go
File metadata and controls
75 lines (65 loc) · 1.59 KB
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
// Copyright 2015 Canonical Ltd.
// Licensed under the LGPL, see LICENCE file for details.
package macarooncompat
import (
"fmt"
)
type Macaroon interface {
MarshalJSON() ([]byte, error)
MarshalBinary() ([]byte, error)
WithFirstPartyCaveat(caveatId string) (Macaroon, error)
WithThirdPartyCaveat(rootKey []byte, caveatId string, loc string) (Macaroon, error)
Bind(primary Macaroon) (Macaroon, error)
Verify(rootKey []byte, check Checker, discharges []Macaroon) error
Signature() []byte
}
type Checker map[string]bool
func (c Checker) Check(cav string) error {
if c[cav] {
return nil
}
return fmt.Errorf("condition %q not met", cav)
}
type Package interface {
UnmarshalJSON(data []byte) (Macaroon, error)
UnmarshalBinary(data []byte) (Macaroon, error)
New(rootKey []byte, id, loc string) (Macaroon, error)
}
type Implementation string
const (
ImplGoV1 Implementation = "gov1"
ImplGoV2 Implementation = "gov2"
ImplLibMacaroons2 Implementation = "libmacaroons2"
ImplJSMacaroon Implementation = "jsmacaroon"
ImplPyMacaroons2 Implementation = "pymacaroons2"
ImplPyMacaroons3 Implementation = "pymacaroons3"
)
var Implementations = []struct {
Name Implementation
Pkg Package
}{{
Name: ImplGoV1,
Pkg: goMacaroonV1Package{},
}, {
Name: ImplGoV2,
Pkg: goMacaroonV2Package{},
}, {
Name: ImplLibMacaroons2,
Pkg: libMacaroonsPkg{
version: 2,
},
}, {
Name: ImplJSMacaroon,
Pkg: jsMacaroonPkg{},
}, {
Name: ImplPyMacaroons2,
Pkg: pyMacaroonsPkg{
version: 2,
},
}, {
Name: ImplPyMacaroons3,
Pkg: pyMacaroonsPkg{
version: 3,
},
}}
// TODO add libmacaroons python 3.