make id field in RSAIdentity private

This commit is contained in:
Nick Mathewson 2020-05-08 11:21:10 -04:00
parent b48597fb18
commit 75a1269429
3 changed files with 8 additions and 9 deletions

View File

@ -191,20 +191,17 @@ mod curve25519_impls {
/// Implement readable and writeable for the the RSAIdentity type.
mod rsa_impls {
use super::*;
use std::convert::TryInto;
use tor_llcrypto::pk::rsa::*;
impl Writeable for RSAIdentity {
fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) {
b.write_all(&self.id[..])
b.write_all(self.as_bytes())
}
}
impl Readable for RSAIdentity {
fn take_from(b: &mut Reader<'_>) -> Result<Self> {
let m = b.take(RSA_ID_LEN)?;
Ok(RSAIdentity {
id: m.try_into().expect("take is broken"),
})
Ok(RSAIdentity::from_bytes(m).expect("take gave wrong length"))
}
}
}

View File

@ -21,7 +21,7 @@ pub const RSA_ID_LEN: usize = 20;
/// identity key. These are used all over the Tor protocol.
#[derive(Clone, Zeroize, Debug)]
pub struct RSAIdentity {
pub id: [u8; RSA_ID_LEN],
id: [u8; RSA_ID_LEN],
}
impl PartialEq<RSAIdentity> for RSAIdentity {
@ -42,8 +42,10 @@ impl RSAIdentity {
/// Returns None if the input is not of the correct length.
///
/// ```
/// use tor_llcrypto::pk::rsa::RSAIdentity;
///
/// let bytes = b"xyzzyxyzzyxyzzyxyzzy";
/// let id = RSAIdentity::from_bytes(&bytes);
/// let id = RSAIdentity::from_bytes(bytes);
/// assert_eq!(id.unwrap().as_bytes(), bytes);
///
/// let truncated = b"xyzzy";

View File

@ -223,7 +223,7 @@ mod tests {
let mut rng = rand_core::OsRng;
let relay_secret = StaticSecret::new(&mut rng);
let relay_public = PublicKey::from(&relay_secret);
let relay_identity = RSAIdentity { id: [12; 20] };
let relay_identity = RSAIdentity::from_bytes(&[12; 20]).unwrap();
let relay_ntpk = NtorPublicKey {
id: relay_identity,
pk: relay_public.clone(),
@ -296,7 +296,7 @@ mod tests {
let keys = hex!("0c62dee7f48893370d0ef896758d35729867beef1a5121df80e00f79ed349af39b51cae125719182f19d932a667dae1afbf2e336e6910e7822223e763afad0a13342157969dc6b79");
let relay_pk = NtorPublicKey {
id: RSAIdentity { id },
id: RSAIdentity::from_bytes(&id).unwrap(),
pk: b_pk.into(),
};
let relay_sk = NtorSecretKey {