use libslug::slugcrypt::internals::signature::ed25519::ED25519SecretKey;
use libslug::slugcrypt::internals::signature::sphincs_plus::SPHINCSSecretKey;
use serde::{Serialize,Deserialize};
use libslug::slugcrypt::internals::signature::{ed25519::ED25519PublicKey, sphincs_plus::SPHINCSPublicKey};
use libslug::slugcrypt::internals::digest::blake2::SlugBlake2bHasher;
use libslug::slugcrypt::internals::digest::digest::SlugDigest;
use std::collections::HashSet;
use chrono::prelude::*;
use zeroize::{Zeroize,ZeroizeOnDrop};
use crate::UserCertificate;
use crate::prelude::*;
pub enum AlterCertificateInfo {
_0x00CREATE_CERTIFICATE,
_0x01REVOKE_CERTIFICATE,
_0x02UPDATE_CERTIFICATE,
_0x03WEBOFTRUST,
_0x04SIGNCERTIFICATE,
_0xf7EMPTYINVALID,
_0xf8SIGNKEY,
_0xf9SIGNDATA,
_0xfaSIGNSOURCE,
_0xfbSIGNEPHERMALMESSAGE,
_0xfcSIGNCERTIFICATE,
_0xfdSIGNFILE,
_0xffSIGNEXTENDABLE(u16),
}
pub struct CertificateSigningRequest {
_type: CertificateType,
cert: UserCertificate,
challenge: Challenge,
}
pub struct Challenge {
challenge: String,
reasons: Vec<AlterCertificateInfo>,
}
pub struct CertificateSigningInitialResponse {
csr: CertificateSigningRequest,
challenge: String,
tx_id: String,
}
pub struct UserData {
email: String,
author: String,
other: Vec<(String,String)>
}
pub struct CSR_DOMAIN {
top_level: String,
name: String,
subdomains: Vec<String>,
namespace: String,
}
pub struct CertificateSigningRequestResponse {
id: u64,
_type: CertificateType,
cert_domain: CSR_DOMAIN,
}
pub enum CertificateType {
SelfSigned,
CertificateAuthority,
Intermediate,
WOT,
Security,
}
type PublicKeyID = String;
type ED25519PublicKeyCache = String; type SPHINCSPublicKeyCache = String;
type EphermalSignatureID = String;
pub struct RustySigsRegistry {
certificates: HashSet<PublicKeyID,UserCertificate>
}
pub struct RustySigsRegistryCache {
id: HashSet<u64, PublicKeyID>,
ed25519_pk: HashSet<ED25519PublicKeyCache, PublicKeyID>,
sphincs_pk: HashSet<SPHINCSPublicKeyCache, PublicKeyID>,
ephermal_sig: HashSet<EphermalSignatureID,PublicKeyID>,
}
#[derive(Serialize,Deserialize,Clone)]
pub struct RustySigsCertRequest {
version: u8,
common_name: String,
owners: Vec<String>,
timestamp: DateTime<Utc>,
keypair: UserCertificate,
}
pub struct RustySigsConnect;
#[derive(Serialize,Deserialize,Clone,Zeroize,ZeroizeOnDrop)]
pub struct ShulginSigning {
id_hash: String, fingerprint: String,
classical_pk: ED25519PublicKey, sphincs_pk: SPHINCSPublicKey, }
impl ShulginSigning {
pub fn new(classical_pk: ED25519PublicKey, sphincs_pk: SPHINCSPublicKey) -> Self {
let hashable_str = Self::format_for_hashing(&classical_pk, &sphincs_pk);
let mut hasher = SlugBlake2bHasher::new(48);
let blake2b_hash_48 = SlugDigest::from_bytes(&hasher.update(hashable_str.as_bytes())).expect("Failed To Get From Bytes").to_string().to_string();
let mut hasher_id = SlugBlake2bHasher::new(8);
let blake2b_id = SlugDigest::from_bytes(&hasher.update(&blake2b_hash_48)).unwrap().to_string().to_string();
return Self {
id_hash: blake2b_id,
fingerprint: blake2b_hash_48,
classical_pk: classical_pk,
sphincs_pk: sphincs_pk,
}
}
fn format_for_hashing(classical_pk: &ED25519PublicKey, sphincs_pk: &SPHINCSPublicKey) -> String {
let mut s = String::new();
s.push_str(classical_pk.to_hex_string().as_str());
s.push_str(":");
s.push_str(sphincs_pk.to_hex_string().unwrap().as_str());
return s
}
pub fn get_delimiter() -> String {
return String::from(":")
}
}