aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-11-26 18:45:59 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-11-26 18:45:59 +0100
commitf2a90a51ce3045e676ba105caf96d5037e03d4b4 (patch)
treeb6e1cd8ccba7223e79283242c28ad50c904e23f2 /src/lib.rs
downloadhohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.tar.gz
hohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.tar.bz2
hohibe-f2a90a51ce3045e676ba105caf96d5037e03d4b4.zip
initial commit
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..ce38f07
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,43 @@
+pub mod error;
+pub mod hibe;
+pub mod kem;
+
+use error::Result;
+
+/// A trait to provide byte-level access to objects.
+pub trait ByteAccess {
+ /// Provides access to the bytes.
+ ///
+ /// Unlike [`AsRef`], there are no statements made about the performance of this operation.
+ /// This operation will allocate a fresh vector, and the byte representation may or may not
+ /// have to be computed first.
+ fn bytes(&self) -> Vec<u8>;
+
+ /// Provide a short fingerprint of the bytes.
+ ///
+ /// This can be used to "summarize" long keys when displaying them, to still provide
+ /// distinguishing features but to not print out the whole key.
+ ///
+ /// By default, this method uses the first 16 bytes of the [`ByteAccess::bytes`]
+ /// representation, and formats them as a hex string.
+ fn fingerprint(&self) -> String {
+ hex::encode(&self.bytes()[..16])
+ }
+}
+
+/// A trait to mark objects that can map from an application-specific identity to a HIBE-specific
+/// identity.
+///
+/// A mapper can be implemented multiple times for a single struct, thereby providing multiple
+/// (equivalent) ways to map.
+pub trait Mapper<F, T> {
+ fn map_identity(&self, input: F) -> Result<Vec<T>>;
+}
+
+/// [`Mapper`] is automatically implemented for functions and closures that match the signature of
+/// [`Mapper::map_identity`].
+impl<X, Y, F: Fn(X) -> Result<Vec<Y>>> Mapper<X, Y> for F {
+ fn map_identity(&self, input: X) -> Result<Vec<Y>> {
+ self(input)
+ }
+}