pub struct Macaroon { /* private fields */ }Expand description
A Macaroon has a location, identifier, signature, and caveats.
Implementations§
Source§impl Macaroon
impl Macaroon
Sourcepub fn new(
location: impl Into<String>,
identifier: impl Into<String>,
secret: Secret,
) -> Result<Self, Error>
pub fn new( location: impl Into<String>, identifier: impl Into<String>, secret: Secret, ) -> Result<Self, Error>
Mint a new macaroon for the location, identifier, and root secret.
Sourcepub fn location(&self) -> &str
pub fn location(&self) -> &str
The location of the macaroon. This will be provided to the loader. Intentionally not protected by the signature; it should be a hint to where the macaroon came from.
Sourcepub fn identifier(&self) -> &str
pub fn identifier(&self) -> &str
The identifier for the macaroon. This is how the server will translate the macaroon to its root secret.
Sourcepub fn signature(&self) -> &Secret
pub fn signature(&self) -> &Secret
The signature of the macaroon. Keep it secret or any derived macaroons can be leaked.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Decode exactly one macaroon from its prototk byte representation.
Trailing bytes are rejected.
Sourcepub fn caveat_count(&self) -> usize
pub fn caveat_count(&self) -> usize
The number of caveats attached to the macaroon.
Sourcepub fn caveats(
&self,
) -> impl ExactSizeIterator<Item = CaveatRef<'_>> + DoubleEndedIterator + '_
pub fn caveats( &self, ) -> impl ExactSizeIterator<Item = CaveatRef<'_>> + DoubleEndedIterator + '_
Iterate over read-only caveat views.
Sourcepub fn has_caveats(&self) -> bool
pub fn has_caveats(&self) -> bool
Returns true if this macaroon has any caveats.
Sourcepub fn add_exact_string(&mut self, what: impl Into<String>) -> Result<(), Error>
pub fn add_exact_string(&mut self, what: impl Into<String>) -> Result<(), Error>
Add a caveat that must match exactly.
Sourcepub fn add_fact(
&mut self,
name: &'static str,
value: impl Display,
) -> Result<(), Error>
pub fn add_fact( &mut self, name: &'static str, value: impl Display, ) -> Result<(), Error>
Add a canonical exact-string fact caveat.
The fact name is static so application code controls the vocabulary. The caveat string is
formatted as "{name} = {value}".
Sourcepub fn add_expires(&mut self, when: u64) -> Result<(), Error>
pub fn add_expires(&mut self, when: u64) -> Result<(), Error>
Add a caveat that expires the macaroon after when.
Sourcepub fn add_expires_at(&mut self, when: SystemTime) -> Result<(), Error>
pub fn add_expires_at(&mut self, when: SystemTime) -> Result<(), Error>
Add an expiration caveat from a SystemTime.
Sourcepub fn add_not_before(&mut self, when: u64) -> Result<(), Error>
pub fn add_not_before(&mut self, when: u64) -> Result<(), Error>
Add a caveat that rejects verifier times before when.
Sourcepub fn add_not_before_at(&mut self, when: SystemTime) -> Result<(), Error>
pub fn add_not_before_at(&mut self, when: SystemTime) -> Result<(), Error>
Add a not-before caveat from a SystemTime.
Sourcepub fn add_ttl(&mut self, ttl: Duration) -> Result<(), Error>
pub fn add_ttl(&mut self, ttl: Duration) -> Result<(), Error>
Add a fresh expiration caveat for ttl after the current system time.
This appends a new caveat. It does not replace earlier expiration caveats, so the effective expiration remains the minimum of all expiration caveats.
Sourcepub fn add_ttl_from(
&mut self,
now: SystemTime,
ttl: Duration,
) -> Result<(), Error>
pub fn add_ttl_from( &mut self, now: SystemTime, ttl: Duration, ) -> Result<(), Error>
Add a fresh expiration caveat for ttl after now.
This is useful for deterministic tests and for applications that already captured request time.
Sourcepub fn add_third_party_caveat(
&mut self,
location: impl Into<String>,
identifier: impl Into<String>,
secret: ThirdPartySecret,
) -> Result<(), Error>
pub fn add_third_party_caveat( &mut self, location: impl Into<String>, identifier: impl Into<String>, secret: ThirdPartySecret, ) -> Result<(), Error>
Add a third party caveat. Provide signature() to ask the third party to generate the
identifier and secret.
The location is an unsigned routing hint. Verification depends on the identifier, encrypted verification-key material, and signature chain.
Sourcepub fn bind_discharge(&self, discharge: &mut Macaroon) -> Result<(), Error>
pub fn bind_discharge(&self, discharge: &mut Macaroon) -> Result<(), Error>
Bind a macaroon to the request to make sure discharge macaroons cannot be used in other contexts.
Sourcepub fn bind_discharge_owned(
&self,
discharge: Macaroon,
) -> Result<Macaroon, Error>
pub fn bind_discharge_owned( &self, discharge: Macaroon, ) -> Result<Macaroon, Error>
Bind and return a single discharge macaroon.
This is the owned-value form of Macaroon::bind_discharge.
Sourcepub fn bind_discharges(&self, discharges: &mut [Macaroon]) -> Result<(), Error>
pub fn bind_discharges(&self, discharges: &mut [Macaroon]) -> Result<(), Error>
Bind every discharge macaroon in place.
Sourcepub fn bind_discharges_owned<I>(
&self,
discharges: I,
) -> Result<Vec<Macaroon>, Error>where
I: IntoIterator<Item = Macaroon>,
pub fn bind_discharges_owned<I>(
&self,
discharges: I,
) -> Result<Vec<Macaroon>, Error>where
I: IntoIterator<Item = Macaroon>,
Bind owned discharge macaroons and return them as a vector.
Sourcepub fn covering_set(
&self,
candidates: &[Macaroon],
) -> Result<Vec<Macaroon>, Error>
pub fn covering_set( &self, candidates: &[Macaroon], ) -> Result<Vec<Macaroon>, Error>
Assemble the transitive discharge cover from candidates.
The returned set contains discharge macaroons only, not self. Selection is based only on
public macaroon data: locations, identifiers, and third-party caveat references. This does
not verify signatures, decrypt third-party secrets, or prove that the selected macaroons
satisfy their caveats; pass the returned set to Verifier::verify for that.
If more than one candidate has the same public location and identifier, the first candidate is selected because public data cannot distinguish which proof is valid.
Sourcepub fn covering_set_refs<'a>(
&self,
candidates: &'a [Macaroon],
) -> Result<Vec<&'a Macaroon>, Error>
pub fn covering_set_refs<'a>( &self, candidates: &'a [Macaroon], ) -> Result<Vec<&'a Macaroon>, Error>
Assemble the transitive discharge cover from candidates, returning references into the
candidate slice.
See Macaroon::covering_set for selection semantics.
Trait Implementations§
impl Eq for Macaroon
Source§impl<'prototk> FieldPackHelper<'prototk, message<Macaroon>> for Macaroon
impl<'prototk> FieldPackHelper<'prototk, message<Macaroon>> for Macaroon
Source§fn field_pack_sz(&self, tag: &Tag) -> usize
fn field_pack_sz(&self, tag: &Tag) -> usize
Source§fn field_pack(&self, tag: &Tag, out: &mut [u8])
fn field_pack(&self, tag: &Tag, out: &mut [u8])
Source§impl<'prototk> FieldUnpackHelper<'prototk, message<Macaroon>> for Macaroon
impl<'prototk> FieldUnpackHelper<'prototk, message<Macaroon>> for Macaroon
Source§fn merge_field(&mut self, proto: message<Macaroon>)
fn merge_field(&mut self, proto: message<Macaroon>)
impl<'prototk> Message<'prototk> for Macaroon
Source§impl Packable for Macaroon
impl Packable for Macaroon
Source§fn pack_sz(&self) -> usize
fn pack_sz(&self) -> usize
pack_sz returns the number of bytes required to serialize the Packable object.Source§fn pack(&self, buf: &mut [u8])
fn pack(&self, buf: &mut [u8])
pack fills in the buffer out with the packed binary representation of the Packable
object. The implementor is responsible to ensure that out is exactly pack_sz() bytes
and implementations are encouraged to assert this. Read moreSource§fn stream<W: Write>(&self, writer: &mut W) -> Result<usize, Error>
fn stream<W: Write>(&self, writer: &mut W) -> Result<usize, Error>
stream writes the object to the provided writer using the same representation that would
be used in a call to pack. The implementor is responsible for making sure that the
number of bytes written is exactly equal to the number of required bytes. Read more