#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HashAlgorithm {
Sha1,
Sha256,
Sha512,
}
impl HashAlgorithm {
#[must_use]
pub const fn algorithm_uri(&self) -> &'static str {
match self {
Self::Sha1 => "http://www.w3.org/2000/09/xmldsig#sha1",
Self::Sha256 => "http://www.w3.org/2001/04/xmlenc#sha256",
Self::Sha512 => "http://www.w3.org/2001/04/xmlenc#sha512",
}
}
#[must_use]
pub const fn name(&self) -> &'static str {
match self {
Self::Sha1 => "SHA1",
Self::Sha256 => "SHA256",
Self::Sha512 => "SHA512",
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SignatureCommitment {
Created,
Approved,
Reviewed,
}
impl SignatureCommitment {
#[must_use]
pub const fn commitment_uri(&self) -> &'static str {
match self {
Self::Created => {
"http://schemas.openxmlformats.org/package/2006/RelationshipTransform/opc-SignatureOrigin/created"
}
Self::Approved => {
"http://schemas.openxmlformats.org/package/2006/RelationshipTransform/opc-SignatureOrigin/approved"
}
Self::Reviewed => {
"http://schemas.openxmlformats.org/package/2006/RelationshipTransform/opc-SignatureOrigin/reviewed"
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SignerInfo {
pub name: String,
pub email: Option<String>,
pub title: Option<String>,
}
impl SignerInfo {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
email: None,
title: None,
}
}
#[must_use]
pub fn with_email(mut self, email: impl Into<String>) -> Self {
self.email = Some(email.into());
self
}
#[must_use]
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DigitalSignature {
pub signer: SignerInfo,
pub hash_algorithm: HashAlgorithm,
pub sign_time: Option<String>,
pub commitment: SignatureCommitment,
}
impl DigitalSignature {
#[must_use]
pub const fn new(signer: SignerInfo, algorithm: HashAlgorithm) -> Self {
Self {
signer,
hash_algorithm: algorithm,
sign_time: None,
commitment: SignatureCommitment::Created,
}
}
#[must_use]
pub const fn with_commitment(mut self, commitment: SignatureCommitment) -> Self {
self.commitment = commitment;
self
}
#[must_use]
pub fn with_sign_time(mut self, time: impl Into<String>) -> Self {
self.sign_time = Some(time.into());
self
}
}