deduplicate to_io_error fn
This commit is contained in:
parent
0ed6e35303
commit
3f55f9a568
|
@ -7,18 +7,12 @@ use async_std::{
|
|||
prelude::*,
|
||||
};
|
||||
|
||||
use std::string::ToString;
|
||||
|
||||
use super::{
|
||||
error::{Error, Result},
|
||||
JsonSSBSecret, OwnedIdentity, CURVE_ED25519,
|
||||
util, JsonSSBSecret, OwnedIdentity, CURVE_ED25519,
|
||||
};
|
||||
use crate::crypto::{ToSodiumObject, ToSsbId};
|
||||
|
||||
fn to_io_error<T: ToString>(err: T) -> async_std::io::Error {
|
||||
async_std::io::Error::new(std::io::ErrorKind::Other, err.to_string())
|
||||
}
|
||||
|
||||
/// Return an `OwnedIdentity` from the local go-sbot secret file.
|
||||
pub async fn from_gosbot_local() -> Result<OwnedIdentity> {
|
||||
let home_dir = dirs::home_dir().ok_or(Error::HomeNotFound)?;
|
||||
|
@ -34,7 +28,7 @@ pub async fn read_gosbot_config<R: Read + Unpin>(reader: &mut R) -> Result<Owned
|
|||
reader.read_to_string(&mut buf).await?;
|
||||
|
||||
// parse json
|
||||
let secret: JsonSSBSecret = serde_json::from_str(buf.as_ref()).map_err(to_io_error)?;
|
||||
let secret: JsonSSBSecret = serde_json::from_str(buf.as_ref()).map_err(util::to_io_error)?;
|
||||
|
||||
if secret.curve != CURVE_ED25519 {
|
||||
return Err(Error::InvalidConfig);
|
||||
|
|
|
@ -2,6 +2,7 @@ mod error;
|
|||
pub mod gosbot;
|
||||
mod identity;
|
||||
pub mod patchwork;
|
||||
mod util;
|
||||
|
||||
pub use gosbot::{from_gosbot_local, read_gosbot_config, write_gosbot_config};
|
||||
pub use identity::{JsonSSBSecret, OwnedIdentity, CURVE_ED25519};
|
||||
|
|
|
@ -3,19 +3,13 @@ use async_std::{
|
|||
prelude::*,
|
||||
};
|
||||
|
||||
use std::string::ToString;
|
||||
|
||||
use super::{
|
||||
error::{Error, Result},
|
||||
JsonSSBSecret, OwnedIdentity, CURVE_ED25519,
|
||||
util, JsonSSBSecret, OwnedIdentity, CURVE_ED25519,
|
||||
};
|
||||
use crate::crypto::{ToSodiumObject, ToSsbId};
|
||||
use serde_json::to_vec_pretty;
|
||||
|
||||
fn to_io_error<T: ToString>(err: T) -> async_std::io::Error {
|
||||
async_std::io::Error::new(std::io::ErrorKind::Other, err.to_string())
|
||||
}
|
||||
|
||||
pub async fn from_patchwork_local() -> Result<OwnedIdentity> {
|
||||
let home_dir = dirs::home_dir().ok_or(Error::HomeNotFound)?;
|
||||
let local_key_file = format!("{}/.ssb/secret", home_dir.to_string_lossy());
|
||||
|
@ -34,7 +28,7 @@ pub async fn read_patchwork_config<R: Read + Unpin>(reader: &mut R) -> Result<Ow
|
|||
.join("");
|
||||
|
||||
// parse json
|
||||
let secret: JsonSSBSecret = serde_json::from_str(json.as_ref()).map_err(to_io_error)?;
|
||||
let secret: JsonSSBSecret = serde_json::from_str(json.as_ref()).map_err(util::to_io_error)?;
|
||||
|
||||
if secret.curve != CURVE_ED25519 {
|
||||
return Err(Error::InvalidConfig);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
use std::string::ToString;
|
||||
|
||||
pub fn to_io_error<T: ToString>(err: T) -> async_std::io::Error {
|
||||
async_std::io::Error::new(std::io::ErrorKind::Other, err.to_string())
|
||||
}
|
Loading…
Reference in New Issue