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: u32Version 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: u64Unix timestamp after which this token is invalid.
Implementations§
Source§impl MachineToken
impl MachineToken
pub const VERSION: u32 = 1
Sourcepub fn new(
signing_secret: &SigningSecretKey,
recipient_secret: &RecipientSecretKey,
content_key: &[u8; 32],
source_commit: Vec<u8>,
repo_name: Option<String>,
expires_at: u64,
) -> MachineToken
pub fn new( signing_secret: &SigningSecretKey, recipient_secret: &RecipientSecretKey, content_key: &[u8; 32], source_commit: Vec<u8>, repo_name: Option<String>, expires_at: u64, ) -> MachineToken
Create a new machine token.
Sourcepub fn is_expired(&self, now: u64) -> bool
pub fn is_expired(&self, now: u64) -> bool
Check if the token has expired.
Sourcepub fn from_bytes(data: &[u8]) -> Result<MachineToken, CryptoError>
pub fn from_bytes(data: &[u8]) -> Result<MachineToken, CryptoError>
Deserialize from CBOR bytes.
Sourcepub fn seal(&self, key: &[u8; 32]) -> Result<Vec<u8>, CryptoError>
pub fn seal(&self, key: &[u8; 32]) -> Result<Vec<u8>, CryptoError>
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.
Sourcepub fn unseal(
ciphertext: &[u8],
key: &[u8; 32],
) -> Result<MachineToken, CryptoError>
pub fn unseal( ciphertext: &[u8], key: &[u8; 32], ) -> Result<MachineToken, CryptoError>
Decrypt a sealed token.
Sourcepub fn to_base64(&self) -> Result<String, CryptoError>
pub fn to_base64(&self) -> Result<String, CryptoError>
Encode as a base64 string (for env vars, CLI output).
Sourcepub fn to_vault(&self) -> Result<KeyVault, CryptoError>
pub fn to_vault(&self) -> Result<KeyVault, CryptoError>
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.
Sourcepub fn to_signing_key(&self) -> Result<SigningKey, CryptoError>
pub fn to_signing_key(&self) -> Result<SigningKey, CryptoError>
Extract the signing key from this token.
Sourcepub fn from_base64(s: &str) -> Result<MachineToken, CryptoError>
pub fn from_base64(s: &str) -> Result<MachineToken, CryptoError>
Decode from a base64 string.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MachineToken
impl<'de> Deserialize<'de> for MachineToken
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<MachineToken, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<MachineToken, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for MachineToken
impl Serialize for MachineToken
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for MachineToken
impl RefUnwindSafe for MachineToken
impl Send for MachineToken
impl Sync for MachineToken
impl Unpin for MachineToken
impl UnsafeUnpin for MachineToken
impl UnwindSafe for MachineToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more