simploxide_client/crypto/
mod.rs1pub mod fs;
2
3#[cfg(feature = "native_crypto")]
4pub mod native;
5
6pub type XSalsa20Key = [u8; 32];
7pub type XSalsa20Nonce = [u8; 24];
8pub type Poly1305Tag = [u8; 16];
9
10pub trait SimplexSecretBox {
11 fn init(key: &XSalsa20Key, nonce: &XSalsa20Nonce) -> Self;
19
20 fn encrypt_chunk(&mut self, chunk: impl AsRef<[u8]>, buf: impl AsMut<[u8]>);
23
24 fn decrypt_chunk(&mut self, chunk: impl AsRef<[u8]>, buf: impl AsMut<[u8]>);
27
28 fn auth_tag(&mut self) -> Poly1305Tag;
29
30 fn verify_tag(&mut self, tag_to_verify: &Poly1305Tag) -> bool;
31}
32
33#[derive(Debug, Clone, Copy)]
34pub struct InvalidAuthTag;
35
36impl InvalidAuthTag {
37 pub fn io_error() -> std::io::Error {
38 std::io::Error::new(std::io::ErrorKind::InvalidData, InvalidAuthTag)
39 }
40}
41
42impl From<InvalidAuthTag> for ::std::io::Error {
43 fn from(_: InvalidAuthTag) -> Self {
44 InvalidAuthTag::io_error()
45 }
46}
47
48impl std::fmt::Display for InvalidAuthTag {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 write!(f, "Invalid poly1305 auth tag")
51 }
52}
53
54impl std::error::Error for InvalidAuthTag {}
55
56#[derive(Debug, Clone, Copy)]
57pub struct InvalidCryptoArgs;
58
59impl InvalidCryptoArgs {
60 pub fn io_error() -> std::io::Error {
61 std::io::Error::new(std::io::ErrorKind::InvalidData, InvalidCryptoArgs)
62 }
63}
64
65impl From<InvalidCryptoArgs> for ::std::io::Error {
66 fn from(_: InvalidCryptoArgs) -> Self {
67 InvalidCryptoArgs::io_error()
68 }
69}
70
71impl std::fmt::Display for InvalidCryptoArgs {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 write!(f, "Invalid file crypto args")
74 }
75}
76
77impl std::error::Error for InvalidCryptoArgs {}