Struct keygen_rs::machine_file::MachineFile
source · pub struct MachineFile {
pub id: String,
pub certificate: String,
pub issued: DateTime<Utc>,
pub expiry: DateTime<Utc>,
pub ttl: i32,
}Fields§
§id: String§certificate: String§issued: DateTime<Utc>§expiry: DateTime<Utc>§ttl: i32Implementations§
source§impl MachineFile
impl MachineFile
pub fn from_cert(key: &str, content: &str) -> Result<MachineFile, Error>
sourcepub fn verify(&self) -> Result<(), Error>
pub fn verify(&self) -> Result<(), Error>
Examples found in repository?
examples/checkout_machine.rs (line 31)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
async fn main() -> Result<(), Error> {
dotenv().ok();
config::set_config(KeygenConfig {
api_url: env::var("KEYGEN_API_URL").expect("KEYGEN_API_URL must be set"),
account: env::var("KEYGEN_ACCOUNT").expect("KEYGEN_ACCOUNT must be set"),
product: env::var("KEYGEN_PRODUCT").expect("KEYGEN_PRODUCT must be set"),
license_key: Some(env::var("KEYGEN_LICENSE_KEY").expect("KEYGEN_LICENSE_KEY must be set")),
public_key: Some(env::var("KEYGEN_PUBLIC_KEY").expect("KEYGEN_PUBLIC_KEY must be set")),
..KeygenConfig::default()
});
let config = config::get_config();
let fingerprint = machine_uid::get().unwrap_or("".into());
if let Ok(license) = keygen_rs::validate(&[fingerprint.clone()], &[]).await {
let machine = license.machine(&fingerprint).await?;
let options = MachineCheckoutOpts {
ttl: Some(chrono::Duration::days(7).num_seconds()),
include: None,
};
let machine_file = machine.checkout(&options).await?;
if machine_file.verify().is_ok() {
// the encryption secret for a machine file is the license key concatenated with the machine fingerprint
// https://keygen.sh/docs/api/cryptography/#cryptographic-lic-decrypt
let key = format!("{}{}", config.license_key.unwrap(), machine.fingerprint);
let dataset = machine_file.decrypt(&key)?;
println!("Machine checkout successful: {:?}", dataset);
}
} else {
println!("License validation failed");
};
Ok(())
}sourcepub fn decrypt(&self, key: &str) -> Result<MachineFileDataset, Error>
pub fn decrypt(&self, key: &str) -> Result<MachineFileDataset, Error>
Examples found in repository?
examples/checkout_machine.rs (line 35)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
async fn main() -> Result<(), Error> {
dotenv().ok();
config::set_config(KeygenConfig {
api_url: env::var("KEYGEN_API_URL").expect("KEYGEN_API_URL must be set"),
account: env::var("KEYGEN_ACCOUNT").expect("KEYGEN_ACCOUNT must be set"),
product: env::var("KEYGEN_PRODUCT").expect("KEYGEN_PRODUCT must be set"),
license_key: Some(env::var("KEYGEN_LICENSE_KEY").expect("KEYGEN_LICENSE_KEY must be set")),
public_key: Some(env::var("KEYGEN_PUBLIC_KEY").expect("KEYGEN_PUBLIC_KEY must be set")),
..KeygenConfig::default()
});
let config = config::get_config();
let fingerprint = machine_uid::get().unwrap_or("".into());
if let Ok(license) = keygen_rs::validate(&[fingerprint.clone()], &[]).await {
let machine = license.machine(&fingerprint).await?;
let options = MachineCheckoutOpts {
ttl: Some(chrono::Duration::days(7).num_seconds()),
include: None,
};
let machine_file = machine.checkout(&options).await?;
if machine_file.verify().is_ok() {
// the encryption secret for a machine file is the license key concatenated with the machine fingerprint
// https://keygen.sh/docs/api/cryptography/#cryptographic-lic-decrypt
let key = format!("{}{}", config.license_key.unwrap(), machine.fingerprint);
let dataset = machine_file.decrypt(&key)?;
println!("Machine checkout successful: {:?}", dataset);
}
} else {
println!("License validation failed");
};
Ok(())
}pub fn certificate(&self) -> Result<Certificate, Error>
Trait Implementations§
source§impl Clone for MachineFile
impl Clone for MachineFile
source§fn clone(&self) -> MachineFile
fn clone(&self) -> MachineFile
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for MachineFile
impl Debug for MachineFile
source§impl<'de> Deserialize<'de> for MachineFile
impl<'de> Deserialize<'de> for MachineFile
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for MachineFile
impl RefUnwindSafe for MachineFile
impl Send for MachineFile
impl Sync for MachineFile
impl Unpin for MachineFile
impl UnwindSafe for MachineFile
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)