|
@@ -1,7 +1,16 @@
|
|
-use std::collections::HashMap;
|
|
|
|
|
|
+use std::{
|
|
|
|
+ collections::HashMap,
|
|
|
|
+ hash::Hash as Hashable,
|
|
|
|
+};
|
|
|
|
+use serde::{Serialize, Deserialize};
|
|
|
|
+use serde_big_array::BigArray;
|
|
|
|
+
|
|
|
|
+#[cfg(test)]
|
|
|
|
+mod serde_tests;
|
|
|
|
|
|
/// A Block tagged with its version number.
|
|
/// A Block tagged with its version number.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
enum VersionedBlock {
|
|
enum VersionedBlock {
|
|
V0(Block)
|
|
V0(Block)
|
|
}
|
|
}
|
|
@@ -9,6 +18,7 @@ enum VersionedBlock {
|
|
/// A container which binds together ciphertext along with the metadata needed to identify,
|
|
/// A container which binds together ciphertext along with the metadata needed to identify,
|
|
/// verify and decrypt it.
|
|
/// verify and decrypt it.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Block {
|
|
struct Block {
|
|
/// Identifies this block and defines its location in the tree.
|
|
/// Identifies this block and defines its location in the tree.
|
|
path: Path,
|
|
path: Path,
|
|
@@ -27,6 +37,7 @@ struct Block {
|
|
|
|
|
|
/// An envelopment of a key, which is tagged with the principal who the key is meant for.
|
|
/// An envelopment of a key, which is tagged with the principal who the key is meant for.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct ReadCap {
|
|
struct ReadCap {
|
|
/// The principal this `ReadCap` was issued to.
|
|
/// The principal this `ReadCap` was issued to.
|
|
issued_to: Principal,
|
|
issued_to: Principal,
|
|
@@ -36,6 +47,7 @@ struct ReadCap {
|
|
|
|
|
|
/// Verifies that a principal is authorized to write blocks in a tree.
|
|
/// Verifies that a principal is authorized to write blocks in a tree.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct WriteCap {
|
|
struct WriteCap {
|
|
/// The principal this `WriteCap` was issued to.
|
|
/// The principal this `WriteCap` was issued to.
|
|
issued_to: Principal,
|
|
issued_to: Principal,
|
|
@@ -54,6 +66,7 @@ struct WriteCap {
|
|
/// Fragments are created from blocks using Erasure Encoding and stored with other nodes in the
|
|
/// Fragments are created from blocks using Erasure Encoding and stored with other nodes in the
|
|
/// network to provide availability and redundancy of data.
|
|
/// network to provide availability and redundancy of data.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Fragment {
|
|
struct Fragment {
|
|
/// The path to the block this fragment is from.
|
|
/// The path to the block this fragment is from.
|
|
path: Path,
|
|
path: Path,
|
|
@@ -65,6 +78,7 @@ struct Fragment {
|
|
|
|
|
|
/// The body of every non-leaf node in a tree contains this data structure.
|
|
/// The body of every non-leaf node in a tree contains this data structure.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Directory {
|
|
struct Directory {
|
|
/// The nodes that are attached to the tree at this block.
|
|
/// The nodes that are attached to the tree at this block.
|
|
nodes: Vec<Principal>,
|
|
nodes: Vec<Principal>,
|
|
@@ -74,6 +88,7 @@ struct Directory {
|
|
|
|
|
|
/// Keeps track of which principal is storing a fragment.
|
|
/// Keeps track of which principal is storing a fragment.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct FragmentRecord {
|
|
struct FragmentRecord {
|
|
/// The fragment serial number this record is for.
|
|
/// The fragment serial number this record is for.
|
|
serial: FragmentSerial,
|
|
serial: FragmentSerial,
|
|
@@ -82,35 +97,45 @@ struct FragmentRecord {
|
|
}
|
|
}
|
|
|
|
|
|
/// An identifier for a security principal, which is any entity that can be authenticated.
|
|
/// An identifier for a security principal, which is any entity that can be authenticated.
|
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
struct Principal(Hash);
|
|
struct Principal(Hash);
|
|
|
|
|
|
/// Encrypted data.
|
|
/// Encrypted data.
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Ciphertext<T>(T);
|
|
struct Ciphertext<T>(T);
|
|
|
|
|
|
/// An identifier for a block in a tree.
|
|
/// An identifier for a block in a tree.
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Path(Vec<String>);
|
|
struct Path(Vec<String>);
|
|
|
|
|
|
/// An instant in time represented by the number of seconds since January 1st 1970, 00:00:00 UTC.
|
|
/// An instant in time represented by the number of seconds since January 1st 1970, 00:00:00 UTC.
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
struct Epoch(u64);
|
|
struct Epoch(u64);
|
|
|
|
|
|
/// The serial number of a block fragment.
|
|
/// The serial number of a block fragment.
|
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
struct FragmentSerial(u32);
|
|
struct FragmentSerial(u32);
|
|
|
|
|
|
/// A cryptographic hash.
|
|
/// A cryptographic hash.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
enum Hash {
|
|
enum Hash {
|
|
Sha2_256([u8; 32]),
|
|
Sha2_256([u8; 32]),
|
|
|
|
+ #[serde(with = "BigArray")]
|
|
Sha2_512([u8; 64]),
|
|
Sha2_512([u8; 64]),
|
|
}
|
|
}
|
|
|
|
|
|
/// A cryptographic signature.
|
|
/// A cryptographic signature.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
enum Signature {
|
|
enum Signature {
|
|
|
|
+ #[serde(with = "BigArray")]
|
|
Ed25519([u8; 64]),
|
|
Ed25519([u8; 64]),
|
|
}
|
|
}
|
|
|
|
|
|
/// A cryptographic key.
|
|
/// A cryptographic key.
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
enum Key {
|
|
enum Key {
|
|
Xsalsa20Poly1305([u8; 32]),
|
|
Xsalsa20Poly1305([u8; 32]),
|
|
}
|
|
}
|