pub struct RouterSigEd25519(pub Signature);Expand description
SHA-256 router descriptor signature including magic and the keyword.
Tuple Fields§
§0: SignatureImplementations§
Source§impl RouterSigEd25519
impl RouterSigEd25519
Sourceconst HASH_PREFIX_MAGIC: &str = "Tor router descriptor signature v1"
const HASH_PREFIX_MAGIC: &str = "Tor router descriptor signature v1"
The magic prefix for hashing this type of signature.
Sourcefn hash(document_sofar: &str, signature_item_kw_spc: &[&str]) -> [u8; 32]
fn hash(document_sofar: &str, signature_item_kw_spc: &[&str]) -> [u8; 32]
Calculate the hash for signature
signature_item_kw_spc is the keyword with a trailing space.
It’s &[&str] for the convenience of the two call sites.
Sourcepub fn new_sign_netdoc(
private_key: &Keypair,
encoder: &NetdocEncoder,
item_keyword: &str,
) -> StdResult<Self, Bug>
pub fn new_sign_netdoc( private_key: &Keypair, encoder: &NetdocEncoder, item_keyword: &str, ) -> StdResult<Self, Bug>
Make a signature during document encoding
item_keyword is the keyword for the signature item.
§Example
use derive_deftly::Deftly;
use tor_error::Bug;
use tor_llcrypto::pk::ed25519;
use tor_netdoc::derive_deftly_template_NetdocEncodable;
use tor_netdoc::encode::{NetdocEncodable, NetdocEncoder};
use tor_netdoc::types::routerdesc::RouterSigEd25519;
#[derive(Deftly, Default)]
#[derive_deftly(NetdocEncodable)]
pub struct Document {
pub document_intro_keyword: (),
}
#[derive(Deftly)]
#[derive_deftly(NetdocEncodable)]
pub struct DocumentSignatures {
pub document_signature: RouterSigEd25519,
}
impl Document {
pub fn encode_sign(&self, k: &ed25519::Keypair) -> Result<String, Bug> {
let mut encoder = NetdocEncoder::new();
self.encode_unsigned(&mut encoder)?;
let document_signature =
RouterSigEd25519::new_sign_netdoc(k, &encoder, "document-signature")?;
let sigs = DocumentSignatures { document_signature };
sigs.encode_unsigned(&mut encoder)?;
let encoded = encoder.finish()?;
Ok(encoded)
}
}
let k = ed25519::Keypair::generate(&mut tor_basic_utils::test_rng::testing_rng());
let doc = Document::default();
let encoded = doc.encode_sign(&k)?;
assert!(encoded.starts_with(concat!(
"document-intro-keyword\n",
"document-signature ",
)));Trait Implementations§
Source§impl Clone for RouterSigEd25519
impl Clone for RouterSigEd25519
Source§fn clone(&self) -> RouterSigEd25519
fn clone(&self) -> RouterSigEd25519
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RouterSigEd25519
impl Debug for RouterSigEd25519
Source§impl ItemValueEncodable for RouterSigEd25519
impl ItemValueEncodable for RouterSigEd25519
Source§fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> Result<(), Bug>
fn write_item_value_onto(&self, out: ItemEncoder<'_>) -> Result<(), Bug>
Write the item’s arguments, and any object, onto
out Read moreSource§impl PartialEq for RouterSigEd25519
impl PartialEq for RouterSigEd25519
Source§fn eq(&self, other: &RouterSigEd25519) -> bool
fn eq(&self, other: &RouterSigEd25519) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl SignatureItemParseable for RouterSigEd25519
impl SignatureItemParseable for RouterSigEd25519
Source§type HashAccu = RouterHashAccu
type HashAccu = RouterHashAccu
The Rust type of the hash value accumulator for this item. Read more
Source§fn from_unparsed_and_body(
item: UnparsedItem<'_>,
hash_inputs: &SignatureHashInputs<'_>,
hash: &mut Self::HashAccu,
) -> Result<Self, EP>
fn from_unparsed_and_body( item: UnparsedItem<'_>, hash_inputs: &SignatureHashInputs<'_>, hash: &mut Self::HashAccu, ) -> Result<Self, EP>
Parse the item’s value, and also calculate the relevant document hash Read more
impl Eq for RouterSigEd25519
impl StructuralPartialEq for RouterSigEd25519
Auto Trait Implementations§
impl Freeze for RouterSigEd25519
impl RefUnwindSafe for RouterSigEd25519
impl Send for RouterSigEd25519
impl Sync for RouterSigEd25519
impl Unpin for RouterSigEd25519
impl UnsafeUnpin for RouterSigEd25519
impl UnwindSafe for RouterSigEd25519
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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)
Converts
&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)
Converts
&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<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
Compare self to
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>
Converts
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>
Converts
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