mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
use r2d2 pool, update rusqlite version
This commit is contained in:
parent
c3f63dfbdc
commit
33369e31ea
17 changed files with 171 additions and 197 deletions
|
|
@ -46,7 +46,7 @@ impl Save {
|
|||
button.set_sensitive(false);
|
||||
|
||||
// Create PEM file based on option ID selected
|
||||
match Certificate::new(profile.clone(), profile_identity_id) {
|
||||
match Certificate::build(profile.clone(), profile_identity_id) {
|
||||
Ok(certificate) => {
|
||||
// Init file filters related with PEM extension
|
||||
let filters = ListStore::new::<FileFilter>();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
mod error;
|
||||
pub use error::Error;
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use crate::profile::Profile;
|
||||
use gtk::{gio::TlsCertificate, prelude::TlsCertificateExt};
|
||||
|
|
@ -15,19 +14,17 @@ impl Certificate {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn new(profile: Rc<Profile>, profile_identity_id: i64) -> Result<Self, Error> {
|
||||
match profile.identity.database.record(profile_identity_id) {
|
||||
Ok(record) => match record {
|
||||
Some(identity) => match TlsCertificate::from_pem(&identity.pem) {
|
||||
Ok(certificate) => Ok(Self {
|
||||
data: identity.pem,
|
||||
name: certificate.subject_name().unwrap().replace("CN=", ""),
|
||||
}),
|
||||
Err(e) => Err(Error::TlsCertificate(e)),
|
||||
},
|
||||
None => Err(Error::NotFound(profile_identity_id)),
|
||||
},
|
||||
Err(e) => Err(Error::Database(e)),
|
||||
pub fn build(profile: Rc<Profile>, profile_identity_id: i64) -> Result<Self> {
|
||||
let record = profile.identity.database.record(profile_identity_id)?;
|
||||
match record {
|
||||
Some(identity) => Ok(Self {
|
||||
name: TlsCertificate::from_pem(&identity.pem)?
|
||||
.subject_name()
|
||||
.unwrap_or_default()
|
||||
.replace("CN=", ""),
|
||||
data: identity.pem,
|
||||
}),
|
||||
None => bail!("Identity not found!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
use gtk::glib;
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Database(sqlite::Error),
|
||||
NotFound(i64),
|
||||
TlsCertificate(glib::Error),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Database(e) => {
|
||||
write!(f, "Database error: {e}")
|
||||
}
|
||||
Self::NotFound(profile_identity_id) => {
|
||||
write!(f, "Record for `{profile_identity_id}` not found")
|
||||
}
|
||||
Self::TlsCertificate(e) => {
|
||||
write!(f, "TLS certificate error: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue