Exemplo n.º 1
0
// WithFirstPartyCaveat adds a first party caveat with the given predicate
// to m.
func (m *Macaroon) WithFirstPartyCaveat(predicate string) error {
	mNext, err := m.newFirstPartyCaveat(predicate)
	if err != nil {
		return err
	}
	mPrev := m.m
	m.m = mNext.m
	C.macaroon_destroy(mPrev)
	return nil
}
Exemplo n.º 2
0
// WithThirdPartyCaveat adds a caveat with the given location,
// key and id to m.
func (m *Macaroon) WithThirdPartyCaveat(location, key, id string) error {
	mNext, err := m.newThirdPartyCaveat(location, key, id)
	if err != nil {
		return err
	}
	mPrev := m.m
	m.m = mNext.m
	C.macaroon_destroy(mPrev)
	return nil
}
Exemplo n.º 3
0
// NewMacaroon returns a new macaroon with the given location,
// root key and identifier.
func NewMacaroon(location, key, id string) (*Macaroon, error) {
	var err C.enum_macaroon_returncode
	cLoc, cLocSz := cUStrN(location)
	cKey, cKeySz := cUStrN(key)
	cId, cIdSz := cUStrN(id)
	m := C.macaroon_create(cLoc, cLocSz, cKey, cKeySz, cId, cIdSz, &err)
	if err != 0 {
		defer C.macaroon_destroy(m)
		return nil, macaroonError(err)
	}
	return &Macaroon{m}, nil
}
Exemplo n.º 4
0
// Destroy frees the memory held by a macaroon.
func (m *Macaroon) Destroy() {
	C.macaroon_destroy(m.m)
	m.m = nil
}