impl some sqlite types for SSK type

This commit is contained in:
Horhik 2021-03-13 11:23:40 +03:00
parent ffbc1abc92
commit d7031544fe
2 changed files with 22 additions and 0 deletions

View file

@ -12,3 +12,4 @@ description = "Implementation of FCPv2 freenet protocol"
[dependencies]
regex = "1.4.3"
rusqlite = "0.24.2"

View file

@ -2,18 +2,39 @@ pub mod traits;
use regex::Regex;
use traits::*;
use rusqlite::types::ToSqlOutput;
use rusqlite::{Result, ToSql, types::{FromSql, ValueRef, FromSqlResult, FromSqlError}};
#[derive(Debug, PartialEq)]
pub struct SSK {
pub sign_key: String,
pub decrypt_key: String,
pub settings: Option<String>,
}
impl ToSql for SSK {
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
Ok(ToSqlOutput::from(self.convert()))
}
}
impl FromSql for SSK{
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>{
match SSK::parse(value.as_str()?) {
Some(res) => Ok(res),
None => Err(FromSqlError::InvalidType)
}
}
}
#[derive(Debug, PartialEq)]
pub struct USK {
pub ssk: SSK,
pub index: i32,
}
#[derive(Debug, PartialEq)]
pub struct SSKKeypair {
pub insert_uri: SSK,