#[non_exhaustive]pub struct RsaSha1Signature {
pub signature: Vec<u8>,
}Expand description
RSA signature using SHA-1 as per “Signing documents” in dir-spec
https://spec.torproject.org/dir-spec/netdoc.html#signing
Used for
AuthCert::dir-key-certification,
for example.
§Caveats
This type MUST NOT be used for anomalous signatures
such as
AuthCert::dir_key_crosscert;
in that case because dir_key_crosscert’s
set of allowed object labels includes ID SIGNATURE whereas this type
is always SIGNATURE
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.signature: Vec<u8>The bytes of the signature (base64-decoded).
Implementations§
Source§impl RsaSha1Signature
impl RsaSha1Signature
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 according to “Signing documents” in the netdoc spec
https://spec.torproject.org/dir-spec/netdoc.html#signing
NetdocEncoder should have had the body of the document
(everything except the signatures) already encoded.
item_keyword is the keyword for the signature item.
This is needed because different documents use different keywords,
and the keyword is covered by the signature (an annoying is a layering violation).
See https://gitlab.torproject.org/tpo/core/torspec/-/issues/322.
§Example
use derive_deftly::Deftly;
use tor_error::Bug;
use tor_llcrypto::pk::rsa;
use tor_netdoc::derive_deftly_template_NetdocEncodable;
use tor_netdoc::encode::{NetdocEncodable, NetdocEncoder};
use tor_netdoc::types::RsaSha1Signature;
#[derive(Deftly, Default)]
#[derive_deftly(NetdocEncodable)]
pub struct Document {
pub document_intro_keyword: (),
}
#[derive(Deftly)]
#[derive_deftly(NetdocEncodable)]
pub struct DocumentSignatures {
pub document_signature: RsaSha1Signature,
}
impl Document {
pub fn encode_sign(&self, k: &rsa::KeyPair) -> Result<String, Bug> {
let mut encoder = NetdocEncoder::new();
self.encode_unsigned(&mut encoder)?;
let document_signature =
RsaSha1Signature::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 = rsa::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\n",
"-----BEGIN SIGNATURE-----\n",
)));Trait Implementations§
Source§impl Clone for RsaSha1Signature
impl Clone for RsaSha1Signature
Source§fn clone(&self) -> RsaSha1Signature
fn clone(&self) -> RsaSha1Signature
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RsaSha1Signature
impl Debug for RsaSha1Signature
Source§impl ItemValueEncodable for RsaSha1Signature
impl ItemValueEncodable for RsaSha1Signature
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 PartialEq for RsaSha1Signature
impl PartialEq for RsaSha1Signature
Source§fn eq(&self, other: &RsaSha1Signature) -> bool
fn eq(&self, other: &RsaSha1Signature) -> bool
self and other values to be equal, and is used by ==.Source§impl SignatureItemParseable for RsaSha1Signature
impl SignatureItemParseable for RsaSha1Signature
Source§type HashAccu = Sha1WholeKeywordLine
type HashAccu = Sha1WholeKeywordLine
Source§fn from_unparsed_and_body<'s>(
input: UnparsedItem<'s>,
document_body: &SignatureHashInputs<'_>,
hash_accu: &mut Sha1WholeKeywordLine,
) -> Result<Self, EP>
fn from_unparsed_and_body<'s>( input: UnparsedItem<'s>, document_body: &SignatureHashInputs<'_>, hash_accu: &mut Sha1WholeKeywordLine, ) -> Result<Self, EP>
impl Eq for RsaSha1Signature
impl StructuralPartialEq for RsaSha1Signature
Auto Trait Implementations§
impl Freeze for RsaSha1Signature
impl RefUnwindSafe for RsaSha1Signature
impl Send for RsaSha1Signature
impl Sync for RsaSha1Signature
impl Unpin for RsaSha1Signature
impl UnsafeUnpin for RsaSha1Signature
impl UnwindSafe for RsaSha1Signature
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<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