|
@@ -10,6 +10,8 @@ use serde_big_array::BigArray;
|
|
|
#[cfg(test)]
|
|
|
mod serde_tests;
|
|
|
|
|
|
+mod crypto;
|
|
|
+
|
|
|
/// A Block tagged with its version number.
|
|
|
#[allow(dead_code)]
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
@@ -26,13 +28,13 @@ struct Block {
|
|
|
path: Path,
|
|
|
/// This field contains a collection of `ReadCap`s indexed by the principal who holds them.
|
|
|
/// `ReadCap`s are envelopments of the key used to encrypt this block.
|
|
|
- read_caps: HashMap<Principal, Ciphertext<Key>>,
|
|
|
+ read_caps: HashMap<Principal, Cryptotext<Key>>,
|
|
|
/// This field is used to verify that the signer of this block had permission to write it.
|
|
|
/// It contains a certificate chain that must lead back to the root key for the tree this block
|
|
|
/// is part of.
|
|
|
write_cap: WriteCap,
|
|
|
/// The encrypted data contained in this block.
|
|
|
- body: Ciphertext<Vec<u8>>,
|
|
|
+ body: Cryptotext<Vec<u8>>,
|
|
|
/// The contents of the block are covered by a digital signature contained in this field.
|
|
|
signature: Signature
|
|
|
}
|
|
@@ -44,7 +46,7 @@ struct ReadCap {
|
|
|
/// The principal this `ReadCap` was issued to.
|
|
|
issued_to: Principal,
|
|
|
/// An encipherment of a block key using the public key of the principal.
|
|
|
- key: Ciphertext<Key>,
|
|
|
+ key: Cryptotext<Key>,
|
|
|
}
|
|
|
|
|
|
/// Verifies that a principal is authorized to write blocks in a tree.
|
|
@@ -102,9 +104,14 @@ struct FragmentRecord {
|
|
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Hashable)]
|
|
|
struct Principal(Hash);
|
|
|
|
|
|
-/// Encrypted data.
|
|
|
+/// Data that may or may not be encrypted.
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
|
-struct Ciphertext<T>(T);
|
|
|
+enum Cryptotext<T> {
|
|
|
+ /// The inner value of `T` is in plaintext.
|
|
|
+ Plain(T),
|
|
|
+ /// The inner value of `T` is in ciphertext.
|
|
|
+ Cipher(T),
|
|
|
+}
|
|
|
|
|
|
/// An identifier for a block in a tree.
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
@@ -159,7 +166,7 @@ fn main() {
|
|
|
|
|
|
impl ReadCap {
|
|
|
#[allow(dead_code)]
|
|
|
- fn new(issued_to: Hash, key: Ciphertext<Key>) -> ReadCap {
|
|
|
+ fn new(issued_to: Hash, key: Cryptotext<Key>) -> ReadCap {
|
|
|
ReadCap { issued_to: Principal(issued_to), key }
|
|
|
}
|
|
|
}
|