feat: add device_id to CustomerKeySeed

This commit is contained in:
jane400 2024-08-18 18:09:27 +02:00 committed by jane400
parent cc52b99144
commit cda0f946da

View file

@ -6,9 +6,10 @@ use ed25519_dalek::Signer;
pub struct CustomerKeySeed { pub struct CustomerKeySeed {
postnumber: String, pub postnumber: String,
seed: Seed, pub seed: Seed,
uuid: Uuid, pub uuid: Uuid,
pub device_id: Option<String>,
} }
pub struct Seed { pub struct Seed {
@ -44,17 +45,25 @@ impl CustomerKeySeed {
postnumber, postnumber,
seed: Seed::random(), seed: Seed::random(),
uuid: uuid::Uuid::new_v4(), uuid: uuid::Uuid::new_v4(),
device_id: None,
} }
} }
pub fn from(postnumber: &String, seed: Vec<u8>, uuid: &Uuid) -> Self { pub fn from(postnumber: &String, seed: Vec<u8>, uuid: &Uuid, device_id: String) -> Self {
CustomerKeySeed { CustomerKeySeed {
postnumber: postnumber.clone(), postnumber: postnumber.clone(),
seed: Seed::from_bytes(seed), 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 { pub(crate) fn sign(&self, message: &[u8]) -> String {
let signing_key = SigningKey::from_bytes(self.seed.as_bytes()); let signing_key = SigningKey::from_bytes(self.seed.as_bytes());