|
@@ -48,6 +48,22 @@ impl<T> Ciphertext<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+pub struct Signed<T> {
|
|
|
+ data: Vec<u8>,
|
|
|
+ sig: Signature,
|
|
|
+ phantom: PhantomData<T>,
|
|
|
+}
|
|
|
+
|
|
|
+impl<T> Signed<T> {
|
|
|
+ pub fn new(data: Vec<u8>, sig: Signature) -> Signed<T> {
|
|
|
+ Signed {
|
|
|
+ data,
|
|
|
+ sig,
|
|
|
+ phantom: PhantomData,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// Errors that can occur during cryptographic operations.
|
|
|
#[derive(Debug)]
|
|
|
pub enum Error {
|
|
@@ -1129,10 +1145,18 @@ pub(crate) trait Decrypter {
|
|
|
fn decrypt(&self, slice: &[u8]) -> Result<Vec<u8>>;
|
|
|
}
|
|
|
|
|
|
-pub(crate) trait Signer {
|
|
|
+pub trait Signer {
|
|
|
fn sign<'a, I: Iterator<Item = &'a [u8]>>(&self, parts: I) -> Result<Signature>;
|
|
|
}
|
|
|
|
|
|
+pub trait SignerExt: Signer {
|
|
|
+ fn ser_sign<T: Serialize>(&self, value: &T) -> Result<Signed<T>> {
|
|
|
+ let data = to_vec(value)?;
|
|
|
+ let sig = self.sign([data.as_slice()].into_iter())?;
|
|
|
+ Ok(Signed::new(data, sig))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
pub(crate) trait Verifier {
|
|
|
fn verify<'a, I: Iterator<Item = &'a [u8]>>(&self, parts: I, signature: &[u8]) -> Result<()>;
|
|
|
}
|
|
@@ -1153,6 +1177,7 @@ pub(crate) trait Creds: CredsPriv + CredsPub {}
|
|
|
pub(crate) trait CredStore {
|
|
|
type CredHandle: Creds;
|
|
|
type ExportedCreds: Serialize + for<'de> Deserialize<'de>;
|
|
|
+ type WritecapReq: Serialize + for<'de> Deserialize<'de> + AsRef<AsymKeyPub<Sign>>;
|
|
|
|
|
|
/// Returns the node credentials. If credentials haven't been generated, they are generated
|
|
|
/// stored and returned.
|
|
@@ -1175,6 +1200,15 @@ pub(crate) trait CredStore {
|
|
|
password: &str,
|
|
|
exported: Self::ExportedCreds,
|
|
|
) -> Result<Self::CredHandle>;
|
|
|
+ /// Creates a writecap request for the given `Principal`.
|
|
|
+ fn request_writecap(&self, root: Principal) -> Result<Self::WritecapReq>;
|
|
|
+ /// Issues a writecap for the given path to the node in the given request.
|
|
|
+ fn issue_writecap(
|
|
|
+ &self,
|
|
|
+ request: &Self::WritecapReq,
|
|
|
+ path: &Path,
|
|
|
+ password: &str,
|
|
|
+ ) -> Result<Writecap>;
|
|
|
}
|
|
|
|
|
|
/// Returns the base 2 logarithm of the given number. This function will return -1 when given 0, and
|
|
@@ -1185,7 +1219,7 @@ fn log2(mut n: usize) -> isize {
|
|
|
if 0 == n {
|
|
|
return -1;
|
|
|
}
|
|
|
- let num_bits = 8 * std::mem::size_of::<usize>() as isize;
|
|
|
+ let num_bits = usize::BITS.try_into().unwrap();
|
|
|
for k in 0..num_bits {
|
|
|
n >>= 1;
|
|
|
if 0 == n {
|