tuupola / branca-spec

Authenticated and encrypted API tokens using modern crypto
https://www.branca.io/
219 stars 7 forks source link

Go implementation #8

Closed tuupola closed 6 years ago

tuupola commented 6 years ago

Go implementation is missing. Something similar as fernet-go by @kr. Anyone interested in implementing it write me a note here and I will add it to the docs.

hako commented 6 years ago

@tuupola I would like to do this one, I'll let you know here again once it's complete.

tuupola commented 6 years ago

Great! Let me know and I will update the docs.

hako commented 6 years ago

@tuupola I have a work in progress Go implementation of branca at hako/branca. It currently uses libsodium-go, license is MIT.

Any feedback would be appreciated.

tuupola commented 6 years ago

Everything looks great! In the examples maybe make two small changes.

I will add some more test vectors to the spec. It has been on my todo list for a while. How big hassle was the installing of libdsodium for Go?

hako commented 6 years ago

Thanks for the feedback @tuupola

It was a not much of a hassle for me, but it's not as simple as a go get and you're good to go, it requires additional steps to install, especially on Windows. (which I need to test).

tuupola commented 6 years ago

@hako could you send me example usage for Go which I can use here: https://branca.io/

Example should have the same payload and usage as the other examples. Thanks!

hako commented 6 years ago

@tuupola Here is a short working example based on the ones on the homepage in Go.

package main

import (
        "fmt"
    "encoding/json"

    "github.com/hako/branca"
)

func main() {
    brca := branca.NewBranca("supersecretkeyyoushouldnotcommit")

    data := struct {
        User  string   `json:"user"`
        Scope []string `json:"scope"`
    }{
        User:  "someone@example.com",
        Scope: []string{"read", "write", "delete"},
    }

    jsn, err := json.Marshal(data)
    token, err := brca.EncodeToString(string(jsn[:]))
    payload, err := brca.DecodeToString(token)
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println(token)
    fmt.Println(payload)
}
tuupola commented 6 years ago

Thanks!