lib3mf_core/model/
crypto.rs

1use serde::{Deserialize, Serialize};
2
3/// Represents an XML-DSIG Signature element.
4/// Namespace: <http://www.w3.org/2000/09/xmldsig#>
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6pub struct Signature {
7    pub signed_info: SignedInfo,
8    pub signature_value: SignatureValue,
9    pub key_info: Option<KeyInfo>,
10    // Object element is not typically used for simple 3MF signatures but spec allows it?
11    // We'll stick to core elements first.
12}
13
14#[derive(Debug, Clone, Default, Serialize, Deserialize)]
15pub struct SignedInfo {
16    pub canonicalization_method: CanonicalizationMethod,
17    pub signature_method: SignatureMethod,
18    pub references: Vec<Reference>,
19}
20
21#[derive(Debug, Clone, Default, Serialize, Deserialize)]
22pub struct CanonicalizationMethod {
23    pub algorithm: String,
24}
25
26#[derive(Debug, Clone, Default, Serialize, Deserialize)]
27pub struct SignatureMethod {
28    pub algorithm: String,
29}
30
31#[derive(Debug, Clone, Default, Serialize, Deserialize)]
32pub struct Reference {
33    pub uri: String,
34    pub digest_method: DigestMethod,
35    pub digest_value: DigestValue,
36    // Transforms are optional in 3MF restricted profile (usually C14N is implicit or specified)
37    pub transforms: Option<Vec<Transform>>,
38}
39
40#[derive(Debug, Clone, Default, Serialize, Deserialize)]
41pub struct Transform {
42    pub algorithm: String,
43}
44
45#[derive(Debug, Clone, Default, Serialize, Deserialize)]
46pub struct DigestMethod {
47    pub algorithm: String,
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize)]
51pub struct DigestValue {
52    // Base64 encoded value usually. We store as simple String or bytes?
53    // String for XML mapping, bytes for logic?
54    // Let's store raw string here to match XML, decode later.
55    pub value: String,
56}
57
58#[derive(Debug, Clone, Default, Serialize, Deserialize)]
59pub struct SignatureValue {
60    pub value: String,
61}
62
63#[derive(Debug, Clone, Default, Serialize, Deserialize)]
64pub struct KeyInfo {
65    // For 3MF, usually KeyName (UUID) or KeyValue (RSA Public Key)
66    pub key_name: Option<String>,
67    pub key_value: Option<KeyValue>,
68    pub x509_data: Option<X509Data>,
69}
70
71#[derive(Debug, Clone, Default, Serialize, Deserialize)]
72pub struct X509Data {
73    pub certificate: Option<String>, // Base64 encoded PEM/DER
74}
75
76#[derive(Debug, Clone, Default, Serialize, Deserialize)]
77pub struct KeyValue {
78    pub rsa_key_value: Option<RSAKeyValue>,
79}
80
81#[derive(Debug, Clone, Default, Serialize, Deserialize)]
82pub struct RSAKeyValue {
83    pub modulus: String,
84    pub exponent: String,
85}
86
87// Helper types for Keystore mapping
88#[derive(Debug, Clone)]
89pub struct CertificateInfo {
90    pub subject: String,
91    pub issuer: String,
92    pub serial_number: String,
93    // Real parsed data could be stored if we hold the X509Certificate object,
94    // but usually we just parse on demand from the PEM/DER bytes.
95}