Skip to main content

MachineToken

Struct MachineToken 

Source
pub struct MachineToken {
    pub version: u32,
    pub signing_secret: Vec<u8>,
    pub recipient_secret: Vec<u8>,
    pub content_key: Vec<u8>,
    pub source_commit: Vec<u8>,
    pub repo_name: Option<String>,
    pub expires_at: u64,
}
Expand description

A machine token — packaged credentials for scoped repo access.

Fields§

§version: u32

Version tag for forward compatibility.

§signing_secret: Vec<u8>

Ed25519 signing secret key (32 bytes) — for the machine’s own commits.

§recipient_secret: Vec<u8>

X25519 recipient secret key (32 bytes) — for ECIES operations.

§content_key: Vec<u8>

Content key (32 bytes) — scoped read access to source_commit.

§source_commit: Vec<u8>

CID of the source commit this token grants access to.

§repo_name: Option<String>

Repo name (for display/context).

§expires_at: u64

Unix timestamp after which this token is invalid.

Implementations§

Source§

impl MachineToken

Source

pub const VERSION: u32 = 1

Source

pub fn new( signing_secret: &SigningSecretKey, recipient_secret: &RecipientSecretKey, content_key: &[u8; 32], source_commit: Vec<u8>, repo_name: Option<String>, expires_at: u64, ) -> Self

Create a new machine token.

Source

pub fn is_expired(&self, now: u64) -> bool

Check if the token has expired.

Source

pub fn to_bytes(&self) -> CryptoResult<Vec<u8>>

Serialize to CBOR bytes.

Source

pub fn from_bytes(data: &[u8]) -> CryptoResult<Self>

Deserialize from CBOR bytes.

Source

pub fn seal(&self, key: &[u8; 32]) -> CryptoResult<Vec<u8>>

Encrypt the token with a passphrase-derived key.

The token is CBOR-serialized then AES-256-GCM encrypted. Use a key derived from a passphrase, PIN, or random secret.

Source

pub fn unseal(ciphertext: &[u8], key: &[u8; 32]) -> CryptoResult<Self>

Decrypt a sealed token.

Source

pub fn to_base64(&self) -> CryptoResult<String>

Encode as a base64 string (for env vars, CLI output).

Source

pub fn to_vault(&self) -> CryptoResult<KeyVault>

Create a content-key KeyVault from this token’s content key.

The vault is read-only — it can decrypt the source commit’s objects but cannot seal new commits.

Source

pub fn to_signing_key(&self) -> CryptoResult<SigningKey>

Extract the signing key from this token.

Source

pub fn from_base64(s: &str) -> CryptoResult<Self>

Decode from a base64 string.

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for MachineToken

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MachineToken

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,