summaryrefslogtreecommitdiffstats
path: root/lib/src/profile/device.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/profile/device.rs')
-rw-r--r--lib/src/profile/device.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/src/profile/device.rs b/lib/src/profile/device.rs
new file mode 100644
index 0000000..daeab21
--- /dev/null
+++ b/lib/src/profile/device.rs
@@ -0,0 +1,31 @@
+use std::convert::TryFrom;
+use std::convert::TryInto;
+use anyhow::Result;
+
+#[derive(Clone, Debug)]
+pub struct Device {
+ device_id: libp2p::identity::ed25519::PublicKey,
+}
+
+#[derive(Debug, serde::Serialize, serde::Deserialize)]
+pub struct DeviceSaveable {
+ device_id: Vec<u8>,
+}
+
+impl TryFrom<Device> for DeviceSaveable {
+ type Error = anyhow::Error;
+
+ fn try_from(device: Device) -> Result<Self> {
+ Ok(DeviceSaveable { device_id: device.device_id.encode().to_vec() })
+ }
+}
+
+impl TryInto<Device> for DeviceSaveable {
+ type Error = anyhow::Error;
+
+ fn try_into(self) -> Result<Device> {
+ libp2p::identity::ed25519::PublicKey::decode(&self.device_id)
+ .map(|device_id| Device { device_id })
+ .map_err(anyhow::Error::from)
+ }
+}