Skip to main content

moonbase_licensing/
claims.rs

1use chrono::serde::ts_seconds;
2use chrono::serde::ts_seconds_option;
3use chrono::{DateTime, Utc};
4use serde::Deserialize;
5
6#[derive(Debug, Eq, PartialEq, Deserialize)]
7pub enum ActivationMethod {
8    /// The license has been activated offline and is irrevocable,
9    /// therefore we mustn't check license validity online.
10    Offline,
11    /// The license has been activated online
12    /// and may have been revoked from this machine since.
13    /// We should regularly ask Moonbase if the license is still valid.
14    Online,
15}
16
17/// The claims included in a validated license token provided by Moonbase.
18#[derive(Debug, Deserialize)]
19pub struct LicenseTokenClaims {
20    pub method: ActivationMethod,
21
22    /// The latest release version of the product, if any.
23    #[serde(rename = "p:rel")]
24    pub product_latest_version: Option<String>,
25
26    /// The name of the user that owns this license.
27    #[serde(rename = "u:name")]
28    pub user_name: String,
29
30    /// The signature of the device being activated.
31    /// Should be checked against the user's device signature.
32    #[serde(rename = "sig")]
33    pub device_signature: String,
34
35    /// The date and time at which the license token was last validated online.
36    #[serde(rename = "validated", with = "ts_seconds")]
37    pub last_validated: DateTime<Utc>,
38
39    /// The date and time at which the license expires.
40    #[serde(rename = "exp", with = "ts_seconds_option", default)]
41    pub expires_at: Option<DateTime<Utc>>,
42
43    /// Whether this license token represents a time-limited trial (true),
44    /// or an owned license (false).
45    pub trial: bool,
46}