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 for DID
impl PartialOrd for DID
impl Eq for DID
impl StructuralPartialEq for DID
Auto Trait Implementations§
impl Freeze for DID
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more