Skip to content

Commit

Permalink
refactor: Make SerialisableCertificate mod private
Browse files Browse the repository at this point in the history
This was only being used in `tests::quinn`, which can get what it needs
from `InternalConfig`.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent dfaaa53 commit 5de709e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
8 changes: 3 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl InternalConfig {
/// To be used to read and write our certificate and private key to disk esp. as a part of our
/// configuration file
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
pub(crate) struct SerialisableCertificate {
struct SerialisableCertificate {
/// DER encoded certificate
cert_der: Bytes,
/// DER encoded private key
Expand All @@ -159,7 +159,7 @@ pub(crate) struct SerialisableCertificate {

impl SerialisableCertificate {
/// Returns a new Certificate that is valid for the list of domain names provided
pub(crate) fn new(domains: impl Into<Vec<String>>) -> Result<Self> {
fn new(domains: impl Into<Vec<String>>) -> Result<Self> {
let cert = rcgen::generate_simple_self_signed(domains)?;
Ok(Self {
cert_der: cert.serialize_der()?.into(),
Expand All @@ -172,9 +172,7 @@ impl SerialisableCertificate {
/// # Errors
/// Returns [CertificateParseError](Error::CertificateParseError) if the inputs
/// cannot be parsed
pub(crate) fn obtain_priv_key_and_cert(
&self,
) -> Result<(quinn::PrivateKey, quinn::Certificate)> {
fn obtain_priv_key_and_cert(&self) -> Result<(quinn::PrivateKey, quinn::Certificate)> {
Ok((
quinn::PrivateKey::from_der(&self.key_der).map_err(|_| Error::CertificatePkParse)?,
quinn::Certificate::from_der(&self.cert_der).map_err(|_| Error::CertificateParse)?,
Expand Down
21 changes: 4 additions & 17 deletions src/tests/quinn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use std::net::SocketAddr;
use std::sync::Arc;

use super::{hash, random_msg};
use crate::{
api::bind,
config::{SerialisableCertificate, DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEP_ALIVE_INTERVAL},
peer_config,
};
use crate::{api::bind, config::InternalConfig};
use anyhow::Result;
use bytes::Bytes;
use futures::stream::FuturesUnordered;
Expand Down Expand Up @@ -66,18 +62,9 @@ struct Peer {
impl Peer {
// Takes the channel size. Set `0` to use an unbounded channel.
fn new(channel_size: usize) -> Result<(Self, ChannelReceiver<(SocketAddr, Bytes)>)> {
let (key, cert) = {
let our_complete_cert = SerialisableCertificate::new(vec![DOMAIN.to_string()])?;
our_complete_cert.obtain_priv_key_and_cert()?
};

let endpoint_cfg =
peer_config::new_our_cfg(DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEP_ALIVE_INTERVAL, cert, key)?;

let client_cfg =
peer_config::new_client_cfg(DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEP_ALIVE_INTERVAL)?;
let config = InternalConfig::try_from_config(Default::default())?;

let (endpoint, mut incoming) = bind(endpoint_cfg, "127.0.0.1:0".parse()?)?;
let (endpoint, mut incoming) = bind(config.server, "127.0.0.1:0".parse()?)?;

let (message_tx, message_rx) = if channel_size == 0 {
let (message_tx, message_rx) = unbounded_channel();
Expand Down Expand Up @@ -127,7 +114,7 @@ impl Peer {
Ok((
Peer {
endpoint,
client_cfg,
client_cfg: config.client,
message_tx,
connections,
},
Expand Down

0 comments on commit 5de709e

Please sign in to comment.