use serde::{Deserialize, Serialize};
pub use crate::proof::*;
use crate::{CreateKeyChange, EventIdentifier, ProfileEventAttributes, RotateKeyChange};
#[non_exhaustive]
pub struct ProfileEventAttributeKey;
impl ProfileEventAttributeKey {
pub const FRIENDLY_NAME: &'static str = "OCKAM_FN";
pub const CREATION_DATE: &'static str = "OCKAM_CD";
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ProfileChange {
version: u8,
attributes: ProfileEventAttributes,
change_type: ProfileChangeType,
}
impl ProfileChange {
pub fn version(&self) -> u8 {
self.version
}
pub fn attributes(&self) -> &ProfileEventAttributes {
&self.attributes
}
pub fn change_type(&self) -> &ProfileChangeType {
&self.change_type
}
}
impl ProfileChange {
pub(crate) fn new(
version: u8,
attributes: ProfileEventAttributes,
change_type: ProfileChangeType,
) -> Self {
Self {
version,
attributes,
change_type,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ProfileChangeType {
CreateKey(CreateKeyChange),
RotateKey(RotateKeyChange),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChangeSet {
prev_event_id: EventIdentifier,
data: Vec<ProfileChange>,
}
impl ChangeSet {
pub fn previous_event_identifier(&self) -> &EventIdentifier {
&self.prev_event_id
}
pub fn data(&self) -> &[ProfileChange] {
&self.data
}
}
impl ChangeSet {
pub fn new(prev_event_id: EventIdentifier, data: Vec<ProfileChange>) -> Self {
ChangeSet {
prev_event_id,
data,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ProfileChangeEvent {
identifier: EventIdentifier,
changes: ChangeSet,
proof: ProfileChangeProof,
}
pub type Changes = Vec<ProfileChangeEvent>;
impl ProfileChangeEvent {
pub fn identifier(&self) -> &EventIdentifier {
&self.identifier
}
pub fn changes(&self) -> &ChangeSet {
&self.changes
}
pub fn proof(&self) -> &ProfileChangeProof {
&self.proof
}
}
impl ProfileChangeEvent {
pub fn new(identifier: EventIdentifier, changes: ChangeSet, proof: ProfileChangeProof) -> Self {
ProfileChangeEvent {
identifier,
changes,
proof,
}
}
}