new-idea
Avril 4 years ago
parent 7b71b4fdcb
commit 3a2e30486a
Signed by: flanchan
GPG Key ID: 284488987C31F630

45
Cargo.lock generated

@ -211,7 +211,7 @@ dependencies = [
"crc",
"futures",
"getrandom 0.1.16",
"hex-literal",
"hex-literal 0.3.1",
"hmac",
"libc",
"openssl",
@ -545,12 +545,31 @@ dependencies = [
"libc",
]
[[package]]
name = "hex-literal"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "961de220ec9a91af2e1e5bd80d02109155695e516771762381ef8581317066e0"
dependencies = [
"hex-literal-impl",
"proc-macro-hack",
]
[[package]]
name = "hex-literal"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5af1f635ef1bc545d78392b136bfe1c9809e029023c84a3638a864a10b8819c8"
[[package]]
name = "hex-literal-impl"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "853f769599eb31de176303197b7ba4973299c38c7a7604a6bc88c3eef05b9b46"
dependencies = [
"proc-macro-hack",
]
[[package]]
name = "hmac"
version = "0.9.0"
@ -688,6 +707,20 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "khash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "592c0325561e878d43491e8ef0fed4ecb2b84ddbb1d668405914c50400ba1b9e"
dependencies = [
"crc",
"getrandom 0.1.16",
"hex-literal 0.2.1",
"libc",
"malloc-array",
"sha2",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -709,6 +742,15 @@ dependencies = [
"cfg-if 0.1.10",
]
[[package]]
name = "malloc-array"
version = "1.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f994770c7bb3f8f7db7c4160665fc8814c8c705c10ae59a3d7354f0b8838f5c"
dependencies = [
"libc",
]
[[package]]
name = "matches"
version = "0.1.8"
@ -1828,6 +1870,7 @@ dependencies = [
"futures",
"generational-arena",
"getrandom 0.2.1",
"khash",
"lazy_static",
"log",
"mopa",

@ -18,6 +18,7 @@ difference = "2.0.0"
futures = "0.3.8"
generational-arena = "0.2.8"
getrandom = "0.2.1"
khash = "2.0.0"
lazy_static = "1.4.0"
log = "0.4.11"
mopa = "0.2.2"

@ -27,6 +27,7 @@ use color_eyre::{
mod bytes;
mod delta; //unused now, but tests still use it, so...
mod hard_format;
mod tripcode;
mod post;
mod state;

@ -1,6 +1,9 @@
use super::*;
use cryptohelpers::sha256::Sha256Hash;
use hard_format::formats::PEMFormattedString;
use tripcode::Tripcode;
id_type!(PostID; "A unique post ID");
/// A single completed post
@ -8,10 +11,14 @@ id_type!(PostID; "A unique post ID");
pub struct Post
{
id: PostID,
name: Option<String>,
tripcode: Option<Tripcode>,
email: Option<String>,
body: hard_format::formats::PEMFormattedString,
signature: Option<hard_format::formats::PEMFormattedString>,
body: PEMFormattedString,
signature: Option<PEMFormattedString>,
/// Hash of the body
hash: Sha256Hash,
}

@ -0,0 +1,64 @@
use super::*;
use khash::ctx::{self, Context};
use khash::salt::Salt;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Tripcode(String);
lazy_static!{
static ref CONTEXT: Context = Context::new(ctx::Algorithm::Sha256Truncated, Salt::internal());
}
impl Tripcode
{
/// Generate a tripcode from this string.
pub fn generate(from: impl AsRef<[u8]>) -> Result<Self, khash::error::Error>
{
khash::generate(&CONTEXT, from).map(Self)
}
/// Create a tripcode that *is* this string
#[inline] pub fn from_string(string: String) -> Self
{
Self(string)
}
/// As a string
#[inline] pub fn as_str(&self) -> &str
{
&self.0
}
}
impl From<Tripcode> for String
{
#[inline] fn from(from: Tripcode) -> Self
{
from.0
}
}
impl fmt::Display for Tripcode
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "{}", self.0)
}
}
impl AsRef<str> for Tripcode
{
fn as_ref(&self) -> &str
{
&self.0[..]
}
}
impl std::borrow::Borrow<String> for Tripcode
{
fn borrow(&self) -> &String
{
&self.0
}
}
Loading…
Cancel
Save