create separate file for Freenet keys
This commit is contained in:
parent
20725bf5a2
commit
3119403fa3
|
@ -13,3 +13,4 @@ description = "Implementation of FCPv2 freenet protocol"
|
|||
[dependencies]
|
||||
regex = "1.4.3"
|
||||
rusqlite = "0.24.2"
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
|
|
33
src/types/key.rs
Normal file
33
src/types/key.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use super::traits::{FcpParser, FcpRequest};
|
||||
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,
|
||||
}
|
||||
|
||||
|
|
@ -1,39 +1,8 @@
|
|||
pub mod traits;
|
||||
mod key;
|
||||
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,
|
||||
}
|
||||
|
||||
|
||||
pub use key::*;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct SSKKeypair {
|
||||
|
|
Loading…
Reference in a new issue