logline_core/signature.rs
1#[cfg(not(feature = "std"))]
2use alloc::{string::String, vec::Vec};
3#[cfg(feature = "std")]
4use std::{string::String, vec::Vec};
5
6/// Trait para tipos que podem ser assinados.
7///
8/// Define como um tipo gera bytes determinísticos para assinatura.
9/// `LogLine` implementa este trait.
10pub trait Signable {
11 /// Gera bytes determinísticos que serão assinados.
12 fn to_signable_bytes(&self) -> Vec<u8>;
13}
14
15/// Assinatura digital de uma mensagem.
16///
17/// Contém o algoritmo usado e os bytes da assinatura.
18/// Em versões futuras, será integrado com `ed25519-dalek` para assinaturas reais.
19///
20/// # Exemplo
21///
22/// ```rust
23/// use logline_core::Signature;
24///
25/// let sig = Signature {
26/// alg: "ed25519".into(),
27/// bytes: vec![0u8; 64],
28/// };
29/// ```
30#[derive(Clone, Debug, PartialEq)]
31pub struct Signature {
32 /// Algoritmo de assinatura (ex: "ed25519", "none").
33 pub alg: String,
34 /// Bytes da assinatura.
35 pub bytes: Vec<u8>,
36}
37
38/// Placeholder error type for signing operations (v0.1.0).
39/// Future versions will use proper error types (e.g., ed25519-dalek errors).
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub struct SignError;
42
43/// Trait para tipos que podem assinar mensagens.
44///
45/// Implementações devem assinar os bytes fornecidos e retornar uma `Signature`.
46/// Em produção, use implementações reais como `ed25519-dalek::SigningKey`.
47///
48/// # Exemplo
49///
50/// ```rust
51/// use logline_core::{Signer, Signature, SignError};
52///
53/// struct NoopSigner;
54/// impl Signer for NoopSigner {
55/// fn sign(&self, msg: &[u8]) -> Result<Signature, SignError> {
56/// Ok(Signature { alg: "none".into(), bytes: msg.to_vec() })
57/// }
58/// }
59/// ```
60pub trait Signer {
61 /// Assina a mensagem fornecida e retorna uma `Signature`.
62 ///
63 /// # Erros
64 ///
65 /// Retorna `SignError` se a assinatura falhar.
66 fn sign(&self, msg: &[u8]) -> Result<Signature, SignError>;
67}