fix formatting

This commit is contained in:
mycognosist 2021-12-15 15:36:40 +02:00 committed by adria0.eth
parent 15f4a4c5a3
commit 0ed6e35303
1 changed files with 5 additions and 7 deletions

View File

@ -11,9 +11,7 @@ use std::string::ToString;
use super::{ use super::{
error::{Error, Result}, error::{Error, Result},
CURVE_ED25519, JsonSSBSecret, OwnedIdentity, CURVE_ED25519,
OwnedIdentity,
JsonSSBSecret,
}; };
use crate::crypto::{ToSodiumObject, ToSsbId}; use crate::crypto::{ToSodiumObject, ToSsbId};
@ -29,7 +27,7 @@ pub async fn from_gosbot_local() -> Result<OwnedIdentity> {
read_gosbot_config(&mut file).await read_gosbot_config(&mut file).await
} }
/// Read the contents of the go-sbot secret file, deserialize into a /// Read the contents of the go-sbot secret file, deserialize into a
/// `JsonSSBSecret` and return an `OwnedIdentity`. /// `JsonSSBSecret` and return an `OwnedIdentity`.
pub async fn read_gosbot_config<R: Read + Unpin>(reader: &mut R) -> Result<OwnedIdentity> { pub async fn read_gosbot_config<R: Read + Unpin>(reader: &mut R) -> Result<OwnedIdentity> {
let mut buf = String::new(); let mut buf = String::new();
@ -66,8 +64,8 @@ pub async fn write_gosbot_config<W: Write + Unpin>(
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use async_std::io::Cursor;
use super::*; use super::*;
use async_std::io::Cursor;
// ssb secret file contents, as formatted by go-sbot // ssb secret file contents, as formatted by go-sbot
const SECRET: &str = r#"{"curve":"ed25519","id":"@1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519","private":"F9bw6dPLaHR89hg6Q2dRmoNHHjm+COI53L0kdV3Y4w3W/FLoMyLvP24khAbfdbuaWy/bUZkhs6mZYTVARyf2hg==.ed25519","public":"1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519"}"#; const SECRET: &str = r#"{"curve":"ed25519","id":"@1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519","private":"F9bw6dPLaHR89hg6Q2dRmoNHHjm+COI53L0kdV3Y4w3W/FLoMyLvP24khAbfdbuaWy/bUZkhs6mZYTVARyf2hg==.ed25519","public":"1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519"}"#;
@ -76,13 +74,13 @@ mod test {
async fn test_gosbot_secret() -> Result<()> { async fn test_gosbot_secret() -> Result<()> {
let mut secret_bytes = SECRET.as_bytes(); let mut secret_bytes = SECRET.as_bytes();
let read_secret_output = read_gosbot_config(&mut secret_bytes).await?; let read_secret_output = read_gosbot_config(&mut secret_bytes).await?;
let expected = OwnedIdentity { let expected = OwnedIdentity {
id: "@1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519".to_owned(), id: "@1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519".to_owned(),
sk: "F9bw6dPLaHR89hg6Q2dRmoNHHjm+COI53L0kdV3Y4w3W/FLoMyLvP24khAbfdbuaWy/bUZkhs6mZYTVARyf2hg==.ed25519".to_ed25519_sk()?, sk: "F9bw6dPLaHR89hg6Q2dRmoNHHjm+COI53L0kdV3Y4w3W/FLoMyLvP24khAbfdbuaWy/bUZkhs6mZYTVARyf2hg==.ed25519".to_ed25519_sk()?,
pk: "1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519".to_ed25519_pk()? pk: "1vxS6DMi7z9uJIQG33W7mlsv21GZIbOpmWE1QEcn9oY=.ed25519".to_ed25519_pk()?
}; };
assert_eq!(expected, read_secret_output); assert_eq!(expected, read_secret_output);
// create a Cursor which wraps an in-memory buffer (implements `Write`) // create a Cursor which wraps an in-memory buffer (implements `Write`)
let mut secret_buffer = Cursor::new(Vec::new()); let mut secret_buffer = Cursor::new(Vec::new());
// write the `OwnedIdentity` from `read_gosbot_config()` to the buffer // write the `OwnedIdentity` from `read_gosbot_config()` to the buffer