Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lookup ¶
Example ¶
package main import ( "fmt" cert "github.com/aviate-labs/certificate-go" ) func main() { fmt.Println(string(cert.Lookup(path("a", "x"), tree))) fmt.Println(string(cert.Lookup(path("a", "y"), tree))) fmt.Println(string(cert.Lookup(path("b"), tree))) fmt.Println(string(cert.Lookup(path("d"), tree))) } func path(p ...string) [][]byte { var path [][]byte for _, p := range p { path = append(path, []byte(p)) } return path }
Output: hello world good morning
func Serialize ¶
Example ¶
package main import ( "fmt" cert "github.com/aviate-labs/certificate-go" ) var tree = cert.Fork{ LeftTree: cert.Fork{ LeftTree: cert.Labeled{ Label: []byte("a"), Tree: cert.Fork{ LeftTree: cert.Fork{ LeftTree: cert.Labeled{ Label: []byte("x"), Tree: cert.Leaf("hello"), }, RightTree: cert.Empty{}, }, RightTree: cert.Labeled{ Label: []byte("y"), Tree: cert.Leaf("world"), }, }, }, RightTree: cert.Labeled{ Label: []byte("b"), Tree: cert.Leaf("good"), }, }, RightTree: cert.Fork{ LeftTree: cert.Labeled{ Label: []byte("c"), Tree: cert.Empty{}, }, RightTree: cert.Labeled{ Label: []byte("d"), Tree: cert.Leaf("morning"), }, }, } func main() { b, _ := cert.Serialize(tree) fmt.Printf("%x", b) }
Output: 8301830183024161830183018302417882034568656c6c6f810083024179820345776f726c6483024162820344676f6f648301830241638100830241648203476d6f726e696e67
Types ¶
type Certificate ¶
type Certificate struct { Tree HashTree Signature []byte Delegation *Delegation }
type Delegation ¶
type Delegation struct { SubnetId principal.Principal // The nested certificate typically does not itself again contain a // delegation, although there is no reason why agents should enforce that // property. Certificate Certificate }
type Fork ¶
func (Fork) Reconstruct ¶
type HashTree ¶
type HashTree struct {
// contains filtered or unexported fields
}
func NewHashTree ¶
type LabelResult ¶
type LabelResult string
const ( Absent LabelResult = "absent" Continue LabelResult = "continue" Found LabelResult = "found" Unknown LabelResult = "unknown" )
type Labeled ¶
func (Labeled) Reconstruct ¶
type Node ¶
func Deserialize ¶
Example ¶
package main import ( "encoding/hex" "fmt" cert "github.com/aviate-labs/certificate-go" ) func main() { data, _ := hex.DecodeString("8301830183024161830183018302417882034568656c6c6f810083024179820345776f726c6483024162820344676f6f648301830241638100830241648203476d6f726e696e67") fmt.Println(cert.Deserialize(data)) }
Output: {{a:{{x:hello|∅}|y:world}|b:good}|{c:∅|d:morning}} <nil>
func DeserializeNode ¶ added in v0.0.2
type Pruned ¶
type Pruned [32]byte
Example ¶
package main import ( "encoding/hex" "fmt" cert "github.com/aviate-labs/certificate-go" ) var pruned = cert.Fork{ LeftTree: cert.Fork{ LeftTree: cert.Labeled{ Label: []byte("a"), Tree: cert.Fork{ LeftTree: cert.Pruned(h2b("1B4FEFF9BEF8131788B0C9DC6DBAD6E81E524249C879E9F10F71CE3749F5A638")), RightTree: cert.Labeled{ Label: []byte("y"), Tree: cert.Leaf("world"), }, }, }, RightTree: cert.Labeled{ Label: []byte("b"), Tree: cert.Pruned(h2b("7B32AC0C6BA8CE35AC82C255FC7906F7FC130DAB2A090F80FE12F9C2CAE83BA6")), }, }, RightTree: cert.Fork{ LeftTree: cert.Pruned(h2b("EC8324B8A1F1AC16BD2E806EDBA78006479C9877FED4EB464A25485465AF601D")), RightTree: cert.Labeled{ Label: []byte("d"), Tree: cert.Leaf("morning"), }, }, } func main() { fmt.Printf("%X", pruned.Reconstruct()) } func h2b(s string) [32]byte { var bs [32]byte b, _ := hex.DecodeString(s) copy(bs[:], b) return bs }
Output: EB5C5B2195E62D996B84C9BCC8259D19A83786A2F59E0878CEC84C811F669AA0
func (Pruned) Reconstruct ¶
Click to show internal directories.
Click to hide internal directories.