示例#1
0
// Unmarshal unmarshals a macaroon in the format produced
// by Marshal. It also accepts base64-encoded JSON format.
func Unmarshal(s string) (*Macaroon, error) {
	var err C.enum_macaroon_returncode
	data := cStr(s)
	m := C.macaroon_deserialize(data, &err)
	if m == nil { // TODO: err gets set to INVALID even if this returns successful, fix that
		return nil, macaroonError(err)
	}
	return &Macaroon{m}, nil
}
示例#2
0
// UnmarshalBinary unmarshals the macaroon from binary
// format.
func (m *Macaroon) UnmarshalBinary(data []byte) error {
	// libmacaroons expects the serialization in base64 encoding already,
	// but we just have the binary, so encode it for libmacaroons.
	b64data := make([]byte, base64.URLEncoding.EncodedLen(len(data)))
	base64.URLEncoding.Encode(b64data, data)
	var err C.enum_macaroon_returncode
	cm := C.macaroon_deserialize(cbuf(b64data), &err)
	if cm == nil {
		return macaroonError(err)
	}
	m.m = cm
	return nil
}