From cda0f946da996ca2feaaf2edbc70570f45a812e5 Mon Sep 17 00:00:00 2001 From: jane400 Date: Sun, 18 Aug 2024 18:09:27 +0200 Subject: [PATCH] feat: add device_id to CustomerKeySeed --- libpaket/src/locker/crypto.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libpaket/src/locker/crypto.rs b/libpaket/src/locker/crypto.rs index abb0688..85f8e94 100644 --- a/libpaket/src/locker/crypto.rs +++ b/libpaket/src/locker/crypto.rs @@ -6,9 +6,10 @@ use ed25519_dalek::Signer; pub struct CustomerKeySeed { - postnumber: String, - seed: Seed, - uuid: Uuid, + pub postnumber: String, + pub seed: Seed, + pub uuid: Uuid, + pub device_id: Option, } pub struct Seed { @@ -44,17 +45,25 @@ impl CustomerKeySeed { postnumber, seed: Seed::random(), uuid: uuid::Uuid::new_v4(), + device_id: None, } } - pub fn from(postnumber: &String, seed: Vec, uuid: &Uuid) -> Self { + pub fn from(postnumber: &String, seed: Vec, uuid: &Uuid, device_id: String) -> Self { CustomerKeySeed { postnumber: postnumber.clone(), seed: Seed::from_bytes(seed), - uuid: uuid.clone() + uuid: uuid.clone(), + device_id: Some(device_id), } } + pub fn set_device_id(&mut self, device_id: String) { + assert!(self.device_id.is_none()); + + self.device_id = Some(device_id); + } + pub(crate) fn sign(&self, message: &[u8]) -> String { let signing_key = SigningKey::from_bytes(self.seed.as_bytes());