pub struct XIDDocument { /* private fields */ }Implementations§
Source§impl XIDDocument
impl XIDDocument
pub fn new( key_options: XIDInceptionKeyOptions, mark_options: XIDGenesisMarkOptions, ) -> Self
pub fn from_xid(xid: impl Into<XID>) -> Self
pub fn resolution_methods(&self) -> &HashSet<URI>
pub fn resolution_methods_mut(&mut self) -> &mut HashSet<URI>
pub fn add_resolution_method(&mut self, method: URI)
pub fn remove_resolution_method( &mut self, method: impl AsRef<URI>, ) -> Option<URI>
pub fn keys(&self) -> &HashSet<Key>
pub fn keys_mut(&mut self) -> &mut HashSet<Key>
pub fn add_key(&mut self, key: Key) -> Result<()>
pub fn find_key_by_public_keys( &self, key: &dyn PublicKeysProvider, ) -> Option<&Key>
pub fn find_key_by_reference(&self, reference: &Reference) -> Option<&Key>
Sourcepub fn private_key_envelope_for_key(
&self,
public_keys: &PublicKeys,
password: Option<&str>,
) -> Result<Option<Envelope>>
pub fn private_key_envelope_for_key( &self, public_keys: &PublicKeys, password: Option<&str>, ) -> Result<Option<Envelope>>
Get the private key envelope for a specific key, optionally decrypting it.
§Arguments
public_keys- The public keys identifying the key to retrievepassword- Optional password for decryption
§Returns
Ok(None)if the key is not found or has no private keyOk(Some(Envelope))containing:- Decrypted
PrivateKeysif unencrypted - Decrypted
PrivateKeysif encrypted and correct password provided - Encrypted envelope if encrypted and no password provided
- Decrypted
Err(Error::InvalidPassword)if encrypted and wrong password provided
§Examples
use bc_components::{PrivateKeyBase, PublicKeysProvider};
use bc_envelope::prelude::*;
use bc_xid::{XIDDocument, XIDGenesisMarkOptions, XIDInceptionKeyOptions};
let prvkey_base = PrivateKeyBase::new();
let doc = XIDDocument::new(
XIDInceptionKeyOptions::PrivateKeyBase(prvkey_base.clone()),
XIDGenesisMarkOptions::None,
);
// Get unencrypted private key
let key = doc.keys().iter().next().unwrap();
let envelope = doc
.private_key_envelope_for_key(key.public_keys(), None)
.unwrap()
.unwrap();pub fn take_key(&mut self, key: &dyn PublicKeysProvider) -> Option<Key>
pub fn remove_key(&mut self, key: &dyn PublicKeysProvider) -> Result<()>
pub fn set_name_for_key( &mut self, key: &dyn PublicKeysProvider, name: impl Into<String>, ) -> Result<()>
pub fn is_inception_signing_key( &self, signing_public_key: &SigningPublicKey, ) -> bool
pub fn inception_signing_key(&self) -> Option<&SigningPublicKey>
pub fn inception_key(&self) -> Option<&Key>
pub fn remove_inception_key(&mut self) -> Option<Key>
pub fn verification_key(&self) -> Option<&SigningPublicKey>
pub fn encryption_key(&self) -> Option<&EncapsulationPublicKey>
Sourcepub fn inception_private_keys(&self) -> Option<&PrivateKeys>
pub fn inception_private_keys(&self) -> Option<&PrivateKeys>
Get the private keys from the inception key, if available.
Returns None if there is no inception key or if the inception key
does not have private key material (e.g., if it was encrypted and not
decrypted).
Sourcepub fn extract_inception_private_keys_from_envelope(
envelope: &Envelope,
password: &[u8],
) -> Result<Option<PrivateKeys>>
pub fn extract_inception_private_keys_from_envelope( envelope: &Envelope, password: &[u8], ) -> Result<Option<PrivateKeys>>
Extract private keys from an envelope containing an encrypted XIDDocument.
This is a convenience method that loads the document with the password and returns the inception key’s private keys if available.
Returns None if:
- The document has no inception key
- The inception key has no private key material
- The password is incorrect
pub fn is_empty(&self) -> bool
pub fn delegates(&self) -> &HashSet<Delegate>
pub fn delegates_mut(&mut self) -> &mut HashSet<Delegate>
pub fn add_delegate(&mut self, delegate: Delegate) -> Result<()>
pub fn find_delegate_by_xid( &self, xid_provider: &dyn XIDProvider, ) -> Option<&Delegate>
pub fn find_delegate_by_reference( &self, reference: &Reference, ) -> Option<&Delegate>
pub fn take_delegate( &mut self, xid_provider: &dyn XIDProvider, ) -> Option<Delegate>
pub fn remove_delegate(&mut self, xid_provider: &dyn XIDProvider) -> Result<()>
pub fn find_service_by_uri(&self, uri: impl AsRef<URI>) -> Option<&Service>
pub fn services(&self) -> &HashSet<Service>
pub fn add_service(&mut self, service: Service) -> Result<()>
pub fn take_service(&mut self, uri: impl AsRef<URI>) -> Option<Service>
pub fn check_services_consistency(&self) -> Result<()>
pub fn check_service_consistency(&self, service: &Service) -> Result<()>
pub fn check_contains_key(&self, key: &dyn PublicKeysProvider) -> Result<()>
pub fn check_contains_delegate( &self, xid_provider: &dyn XIDProvider, ) -> Result<()>
pub fn services_reference_key(&self, key: &dyn PublicKeysProvider) -> bool
pub fn services_reference_delegate( &self, xid_provider: &dyn XIDProvider, ) -> bool
pub fn remove_service(&mut self, uri: impl AsRef<URI>) -> Result<()>
pub fn provenance(&self) -> Option<&ProvenanceMark>
pub fn provenance_generator(&self) -> Option<&ProvenanceMarkGenerator>
pub fn set_provenance(&mut self, provenance: Option<ProvenanceMark>)
pub fn set_provenance_with_generator( &mut self, generator: ProvenanceMarkGenerator, mark: ProvenanceMark, )
Sourcepub fn next_provenance_mark_with_embedded_generator(
&mut self,
password: Option<Vec<u8>>,
date: Option<Date>,
info: Option<CBOR>,
) -> Result<()>
pub fn next_provenance_mark_with_embedded_generator( &mut self, password: Option<Vec<u8>>, date: Option<Date>, info: Option<CBOR>, ) -> Result<()>
Advance the provenance mark using the embedded generator.
This method uses the generator embedded in the document’s provenance to generate the next provenance mark. If the generator is encrypted, it will be decrypted using the provided password. After advancement, the generator remains in the document in decrypted state.
§Parameters
password: Optional password to decrypt the generator if encrypted. Pass asVec<u8>orNone.date: Optional date for the new mark. IfNone, the current date is used.info: Optional CBOR-encodable info to attach to the new mark.
§Errors
Returns an error if:
- The document does not have a provenance mark
(
Error::NoProvenanceMark) - The document does not have a generator (
Error::NoGenerator) - The generator is encrypted and the password is wrong
(
Error::InvalidPassword)
Sourcepub fn next_provenance_mark_with_provided_generator(
&mut self,
generator: &mut ProvenanceMarkGenerator,
date: Option<Date>,
info: Option<CBOR>,
) -> Result<()>
pub fn next_provenance_mark_with_provided_generator( &mut self, generator: &mut ProvenanceMarkGenerator, date: Option<Date>, info: Option<CBOR>, ) -> Result<()>
Advance the provenance mark using a provided generator.
This method uses an external generator to generate the next provenance mark. The generator is not embedded in the document after advancement; the caller maintains ownership of the generator.
§Parameters
generator: Mutable reference to the externalProvenanceMarkGenerator.date: Optional date for the new mark. IfNone, the current date is used.info: Optional CBOR-encodable info to attach to the new mark.
§Errors
Returns an error if:
- The document does not have a provenance mark
(
Error::NoProvenanceMark) - The document already has an embedded generator
(
Error::GeneratorConflict) - The provided generator’s chain ID doesn’t match the current mark’s chain ID
- The provided generator’s next_seq doesn’t match the expected sequence number
Sourcepub fn to_envelope(
&self,
private_key_options: XIDPrivateKeyOptions,
generator_options: XIDGeneratorOptions,
signing_options: XIDSigningOptions,
) -> Result<Envelope>
pub fn to_envelope( &self, private_key_options: XIDPrivateKeyOptions, generator_options: XIDGeneratorOptions, signing_options: XIDSigningOptions, ) -> Result<Envelope>
Convert XIDDocument to an Envelope.
Sourcepub fn from_envelope(
envelope: &Envelope,
password: Option<&[u8]>,
verify_signature: XIDVerifySignature,
) -> Result<Self>
pub fn from_envelope( envelope: &Envelope, password: Option<&[u8]>, verify_signature: XIDVerifySignature, ) -> Result<Self>
Extract an XIDDocument from an envelope.
§Parameters
envelope: The envelope to extract the document from. Can be signed or unsigned.password: Optional password to decrypt encrypted private keys. If private keys are encrypted and no password is provided, the keys will be stored without their private key material.verify_signature: Signature verification mode. UseXIDVerifySignature::Noneto skip verification, orXIDVerifySignature::Inceptionto verify that the envelope is signed with the inception key.
§Returns
Returns Ok(XIDDocument) on success.
§Errors
Error::EnvelopeNotSigned: Whenverify_signatureisInceptionbut the envelope is not signed.Error::MissingInceptionKey: Whenverify_signatureisInceptionbut the inception key is not found in the document.Error::SignatureVerificationFailed: When the signature verification fails.Error::InvalidXid: When the inception key does not match the XID.- Other errors from envelope parsing or key extraction.
pub fn to_signed_envelope(&self, signing_key: &impl Signer) -> Envelope
pub fn to_signed_envelope_opt( &self, signing_key: &impl Signer, private_key_options: XIDPrivateKeyOptions, ) -> Envelope
Trait Implementations§
Source§impl AsRef<XIDDocument> for XIDDocument
impl AsRef<XIDDocument> for XIDDocument
Source§fn as_ref(&self) -> &XIDDocument
fn as_ref(&self) -> &XIDDocument
Source§impl Attachable for XIDDocument
impl Attachable for XIDDocument
Source§fn attachments(&self) -> &Attachments
fn attachments(&self) -> &Attachments
Source§fn attachments_mut(&mut self) -> &mut Attachments
fn attachments_mut(&mut self) -> &mut Attachments
Source§fn add_attachment(
&mut self,
payload: impl EnvelopeEncodable,
vendor: &str,
conforms_to: Option<&str>,
)
fn add_attachment( &mut self, payload: impl EnvelopeEncodable, vendor: &str, conforms_to: Option<&str>, )
Source§fn get_attachment(&self, digest: Digest) -> Option<&Envelope>
fn get_attachment(&self, digest: Digest) -> Option<&Envelope>
Source§fn remove_attachment(&mut self, digest: Digest) -> Option<Envelope>
fn remove_attachment(&mut self, digest: Digest) -> Option<Envelope>
Source§fn clear_attachments(&mut self)
fn clear_attachments(&mut self)
Source§fn has_attachments(&self) -> bool
fn has_attachments(&self) -> bool
Source§impl CBORTagged for XIDDocument
impl CBORTagged for XIDDocument
Source§impl CBORTaggedDecodable for XIDDocument
impl CBORTaggedDecodable for XIDDocument
Source§fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for XIDDocument
impl CBORTaggedEncodable for XIDDocument
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for XIDDocument
impl Clone for XIDDocument
Source§fn clone(&self) -> XIDDocument
fn clone(&self) -> XIDDocument
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for XIDDocument
impl Debug for XIDDocument
Source§impl Default for XIDDocument
impl Default for XIDDocument
Source§impl Edgeable for XIDDocument
impl Edgeable for XIDDocument
Source§fn clear_edges(&mut self)
fn clear_edges(&mut self)
Source§impl From<&PrivateKeyBase> for XIDDocument
impl From<&PrivateKeyBase> for XIDDocument
Source§fn from(inception_key: &PrivateKeyBase) -> Self
fn from(inception_key: &PrivateKeyBase) -> Self
Source§impl From<PrivateKeyBase> for XIDDocument
impl From<PrivateKeyBase> for XIDDocument
Source§fn from(inception_key: PrivateKeyBase) -> Self
fn from(inception_key: PrivateKeyBase) -> Self
Source§impl From<PublicKeys> for XIDDocument
impl From<PublicKeys> for XIDDocument
Source§fn from(inception_key: PublicKeys) -> Self
fn from(inception_key: PublicKeys) -> Self
Source§impl From<XID> for XIDDocument
impl From<XID> for XIDDocument
Source§impl From<XIDDocument> for CBOR
impl From<XIDDocument> for CBOR
Source§fn from(value: XIDDocument) -> Self
fn from(value: XIDDocument) -> Self
Source§impl From<XIDDocument> for Envelope
impl From<XIDDocument> for Envelope
Source§fn from(value: XIDDocument) -> Self
fn from(value: XIDDocument) -> Self
Source§impl From<XIDDocument> for XID
impl From<XIDDocument> for XID
Source§fn from(doc: XIDDocument) -> Self
fn from(doc: XIDDocument) -> Self
Source§impl PartialEq for XIDDocument
impl PartialEq for XIDDocument
Source§impl ReferenceProvider for XIDDocument
impl ReferenceProvider for XIDDocument
Source§fn reference(&self) -> Reference
fn reference(&self) -> Reference
Source§fn ref_hex_short(&self) -> String
fn ref_hex_short(&self) -> String
Source§impl TryFrom<&Envelope> for XIDDocument
impl TryFrom<&Envelope> for XIDDocument
Source§impl TryFrom<CBOR> for XIDDocument
impl TryFrom<CBOR> for XIDDocument
Source§impl TryFrom<Envelope> for XIDDocument
impl TryFrom<Envelope> for XIDDocument
Source§impl XIDProvider for XIDDocument
impl XIDProvider for XIDDocument
impl Eq for XIDDocument
impl StructuralPartialEq for XIDDocument
Auto Trait Implementations§
impl Freeze for XIDDocument
impl RefUnwindSafe for XIDDocument
impl Send for XIDDocument
impl Sync for XIDDocument
impl Unpin for XIDDocument
impl UnwindSafe for XIDDocument
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> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EnvelopeEncodable for T
impl<T> EnvelopeEncodable for T
Source§fn into_envelope(self) -> Envelope
fn into_envelope(self) -> Envelope
Converts the value into an envelope by using its Into<Envelope>
implementation.
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