|
@@ -18,7 +18,6 @@ mod crypto;
|
|
|
use crypto::{Hash, Signature, Key, Cryptotext};
|
|
|
|
|
|
/// A Block tagged with its version number.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
enum VersionedBlock {
|
|
|
V0(Block)
|
|
@@ -26,7 +25,6 @@ enum VersionedBlock {
|
|
|
|
|
|
/// A container which binds together ciphertext along with the metadata needed to identify,
|
|
|
/// verify and decrypt it.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct Block {
|
|
|
/// Identifies this block and defines its location in the tree.
|
|
@@ -45,7 +43,6 @@ struct Block {
|
|
|
}
|
|
|
|
|
|
/// An envelopment of a key, which is tagged with the principal who the key is meant for.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct ReadCap {
|
|
|
/// The principal this `ReadCap` was issued to.
|
|
@@ -54,8 +51,13 @@ struct ReadCap {
|
|
|
key: Cryptotext<Key>,
|
|
|
}
|
|
|
|
|
|
+impl ReadCap {
|
|
|
+ fn new(issued_to: Hash, key: Cryptotext<Key>) -> ReadCap {
|
|
|
+ ReadCap { issued_to: Principal(issued_to), key }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// Verifies that a principal is authorized to write blocks in a tree.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct WriteCap {
|
|
|
/// The principal this `WriteCap` was issued to.
|
|
@@ -76,7 +78,6 @@ struct WriteCap {
|
|
|
|
|
|
/// Fragments are created from blocks using Erasure Encoding and stored with other nodes in the
|
|
|
/// network to provide availability and redundancy of data.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct Fragment {
|
|
|
/// The path to the block this fragment is from.
|
|
@@ -87,8 +88,20 @@ struct Fragment {
|
|
|
body: Vec<u8>,
|
|
|
}
|
|
|
|
|
|
+impl Fragment {
|
|
|
+ /// Create a new fragment with the given fields. If `path_str` cannot be parsed then a failed
|
|
|
+ /// `Result` is returned containing a `PathError`.
|
|
|
+ fn new(path_str: &str, serial_num: u32, body: Vec<u8>) -> Result<Fragment, PathError> {
|
|
|
+ let result = Path::try_from(path_str);
|
|
|
+ Ok(Fragment {
|
|
|
+ path: result?,
|
|
|
+ serial: FragmentSerial(serial_num),
|
|
|
+ body
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// The body of every non-leaf node in a tree contains this data structure.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct Directory {
|
|
|
/// The nodes that are attached to the tree at this block.
|
|
@@ -98,7 +111,6 @@ struct Directory {
|
|
|
}
|
|
|
|
|
|
/// Keeps track of which principal is storing a fragment.
|
|
|
-#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
struct FragmentRecord {
|
|
|
/// The fragment serial number this record is for.
|
|
@@ -107,62 +119,9 @@ struct FragmentRecord {
|
|
|
stored_by: Principal,
|
|
|
}
|
|
|
|
|
|
-/// An identifier for a security principal, which is any entity that can be authenticated.
|
|
|
-#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
-struct Principal(Hash);
|
|
|
-
|
|
|
-/// An identifier for a block in a tree.
|
|
|
-#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
-struct Path(Vec<String>);
|
|
|
-
|
|
|
-/// Errors which can occur when converting a string to a `Path`.
|
|
|
-#[derive(Debug, PartialEq)]
|
|
|
-enum PathError {
|
|
|
- /// Occurs when the number of bytes in a string is greater than `Path::BYTE_LIMIT`.
|
|
|
- PathTooLong(usize),
|
|
|
- /// Indicates that a path string was empty.
|
|
|
- Empty,
|
|
|
- /// Occurs when a component in a path string was empty.
|
|
|
- EmptyComponent,
|
|
|
-}
|
|
|
-
|
|
|
-/// 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(i64);
|
|
|
-
|
|
|
-/// The serial number of a block fragment.
|
|
|
-#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
-struct FragmentSerial(u32);
|
|
|
-
|
|
|
-fn main() {
|
|
|
- println!("Hello, world!");
|
|
|
-}
|
|
|
-
|
|
|
-impl ReadCap {
|
|
|
- #[allow(dead_code)]
|
|
|
- fn new(issued_to: Hash, key: Cryptotext<Key>) -> ReadCap {
|
|
|
- ReadCap { issued_to: Principal(issued_to), key }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Fragment {
|
|
|
- /// Create a new fragment with the given fields. If `path_str` cannot be parsed then a failed
|
|
|
- /// `Result` is returned containing a `PathError`.
|
|
|
- #[allow(dead_code)]
|
|
|
- fn new(path_str: &str, serial_num: u32, body: Vec<u8>) -> Result<Fragment, PathError> {
|
|
|
- let result = Path::try_from(path_str);
|
|
|
- Ok(Fragment {
|
|
|
- path: result?,
|
|
|
- serial: FragmentSerial(serial_num),
|
|
|
- body
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
impl FragmentRecord {
|
|
|
/// Creates a new `FragmentRecord` whose `serial` and `stored_by` fields are set to
|
|
|
/// the given values.
|
|
|
- #[allow(dead_code)]
|
|
|
fn new(serial: u32, stored_by: Hash) -> FragmentRecord {
|
|
|
FragmentRecord {
|
|
|
serial: FragmentSerial(serial),
|
|
@@ -171,28 +130,20 @@ impl FragmentRecord {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// An identifier for a security principal, which is any entity that can be authenticated.
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
+struct Principal(Hash);
|
|
|
+
|
|
|
+/// An identifier for a block in a tree.
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
+struct Path(Vec<String>);
|
|
|
+
|
|
|
impl Path {
|
|
|
/// The character that is used to separate path components.
|
|
|
const SEP: char = '/';
|
|
|
/// The limit, in bytes, of a `Path`'s length.
|
|
|
const BYTE_LIMIT: usize = 4096;
|
|
|
-}
|
|
|
|
|
|
-impl Display for PathError {
|
|
|
- fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
|
|
|
- match self {
|
|
|
- PathError::PathTooLong(length) => formatter.write_fmt(format_args!(
|
|
|
- "path contained {} bytes, which is over the {} byte limit",
|
|
|
- length,
|
|
|
- Path::BYTE_LIMIT)
|
|
|
- ),
|
|
|
- PathError::Empty => formatter.write_str("path was empty"),
|
|
|
- PathError::EmptyComponent => formatter.write_str("component of path was empty"),
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl Path {
|
|
|
/// Returns a result which, when successful, returns the index after the last character in the
|
|
|
/// current path component.
|
|
|
fn component_end<I: Iterator<Item = (usize, char)>>(
|
|
@@ -241,11 +192,11 @@ impl Path {
|
|
|
|
|
|
/// Asserts that the number of bytes in the given string is no more than `Path::BYTE_LIMIT`.
|
|
|
fn assert_not_too_long(string: &str) -> Result<(), PathError> {
|
|
|
- let len = string.len();
|
|
|
- if len > Path::BYTE_LIMIT {
|
|
|
- return Err(PathError::PathTooLong(len))
|
|
|
- }
|
|
|
- Ok(())
|
|
|
+ let len = string.len();
|
|
|
+ if len > Path::BYTE_LIMIT {
|
|
|
+ return Err(PathError::PathTooLong(len))
|
|
|
+ }
|
|
|
+ Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -272,6 +223,43 @@ impl<'s> TryFrom<&'s str> for Path {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/// Errors which can occur when converting a string to a `Path`.
|
|
|
+#[derive(Debug, PartialEq)]
|
|
|
+enum PathError {
|
|
|
+ /// Occurs when the number of bytes in a string is greater than `Path::BYTE_LIMIT`.
|
|
|
+ PathTooLong(usize),
|
|
|
+ /// Indicates that a path string was empty.
|
|
|
+ Empty,
|
|
|
+ /// Occurs when a component in a path string was empty.
|
|
|
+ EmptyComponent,
|
|
|
+}
|
|
|
+
|
|
|
+impl Display for PathError {
|
|
|
+ fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
|
|
|
+ match self {
|
|
|
+ PathError::PathTooLong(length) => formatter.write_fmt(format_args!(
|
|
|
+ "path contained {} bytes, which is over the {} byte limit",
|
|
|
+ length,
|
|
|
+ Path::BYTE_LIMIT)
|
|
|
+ ),
|
|
|
+ PathError::Empty => formatter.write_str("path was empty"),
|
|
|
+ PathError::EmptyComponent => formatter.write_str("component of path was empty"),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/// 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(i64);
|
|
|
+
|
|
|
+/// The serial number of a block fragment.
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
+struct FragmentSerial(u32);
|
|
|
+
|
|
|
+fn main() {
|
|
|
+ println!("Hello, world!");
|
|
|
+}
|
|
|
+
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use super::*;
|