impl some sqlite types for SSK type
This commit is contained in:
parent
ffbc1abc92
commit
d7031544fe
|
@ -12,3 +12,4 @@ description = "Implementation of FCPv2 freenet protocol"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1.4.3"
|
regex = "1.4.3"
|
||||||
|
rusqlite = "0.24.2"
|
||||||
|
|
|
@ -2,18 +2,39 @@ pub mod traits;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use traits::*;
|
use traits::*;
|
||||||
|
|
||||||
|
use rusqlite::types::ToSqlOutput;
|
||||||
|
use rusqlite::{Result, ToSql, types::{FromSql, ValueRef, FromSqlResult, FromSqlError}};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct SSK {
|
pub struct SSK {
|
||||||
pub sign_key: String,
|
pub sign_key: String,
|
||||||
pub decrypt_key: String,
|
pub decrypt_key: String,
|
||||||
pub settings: Option<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)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct USK {
|
pub struct USK {
|
||||||
pub ssk: SSK,
|
pub ssk: SSK,
|
||||||
pub index: i32,
|
pub index: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct SSKKeypair {
|
pub struct SSKKeypair {
|
||||||
pub insert_uri: SSK,
|
pub insert_uri: SSK,
|
||||||
|
|
Loading…
Reference in a new issue