pub fn builder(pubkey: &PublicKey, cert_type: CertType, signing_key: &PublicKey) -> Result<Certificate> {
        let kt_name = format!("{}-cert-v01@openssh.com", pubkey.key_type.name);
        let key_type = KeyType::from_name(kt_name.as_str()).unwrap();
        let rng = SystemRandom::new();

        let mut nonce = [0x0u8; 32];
        match SecureRandom::fill(&rng, &mut nonce) {
            Ok(()) => (),
            Err(_) => return Err(Error::UnexpectedEof),
        };

        let mut serial = [0x0u8; 8];
        match SecureRandom::fill(&rng, &mut serial) {
            Ok(()) => (),
            Err(_) => return Err(Error::UnexpectedEof),
        };
        let serial = u64::from_be_bytes(serial);

        Ok(Certificate {
            nonce: nonce.to_vec(),
            key: pubkey.clone(),
            key_type,
            serial,
            cert_type,
            key_id: String::new(),
            principals: vec![],
            valid_after: 0,
            valid_before: 0,
            critical_options: HashMap::new(),
            extensions: HashMap::new(),
            reserved: vec![0,0,0,0,0,0,0,0],
            signature_key: signing_key.clone(),
            signature: vec![],
            comment: None,
            serialized: vec![],
        })
    }
/// Create a new empty SSH certificate. Values must then be filled in using
/// the mutator methods below.
///
/// # Example
///
/// ```rust
/// # use sshcerts::{Certificate, PublicKey};
/// # use sshcerts::ssh::{CertType, CriticalOptions, Extensions};
/// # fn test_signer(buf: &[u8]) -> Option<Vec<u8>> { None }
/// # fn test_pubkey() -> Option<Vec<u8>> { None }
/// # fn example() {
///     let ssh_pubkey = PublicKey::from_string("ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOhHAGJtT9s6zPW4OdQMzGbXEyj0ntkESrE1IZBgaCUSh9fWK1gRz+UJOcCB1JTC/kF2EPlwkX6XEpQToZl51oo= obelisk@exclave.lan").unwrap();
///     let cert = Certificate::builder(&ssh_pubkey, CertType::User, &ssh_pubkey).unwrap()
///        .serial(0xFEFEFEFEFEFEFEFE)
///        .key_id("key_id")
///        .principal("obelisk")
///        .valid_after(0)
///        .valid_before(0xFFFFFFFFFFFFFFFF)
///        .set_critical_options(CriticalOptions::None)
///        .set_extensions(Extensions::Standard)
///        .sign(test_signer);
/// 
///        match cert {
///            Ok(cert) => println!("{}", cert),
///            Err(e) => println!("Encountered an error while creating certificate: {}", e),
///        }
/// # }
/// ```
Create a new empty SSH certificate. Values must then be filled in using
the mutator methods below.
Create a new empty SSH certificate . Values must then be filled in using the mutator methods below .
pub fn builder(pubkey: &PublicKey, cert_type: CertType, signing_key: &PublicKey) -> Result<Certificate> {
        let kt_name = format!("{}-cert-v01@openssh.com", pubkey.key_type.name);
        let key_type = KeyType::from_name(kt_name.as_str()).unwrap();
        let rng = SystemRandom::new();
        let mut nonce = [0x0u8; 32];
        match SecureRandom::fill(&rng, &mut nonce) {
            Ok(()) => (),
            Err(_) => return Err(Error::UnexpectedEof),
        };
        let mut serial = [0x0u8; 8];
        match SecureRandom::fill(&rng, &mut serial) {
            Ok(()) => (),
            Err(_) => return Err(Error::UnexpectedEof),
        };
        let serial = u64::from_be_bytes(serial);
        Ok(Certificate {
            nonce: nonce.to_vec(),
            key: pubkey.clone(),
            key_type,
            serial,
            cert_type,
            key_id: String::new(),
            principals: vec![],
            valid_after: 0,
            valid_before: 0,
            critical_options: HashMap::new(),
            extensions: HashMap::new(),
            reserved: vec![0,0,0,0,0,0,0,0],
            signature_key: signing_key.clone(),
            signature: vec![],
            comment: None,
            serialized: vec![],
        })
    }
pub fn builder ( pubkey : & PublicKey , cert_type : CertType , signing_key : & PublicKey ) -> Result < Certificate > { let kt_name = format ! ( " " pubkey key_type name ) ; let key_type = KeyType :: from_name ( kt_name . as_str ( ) ) . unwrap ( ) ; let rng = SystemRandom :: new ( ) ; let mut nonce = [ 0x0u8 ; 32 ] ; match SecureRandom :: fill ( & rng , & mut nonce ) { Ok ( ( ) ) => ( ) , Err ( _ ) => return Err ( Error :: UnexpectedEof ) , } ; let mut serial = [ 0x0u8 ; 8 ] ; match SecureRandom :: fill ( & rng , & mut serial ) { Ok ( ( ) ) => ( ) , Err ( _ ) => return Err ( Error :: UnexpectedEof ) , } ; let serial = u64 :: from_be_bytes ( serial ) ; Ok ( Certificate { nonce : nonce . to_vec ( ) , key : pubkey . clone ( ) , key_type , serial , cert_type , key_id : String :: new ( ) , principals : vec ! [ ] , valid_after : 0 , valid_before : 0 , critical_options : HashMap :: new ( ) , extensions : HashMap :: new ( ) , reserved : vec ! [ 0 0 0 0 0 0 0 0 ] , signature_key : signing_key . clone ( ) , signature : vec ! [ ] , comment : None , serialized : vec ! [ ] , } ) }
Create a new empty SSH certificate.
Create a new empty SSH certificate .
pubkey
&PublicKey
cert_type
CertType
signing_key
&PublicKey
example
None
use sshcerts::{certificate, publickey};
None
use sshcerts::ssh::{certtype, criticaloptions, extensions};
None
fn test_signer(buf: &[u8]) -> option<vec<u8>> { none }
None
fn test_pubkey() -> option<vec<u8>> { none }
None
fn example() {
let ssh_pubkey = PublicKey::from_string("ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOhHAGJtT9s6zPW4OdQMzGbXEyj0ntkESrE1IZBgaCUSh9fWK1gRz+UJOcCB1JTC/kF2EPlwkX6XEpQToZl51oo= obelisk@exclave.lan").unwrap();
let cert = Certificate::builder(&ssh_pubkey, CertType::User, &ssh_pubkey).unwrap()
.serial(0xFEFEFEFEFEFEFEFE)
.key_id("key_id")
.principal("obelisk")
.valid_after(0)
.valid_before(0xFFFFFFFFFFFFFFFF)
.set_critical_options(CriticalOptions::None)
.set_extensions(Extensions::Standard)
.sign(test_signer).

match cert {
Ok(cert) => println!("{}", cert),
Err(e) => println!("Encountered an error while creating certificate: {}", e),
}
let ssh_pubkey = PublicKey :: from_string ( " ecdsa - sha2 - nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOhHAGJtT9s6zPW4OdQMzGbXEyj0ntkESrE1IZBgaCUSh9fWK1gRz + UJOcCB1JTC / kF2EPlwkX6XEpQToZl51oo = obelisk@exclave . lan " ) . unwrap () ; let cert = Certificate :: builder ( &ssh_pubkey CertType :: User &ssh_pubkey ) . unwrap () . serial ( 0xFEFEFEFEFEFEFEFE ) . key_id ( " key_id " ) . principal ( " obelisk " ) . valid_after ( 0 ) . valid_before ( 0xFFFFFFFFFFFFFFFF ) . set_critical_options ( CriticalOptions :: None ) . set_extensions ( Extensions :: Standard ) . sign ( test_signer ) . match cert { Ok ( cert ) = > println! ( " {} " cert ) Err ( e ) = > println! ( " Encountered an error while creating certificate : {} " e ) }
}
None