Struct did_toolkit::did::DID
source · pub struct DID {
pub name: Vec<u8>,
pub id: Vec<u8>,
}Expand description
A DID is a decentralized identity according to https://www.w3.org/TR/did-core/#did-syntax. A
DID internally is represented as a byte array that is percent-encoded on demand according to
the rules defined in that document, as well as validated in some instances with regards to
encoding requirements. DIDs are not required to be UTF-8 compliant in the ID portion, and all
bytes that fall outside of a normal alphanumeric ASCII range are percent-encoded, with a few
exceptions. The internal types are Vec<u8> for malleability but this may change to [u8] in the
future.
DIDs must have both a non-empty name and ID portion according to this interpretation of the
spec. They must start with did: and will be generated as such both in string conversion and
serialization steps. De-serialization also runs through the same checks and conversions.
use did_toolkit::prelude::*;
let did = DID::parse("did:mymethod:alice").unwrap();
assert_eq!(String::from_utf8(did.name).unwrap(), "mymethod");
assert_eq!(String::from_utf8(did.id).unwrap(), "alice");
let did = DID {
name: "mymethod".as_bytes().to_vec(),
id: "alice".as_bytes().to_vec(),
};
assert_eq!(did.to_string(), "did:mymethod:alice");Fields§
§name: Vec<u8>§id: Vec<u8>Implementations§
source§impl DID
impl DID
sourcepub fn parse(s: &str) -> Result<Self, Error>
pub fn parse(s: &str) -> Result<Self, Error>
Parse a DID from a string. See top-level type documentation for information on formats.
sourcepub fn join(&self, parameters: URLParameters) -> URL
pub fn join(&self, parameters: URLParameters) -> URL
When provided with URL parameters, generates a DID URL. These are different from hypertext URLs and should be handled differently.
use did_toolkit::prelude::*;
let did = DID::parse("did:mymethod:alice").unwrap();
let url = did.join(URLParameters{
fragment: Some("key-1".as_bytes().to_vec()),
..Default::default()
});
assert_eq!(url.to_string(), "did:mymethod:alice#key-1");Trait Implementations§
source§impl<'de> Deserialize<'de> for DID
impl<'de> Deserialize<'de> for DID
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl Ord for DID
impl Ord for DID
source§impl PartialOrd<DID> for DID
impl PartialOrd<DID> for DID
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for DID
impl StructuralEq for DID
impl StructuralPartialEq for DID
Auto Trait Implementations§
impl RefUnwindSafe for DID
impl Send for DID
impl Sync for DID
impl Unpin for DID
impl UnwindSafe for DID
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.