|
@@ -98,18 +98,6 @@ struct FragmentRecord {
|
|
|
stored_by: Principal,
|
|
|
}
|
|
|
|
|
|
-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),
|
|
|
- stored_by: Principal(stored_by),
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
/// An identifier for a security principal, which is any entity that can be authenticated.
|
|
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
struct Principal(Hash);
|
|
@@ -122,13 +110,6 @@ struct Ciphertext<T>(T);
|
|
|
#[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;
|
|
|
-}
|
|
|
-
|
|
|
/// Errors which can occur when converting a string to a `Path`.
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
enum PathError {
|
|
@@ -140,6 +121,75 @@ enum PathError {
|
|
|
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);
|
|
|
+
|
|
|
+/// A cryptographic hash.
|
|
|
+#[allow(dead_code)]
|
|
|
+#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
+enum Hash {
|
|
|
+ Sha2_256([u8; 32]),
|
|
|
+ #[serde(with = "BigArray")]
|
|
|
+ Sha2_512([u8; 64]),
|
|
|
+}
|
|
|
+
|
|
|
+/// A cryptographic signature.
|
|
|
+#[allow(dead_code)]
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
+enum Signature {
|
|
|
+ #[serde(with = "BigArray")]
|
|
|
+ Ed25519([u8; 64]),
|
|
|
+}
|
|
|
+
|
|
|
+/// A cryptographic key.
|
|
|
+#[allow(dead_code)]
|
|
|
+#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
+enum Key {
|
|
|
+ Xsalsa20Poly1305([u8; 32]),
|
|
|
+}
|
|
|
+
|
|
|
+fn main() {
|
|
|
+ println!("Hello, world!");
|
|
|
+}
|
|
|
+
|
|
|
+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),
|
|
|
+ stored_by: Principal(stored_by),
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+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 {
|
|
@@ -234,42 +284,6 @@ impl<'s> TryFrom<&'s str> for Path {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/// 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);
|
|
|
-
|
|
|
-/// The serial number of a block fragment.
|
|
|
-#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
-struct FragmentSerial(u32);
|
|
|
-
|
|
|
-/// A cryptographic hash.
|
|
|
-#[allow(dead_code)]
|
|
|
-#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
-enum Hash {
|
|
|
- Sha2_256([u8; 32]),
|
|
|
- #[serde(with = "BigArray")]
|
|
|
- Sha2_512([u8; 64]),
|
|
|
-}
|
|
|
-
|
|
|
-/// A cryptographic signature.
|
|
|
-#[allow(dead_code)]
|
|
|
-#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
-enum Signature {
|
|
|
- #[serde(with = "BigArray")]
|
|
|
- Ed25519([u8; 64]),
|
|
|
-}
|
|
|
-
|
|
|
-/// A cryptographic key.
|
|
|
-#[allow(dead_code)]
|
|
|
-#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
-enum Key {
|
|
|
- Xsalsa20Poly1305([u8; 32]),
|
|
|
-}
|
|
|
-
|
|
|
-fn main() {
|
|
|
- println!("Hello, world!");
|
|
|
-}
|
|
|
-
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use super::*;
|