|
@@ -1,13 +1,70 @@
|
|
|
-// SHA512 requires 64 bytes.
|
|
|
-const signature_len: usize = 64;
|
|
|
-
|
|
|
-struct Block<'a> {
|
|
|
- version: u8,
|
|
|
- path: &'a str,
|
|
|
- read_caps: (),
|
|
|
- write_cap: (),
|
|
|
- body: &'a [u8],
|
|
|
- signature: [u8; signature_len]
|
|
|
+use std::collections::{hash_map, HashMap};
|
|
|
+
|
|
|
+enum VersionedBlock {
|
|
|
+ V0(Block)
|
|
|
+}
|
|
|
+
|
|
|
+struct Block {
|
|
|
+ path: String,
|
|
|
+ read_caps: HashMap<Hash, ReadCap>,
|
|
|
+ write_cap: WriteCap,
|
|
|
+ body: Vec<u8>,
|
|
|
+ signature: Signature
|
|
|
+}
|
|
|
+
|
|
|
+struct ReadCap {
|
|
|
+ issued_to: Hash,
|
|
|
+ key: EnvelopedKey,
|
|
|
+}
|
|
|
+
|
|
|
+struct WriteCap {
|
|
|
+ issued_to: Hash,
|
|
|
+ path: String,
|
|
|
+ chain: Vec<Certificate>,
|
|
|
+ signature: Signature,
|
|
|
+}
|
|
|
+
|
|
|
+struct Certificate {
|
|
|
+ issued_to: Hash,
|
|
|
+ issued_by: Hash,
|
|
|
+ signature: Signature,
|
|
|
+}
|
|
|
+
|
|
|
+enum Hash {
|
|
|
+ None,
|
|
|
+ Sha2_256([u8; 32]),
|
|
|
+ Sha2_512([u8; 64]),
|
|
|
+}
|
|
|
+
|
|
|
+enum Signature {
|
|
|
+ Ed25519([u8; 64]),
|
|
|
+}
|
|
|
+
|
|
|
+enum EnvelopedKey {
|
|
|
+ Xsalsa20Poly1305([u8; 32]),
|
|
|
+}
|
|
|
+
|
|
|
+type Directory = HashMap<String, Vec<FragmentRecord>>;
|
|
|
+
|
|
|
+trait IDirectory {
|
|
|
+ fn file_names(&self) -> hash_map::Keys<'_, String, Vec<FragmentRecord>>;
|
|
|
+}
|
|
|
+
|
|
|
+impl IDirectory for Directory {
|
|
|
+ fn file_names(&self) -> hash_map::Keys<'_, String, Vec<FragmentRecord>> {
|
|
|
+ self.keys()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+struct FragmentRecord {
|
|
|
+ stored_by: Hash,
|
|
|
+ serial: u32,
|
|
|
+}
|
|
|
+
|
|
|
+struct Fragment {
|
|
|
+ path: String,
|
|
|
+ serial: u32,
|
|
|
+ body: Vec<u8>,
|
|
|
}
|
|
|
|
|
|
fn main() {
|