1use std::time::Duration;
4
5use umask::Mode;
6
7use tc_value::{Address, Host, Link, Protocol, Value};
8
9pub use rjwt::VerifyingKey;
10
11pub use tc_state::view::StateView;
12pub use tc_state::CacheBlock;
13
14pub use builder::{Broadcast, Builder, Replicator};
15pub use claim::Claim;
16pub use client::RPCClient;
17pub use kernel::Endpoint;
18pub use server::Server;
19pub use txn::{IntoView, Transaction, Txn, TxnId};
20
21mod builder;
22mod claim;
23mod client;
24mod cluster;
25mod kernel;
26mod server;
27mod txn;
28
29pub mod aes256 {
30 pub use aes_gcm_siv::aead::OsRng;
31 pub use aes_gcm_siv::{Aes256GcmSiv, KeyInit};
32
33 pub type Key = aes_gcm_siv::Key<Aes256GcmSiv>;
34}
35
36#[cfg(debug_assertions)]
37pub const DEFAULT_MAX_RETRIES: u8 = 1;
38#[cfg(not(debug_assertions))]
39pub const DEFAULT_MAX_RETRIES: u8 = 3;
40pub const DEFAULT_PORT: u16 = 8702;
41pub const DEFAULT_TTL: Duration = Duration::from_secs(3);
42pub const SERVICE_TYPE: &'static str = "_tinychain._tcp.local.";
43
44pub type Actor = rjwt::Actor<Value>;
45pub type SignedToken = rjwt::SignedToken<Link, Value, Claim>;
46pub type Token = rjwt::Token<Link, Value, Claim>;
47
48#[cfg(feature = "service")]
49pub type Chain<T> = tc_state::chain::Chain<Txn, T>;
50#[cfg(feature = "service")]
51pub type Collection = tc_state::collection::CollectionBase<Txn>;
52pub type State = tc_state::State<Txn>;
53
54pub trait Authorize {
55 fn has_any<const N: usize>(&self, modes: [Mode; N]) -> bool;
56
57 fn is_none(self) -> bool;
58
59 fn may_read(self) -> bool;
60
61 fn may_write(self) -> bool;
62
63 fn may_execute(self) -> bool;
64}
65
66impl Authorize for Mode {
67 fn has_any<const N: usize>(&self, modes: [Mode; N]) -> bool {
68 modes.into_iter().any(|mode| self.has(mode))
69 }
70
71 #[inline]
72 fn is_none(self) -> bool {
73 self == Mode::new()
74 }
75
76 #[inline]
77 fn may_read(self) -> bool {
78 const ALLOW: [Mode; 3] = [umask::USER_READ, umask::GROUP_READ, umask::OTHERS_READ];
79 self.has_any(ALLOW)
80 }
81
82 #[inline]
83 fn may_write(self) -> bool {
84 const ALLOW: [Mode; 3] = [umask::USER_WRITE, umask::GROUP_WRITE, umask::OTHERS_WRITE];
85 self.has_any(ALLOW)
86 }
87
88 #[inline]
89 fn may_execute(self) -> bool {
90 const ALLOW: [Mode; 3] = [umask::USER_EXEC, umask::GROUP_EXEC, umask::OTHERS_EXEC];
91 self.has_any(ALLOW)
92 }
93}
94
95pub fn default_host() -> Host {
96 Host::from((Protocol::HTTP, Address::LOCALHOST, DEFAULT_PORT))
97}