This commit is contained in:
adria0 2020-04-26 01:15:11 +02:00
parent be722d5474
commit 7cd204cad2
4 changed files with 12 additions and 3 deletions

View File

@ -92,11 +92,11 @@ pub enum Mentions {
#[derive(Debug, Deserialize)]
#[serde(tag = "type")]
pub enum FeedTypedContent {
pub enum TypedMessage {
#[serde(rename = "pub")]
Pub { address: Option<PubAddress> },
#[serde(rename = "post")]
Post,
Post { post: Post },
#[serde(rename = "contact")]
Contact {
contact: Option<SsbId>,

View File

@ -5,3 +5,5 @@ pub use error::{Error, Result};
pub use sodium::{
ToSodiumObject, ToSsbId, CURVE_ED25519_SUFFIX, ED25519_SIGNATURE_SUFFIX, SHA256_SUFFIX,
};
pub use sodiumoxide::crypto::hash::sha256 as sha256;
pub use sodiumoxide::crypto::sign::ed25519 as ed25519;

View File

@ -10,6 +10,7 @@ pub const SHA256_SUFFIX: &str = ".sha256";
pub trait ToSodiumObject {
fn to_ed25519_pk(&self) -> Result<ed25519::PublicKey>;
fn to_ed25519_pk_no_suffix(&self) -> Result<ed25519::PublicKey>;
fn to_ed25519_sk(&self) -> Result<ed25519::SecretKey>;
fn to_ed25519_sk_no_suffix(&self) -> Result<ed25519::SecretKey>;
fn to_ed25519_signature(&self) -> Result<ed25519::Signature>;
@ -43,6 +44,12 @@ impl ToSodiumObject for str {
ed25519::PublicKey::from_slice(&bytes).ok_or_else(|| Error::BadPublicKey)
}
fn to_ed25519_pk_no_suffix(self: &str) -> Result<ed25519::PublicKey> {
let bytes = base64::decode(&self)?;
ed25519::PublicKey::from_slice(&bytes).ok_or_else(|| Error::BadPublicKey)
}
fn to_ed25519_sk(self: &str) -> Result<ed25519::SecretKey> {
if !self.ends_with(CURVE_ED25519_SUFFIX) {

View File

@ -78,7 +78,7 @@ impl Header {
1 => BodyType::UTF8,
2 => BodyType::JSON,
_ => {
warn!("rare message: {}", String::from_utf8_lossy(bytes));
warn!(target: "ssb", "rare message: {}", String::from_utf8_lossy(bytes));
return Err(Error::InvalidBodyType(body_type_value));
}
};