Skip to main content

confium_jce_provider/
lib.rs

1//! Java Cryptography Extension (JCE) provider for Confium.
2//!
3//! Allows Java applications using JCA (Java Cryptography Architecture)
4//! and JKS (Java KeyStore) to use Confium-backed threshold signing
5//! keys transparently.
6//!
7//! Real Java integration requires JNI bindings; this crate provides
8//! the Rust-side logic that the JNI layer calls into.
9//!
10//! See `TODO.roadmap/28-mode2-pki-replacement.md` for full spec.
11
12#![forbid(unsafe_code)]
13#![allow(missing_docs)] // TODO: document before 1.0
14
15use serde::{Deserialize, Serialize};
16
17/// JCE provider info (mirrors `java.security.Provider`).
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct JceProviderInfo {
20    /// Provider name (e.g., "Confium").
21    pub name: String,
22    /// Version string.
23    pub version: String,
24    /// Provider info string.
25    pub info: String,
26}
27
28impl JceProviderInfo {
29    /// Default Confium JCE provider info.
30    pub fn default_confium() -> Self {
31        Self {
32            name: "Confium".into(),
33            version: env!("CARGO_PKG_VERSION").into(),
34            info: "Confium threshold cryptography provider for Java".into(),
35        }
36    }
37}
38
39/// Java algorithm names this provider handles.
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub enum JavaAlgorithm {
43    /// Ed25519 signature.
44    Ed25519,
45    /// ECDSA P-256 signature.
46    EcdsaP256,
47    /// ML-DSA-65 (post-quantum).
48    MlDsa65,
49}
50
51impl JavaAlgorithm {
52    /// Java standard algorithm name.
53    pub fn java_name(&self) -> &'static str {
54        match self {
55            JavaAlgorithm::Ed25519 => "Ed25519",
56            JavaAlgorithm::EcdsaP256 => "SHA256withECDSA",
57            JavaAlgorithm::MlDsa65 => "ML-DSA-65",
58        }
59    }
60}
61
62/// Errors during JCE operations.
63#[derive(Debug, thiserror::Error)]
64pub enum JceError {
65    /// Algorithm not supported.
66    #[error("algorithm not supported: {0}")]
67    UnsupportedAlgorithm(String),
68    /// Threshold signing failed.
69    #[error("threshold signing failed: {0}")]
70    SignFailed(String),
71    /// Key not found in store.
72    #[error("key not found: {0}")]
73    KeyNotFound(String),
74}
75
76#[cfg(test)]
77mod tests {
78    use super::*;
79
80    #[test]
81    fn default_provider_info() {
82        let info = JceProviderInfo::default_confium();
83        assert_eq!(info.name, "Confium");
84    }
85
86    #[test]
87    fn java_algorithm_names() {
88        assert_eq!(JavaAlgorithm::Ed25519.java_name(), "Ed25519");
89        assert_eq!(JavaAlgorithm::EcdsaP256.java_name(), "SHA256withECDSA");
90    }
91}