8 releases
0.4.1 | Aug 9, 2024 |
---|---|
0.4.0 | Jan 19, 2024 |
0.3.0 | Jul 4, 2023 |
0.2.1 | Dec 14, 2022 |
0.1.2 | Aug 23, 2021 |
#2441 in Encoding
394 downloads per month
Used in 21 crates
(18 directly)
29KB
627 lines
Self-Addressing Identifier
A Rust implementation of the IETF Draft SAID specification.
Self-Addressing Identifier (SAID) provides a compact text representation of digests of data. It supports multiple hash algorithms (see below).
License
EUPL 1.2
We have distilled the most crucial license specifics to make your adoption seamless: see here for details.
Example
let data = "hello there";
let code: HashFunction = HashFunctionCode::Blake3_256.into();
let sai = code.derive(data.as_bytes());
assert_eq!(format!("{}", sai), "ENmwqnqVxonf_bNZ0hMipOJJY25dxlC8eSY5BbyMCfLJ");
assert!(sai.verify_binding(data.as_bytes()));
assert!(!sai.verify_binding("wrong data".as_bytes()));
See https://github.com/THCLab/cesrox/blob/master/said/tests/ for full fledged examples.
Supported hash functions
derivation code | digest type | code length | identifier length |
---|---|---|---|
E | Blake3-256 Digest | 1 | 44 |
F | Blake2b-256 Digest | 1 | 44 |
G | Blake2s-256 Digest | 1 | 44 |
H | SHA3-256 Digest | 1 | 44 |
I | SHA2-256 Digest | 1 | 44 |
0D | Blake3-512 Digest | 2 | 88 |
0E | Blake2b-512 Digest | 2 | 88 |
0F | SHA3-512 Digest | 2 | 88 |
0G | SHA2-512 Digest | 2 | 88 |
Self Addressing Data
Module sad
provides trait SAD
that has functions:
compute_digest
- computes the Self Addressing Identifier of a data structure, places it in a chosen field,derivation_data
- returns data that are used for SAID computation.
The SAD trait can be implemented for structures using the provided derive macro. It allows users to select which fields will be replaced by the computed Self Addressing Identifier.
To use macro, feature macros
need to be enabled. It works only for structures that implement Serialize
using the #[derive(Serialize)]
attribute, rather than a custom implementation.
Attributes
Macro uses with following attributes:
version
- adds version field while computing derivation data. Version string contains compact representation of field map, serialization format, and size of a serialized message body. Attribute let user specify protocol code and its major and minor version. When attribute is used, the structure automatically implements theEncode
trait, which provides theencode
function for serializing the element according to the chosen serialization format.said
- this attribute allows users to choose the hash function for computing Self Addressing Identifier and serialization format. The hash function can be specified using the derivation code from the table above. The available serialization formats are JSON, CBOR, and MGPK. By default, JSON and Blake3-256 are used.
Field attributes:
said
- marks field that should be replaced by computed digest duringcompute_digest
.
Example:
#[derive(SAD, Serialize)]
#[version(protocol = "KERI", major = 1, minor = 0)]
struct Something {
pub text: String,
#[said]
pub d: Option<SelfAddressingIdentifier>,
}
Releasing new version
cargo-release is required
To release new version run cargo release
Due to release config it will bump version, create new git tag and push it to remote.
Dependencies
~9MB
~169K SLoC