Skip to main content

glsdk/
credentials.rs

1use crate::Error;
2use gl_client::credentials::Device as DeviceCredentials;
3
4/// A developer certificate obtained from the Greenlight Developer
5/// Console (GDC). When provided to a `Scheduler` via
6/// `with_developer_cert()`, nodes registered through that scheduler
7/// will be associated with the developer's account.
8///
9/// If no developer certificate is provided, the scheduler falls back
10/// to the compiled-in default certificate, which may be sufficient
11/// when using an invite code instead.
12#[derive(uniffi::Object, Clone)]
13pub struct DeveloperCert {
14    pub(crate) inner: gl_client::credentials::Nobody,
15}
16
17#[uniffi::export]
18impl DeveloperCert {
19    /// Create a new `DeveloperCert` from the certificate and private
20    /// key PEM bytes obtained from the Greenlight Developer Console.
21    #[uniffi::constructor()]
22    pub fn new(cert: Vec<u8>, key: Vec<u8>) -> Self {
23        Self {
24            inner: gl_client::credentials::Nobody::with(cert, key),
25        }
26    }
27}
28
29/// `Credentials` is a container for `node_id`, the mTLS client
30/// certificate used to authenticate a client against a node, as well
31/// as the seed secret if present. If no seed is present in the
32/// credentials, then the `Client` will not start a signer in the
33/// background.
34#[derive(uniffi::Object, Clone)]
35pub struct Credentials {
36    pub(crate) inner: DeviceCredentials,
37}
38
39#[uniffi::export]
40impl Credentials {
41    #[uniffi::constructor()]
42    pub fn load(raw: Vec<u8>) -> Result<Credentials, Error> {
43        Ok(Self {
44            inner: DeviceCredentials::from_bytes(raw),
45        })
46    }
47
48    pub fn save(&self) -> Result<Vec<u8>, Error> {
49        Ok(self.inner.to_bytes())
50    }
51}