pub struct EmbeddedCert<VD, UR> {
verified: Option<VD>,
unverified: UR,
}Expand description
One certificate inside a netdoc, covering data other than the netdoc itself
§Semantics and value
This type always embodies:
-
The encoded form of a certificate or signature (its actual bytes, for encoding/decoding.
This encoded unverified raw form is the type parameter
UR. OftenURwill betor_cert::KeyUnknownCert.
Additionally, it can and usually does contain the “verified form”:
-
Interpreted, parsed, data, of whatever was certified. For example, for a family certificate, the family IDs.
It might or might not include something like a
tor_cert::Ed25519Cert, depending whether downstreams need that information.This decoded verified data is the type parameter
VD;EmbeddedCertcontainsOption<VD>(or equivalent).
(We call an EmbeddedCert without the verified form an “unverified EmbeddedCert”.)
§Correctness/availability invariant
Whenever an EmbeddedCert appears in a parsed and verified network document body,
the EmbeddedCert has been verified and the verified form is present.
During parsing of a network document, the document type’s verification function
gets access to the unverified EmbeddedCert.
It is the verify function which must verify and timecheck the certificate,
and, if it is satisfied, call set_verified.
Include fields of this type in documents deriving
NetdocParseableUnverified,
rather than plain NetdocParseable.
This invariant is somewhat fuzzy around the edges, and not 100% enforced by the compiler.
If it is relied on inappropriately, or violated, Bug is thrown.
§Security invariant
Presence of the verified form guarantees that, if the document came from outside, we have verified the signature, and checked that it is timely. So the interpreted form can safely be used.
This guarantee flows from the caller of set_verified,
and may be relied on by users - eg, by callers of get.
§Parsing and encoding
This type implements applicable parsing and encoding traits,
if VD is EmbeddableCertObject<UR>
and UR is Readable and Writable.
See EmbeddableCertObject for full details.
§Example
See crates/tor-netdoc/src/types/embedded_cert/test.rs.
Fields§
§verified: Option<VD>The verified form, if this EmbeddedCert is verified.
unverified: URThe unverified form.
Implementations§
Source§impl<VD, UR> EmbeddedCert<VD, UR>
impl<VD, UR> EmbeddedCert<VD, UR>
Sourcepub fn new(data: VD, raw: UR) -> Self
pub fn new(data: VD, raw: UR) -> Self
Make a new (verified) EmbeddedCert
§Security
If this certificate originated elsewhere, it must have been verified and timechecked.
Sourcepub fn get(&self) -> Result<&VD, Bug>
pub fn get(&self) -> Result<&VD, Bug>
Obtain the verified data
This function will always succeed on a cert found in a (verified) netdoc.
§Error conditions
get will fail only if the correctness/availability invariant
is violated or relied on inappropriately.
See the type-level documentation.
It can fail inside a netdoc verification function,
or after EmbeddedCert::new_unverified_hazardous.
It could also fail if an EmbeddedCert is included in an unsigned netdoc
(ie one to which derived plain
NetdocParseable
rather than
NetdocParseableUnverified.
Sourcepub fn new_unverified_hazardous(unverified: UR) -> Self
pub fn new_unverified_hazardous(unverified: UR) -> Self
Make a new unverified EmbeddedCert
§Correctness
It is the caller’s responsibility to uphold the correctness/availability invariant. See the type-level documentation.
Carelessly creating a loose unverified EmbeddedCert
could expose it to naive code, which expects get to succeed.
Sourcepub fn raw_unverified(&self) -> &UR
pub fn raw_unverified(&self) -> &UR
Obtain the raw data, for verification or encoding
Sourcepub fn set_verified(&mut self, verified: VD)
pub fn set_verified(&mut self, verified: VD)
Set the verified data
Usually called from within a document-specific verify function.
§Security
The signature must have been verified, and timeliness checked.
Trait Implementations§
Source§impl<VD: Clone, UR: Clone> Clone for EmbeddedCert<VD, UR>
impl<VD: Clone, UR: Clone> Clone for EmbeddedCert<VD, UR>
Source§fn clone(&self) -> EmbeddedCert<VD, UR>
fn clone(&self) -> EmbeddedCert<VD, UR>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<VD, UR> ItemObjectEncodable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Writeable,
impl<VD, UR> ItemObjectEncodable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Writeable,
Source§impl<VD, UR> ItemObjectParseable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Readable,
impl<VD, UR> ItemObjectParseable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Readable,
Source§impl<VD, UR> ItemValueEncodable for EmbeddedCert<VD, UR>where
Self: ItemObjectEncodable,
impl<VD, UR> ItemValueEncodable for EmbeddedCert<VD, UR>where
Self: ItemObjectEncodable,
Source§fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> Result<(), Bug>
fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> Result<(), Bug>
out Read moreSource§impl<VD, UR> ItemValueParseable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Readable,
impl<VD, UR> ItemValueParseable for EmbeddedCert<VD, UR>where
VD: EmbeddableCertObject<UR>,
UR: Readable,
Source§fn from_unparsed(item: UnparsedItem<'_>) -> Result<Self, P2EP>
fn from_unparsed(item: UnparsedItem<'_>) -> Result<Self, P2EP>
Source§impl<VD, UR> Writeable for EmbeddedCert<VD, UR>where
UR: Writeable,
impl<VD, UR> Writeable for EmbeddedCert<VD, UR>where
UR: Writeable,
Source§fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) -> Result<(), EncodeError>
fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) -> Result<(), EncodeError>
b.Auto Trait Implementations§
impl<VD, UR> Freeze for EmbeddedCert<VD, UR>
impl<VD, UR> RefUnwindSafe for EmbeddedCert<VD, UR>where
UR: RefUnwindSafe,
VD: RefUnwindSafe,
impl<VD, UR> Send for EmbeddedCert<VD, UR>
impl<VD, UR> Sync for EmbeddedCert<VD, UR>
impl<VD, UR> Unpin for EmbeddedCert<VD, UR>
impl<VD, UR> UnsafeUnpin for EmbeddedCert<VD, UR>where
UR: UnsafeUnpin,
VD: UnsafeUnpin,
impl<VD, UR> UnwindSafe for EmbeddedCert<VD, UR>where
UR: UnwindSafe,
VD: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 moreSource§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<W> WriteableOnce for Wwhere
W: Writeable,
impl<W> WriteableOnce for Wwhere
W: Writeable,
Source§fn write_into<B>(self, b: &mut B) -> Result<(), EncodeError>
fn write_into<B>(self, b: &mut B) -> Result<(), EncodeError>
b, and consume it.