Skip to main content

objects/object/
state_signature.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Cryptographic signature metadata for states.
3
4use serde::{Deserialize, Serialize};
5
6/// Signature information for a state.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8pub struct StateSignature {
9    /// Signature algorithm identifier.
10    pub algorithm: String,
11    /// Public key in hex format.
12    pub public_key: String,
13    /// Signature in hex format.
14    pub signature: String,
15}
16
17impl StateSignature {
18    /// Get the algorithm name.
19    pub fn algorithm(&self) -> &str {
20        &self.algorithm
21    }
22}
23
24/// Signature verification result.
25#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26pub enum SignatureStatus {
27    /// The signature is valid.
28    Valid,
29    /// The signature is invalid.
30    Invalid,
31    /// The state has no signature.
32    Unsigned,
33}
34
35impl SignatureStatus {
36    /// Check if this represents a valid signature.
37    pub fn is_valid(self) -> bool {
38        self == SignatureStatus::Valid
39    }
40
41    /// Check if this represents an unsigned state.
42    pub fn is_unsigned(self) -> bool {
43        self == SignatureStatus::Unsigned
44    }
45}