[−][src]Struct ic_types::principal::Principal
A principal describes the security context of an identity, namely any identity that can be authenticated along with a specific role. In the case of the Internet Computer this maps currently to the identities that can be authenticated by a canister. For example, a canister ID is a Principal. So is a user.
Note a principal is not necessarily tied with a public key-pair, yet we need at least a key-pair of a related principal to sign requests.
A Principal can be serialized to a byte array ([Vec<u8>
]) or a text
representation, but the inner structure of the byte representation
is kept private.
Example of using a Principal object:
use ic_types::Principal; let text = "aaaaa-aa"; // The management canister ID. let principal = Principal::from_text(text).expect("Could not decode the principal."); assert_eq!(principal.as_slice(), &[]); assert_eq!(principal.to_text(), text);
Serialization is enabled with the "serde" feature. It supports serializing to a byte bufer for non-human readable serializer, and a string version for human readable serializers.
use ic_types::Principal; use serde::{Deserialize, Serialize}; use std::str::FromStr; #[derive(Serialize)] struct Data { id: Principal, } let id = Principal::from_str("2chl6-4hpzw-vqaaa-aaaaa-c").unwrap(); // JSON is human readable, so this will serialize to a textual // main.rsrepresentation of the Principal. assert_eq!( serde_json::to_string(&Data { id: id.clone() }).unwrap(), r#"{"id":"2chl6-4hpzw-vqaaa-aaaaa-c"}"# ); // CBOR is not human readable, so will serialize to bytes. assert_eq!( serde_cbor::to_vec(&Data { id: id.clone() }).unwrap(), &[161, 98, 105, 100, 73, 239, 205, 171, 0, 0, 0, 0, 0, 1], );
Implementations
impl Principal
[src]
pub fn management_canister() -> Self
[src]
pub fn self_authenticating<P: AsRef<[u8]>>(public_key: P) -> Self
[src]
Right now we are enforcing a Twisted Edwards Curve 25519 point as the public key.
pub fn anonymous() -> Self
[src]
An anonymous Principal.
pub fn from_text<S: AsRef<str>>(text: S) -> Result<Self, PrincipalError>
[src]
Parse the text format for canister IDs (e.g., jkies-sibbb-ap6
).
The text format follows the public spec (see Textual IDs section).
pub fn to_text(&self) -> String
[src]
Returns this Principal's text representation. The text representation is described in the spec.
pub fn as_slice(&self) -> &[u8]
[src]
Returns this Principal's bytes.
Trait Implementations
impl AsRef<[u8]> for Principal
[src]
impl Clone for Principal
[src]
impl Debug for Principal
[src]
impl<'de> Deserialize<'de> for Principal
[src]
fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<Principal, D::Error>
[src]
deserializer: D
) -> Result<Principal, D::Error>
impl Display for Principal
[src]
impl Eq for Principal
[src]
impl FromStr for Principal
[src]
type Err = PrincipalError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Hash for Principal
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Principal
[src]
fn cmp(&self, other: &Principal) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Principal> for Principal
[src]
impl PartialOrd<Principal> for Principal
[src]
fn partial_cmp(&self, other: &Principal) -> Option<Ordering>
[src]
fn lt(&self, other: &Principal) -> bool
[src]
fn le(&self, other: &Principal) -> bool
[src]
fn gt(&self, other: &Principal) -> bool
[src]
fn ge(&self, other: &Principal) -> bool
[src]
impl Serialize for Principal
[src]
impl StructuralEq for Principal
[src]
impl StructuralPartialEq for Principal
[src]
impl<'_> TryFrom<&'_ [u8]> for Principal
[src]
Implement try_from for a generic sized slice.
type Error = PrincipalError
The type returned in the event of a conversion error.
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ Vec<u8>> for Principal
[src]
type Error = PrincipalError
The type returned in the event of a conversion error.
fn try_from(bytes: &Vec<u8>) -> Result<Self, Self::Error>
[src]
impl<'_> TryFrom<&'_ str> for Principal
[src]
type Error = PrincipalError
The type returned in the event of a conversion error.
fn try_from(s: &str) -> Result<Self, Self::Error>
[src]
impl TryFrom<Vec<u8>> for Principal
[src]
Vector TryFrom. The slice and array version of this trait are defined below.
Auto Trait Implementations
impl RefUnwindSafe for Principal
impl Send for Principal
impl Sync for Principal
impl Unpin for Principal
impl UnwindSafe for Principal
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,