zkgroup/crypto/
timestamp_struct.rs

1//
2// Copyright 2022 Signal Messenger, LLC.
3// SPDX-License-Identifier: AGPL-3.0-only
4//
5
6use curve25519_dalek_signal::scalar::Scalar;
7use serde::{Deserialize, Serialize};
8
9use crate::common::sho::Sho;
10use crate::common::simple_types::Timestamp;
11
12#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct TimestampStruct {
14    pub(crate) timestamp: Timestamp,
15}
16
17impl TimestampStruct {
18    pub fn new(timestamp: Timestamp) -> Self {
19        Self { timestamp }
20    }
21
22    pub fn calc_m(&self) -> Scalar {
23        Self::calc_m_from(self.timestamp)
24    }
25
26    pub fn calc_m_from(timestamp: Timestamp) -> Scalar {
27        let mut sho = Sho::new(
28            b"Signal_ZKGroup_20220524_Timestamp_Calc_m",
29            &timestamp.to_be_bytes(),
30        );
31        sho.get_scalar()
32    }
33}