Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename Tls to NativeTls for potential other TLS impls #9

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ names = { version = "0.14.0", default-features = false }

[[example]]
doc-scrape-examples = true
name = "tcp_sender"
path = "examples/tcp_sender.rs"
name = "broadcast_sender"
path = "examples/broadcast_sender.rs"

[[example]]
doc-scrape-examples = true
name = "tls_sender"
path = "examples/tls_sender.rs"
name = "native_tls_sender"
path = "examples/native_tls_sender.rs"
required-features = ["native-tls"]

[[example]]
doc-scrape-examples = true
name = "udp_sender"
path = "examples/udp_sender.rs"
name = "tcp_sender"
path = "examples/tcp_sender.rs"

[[example]]
doc-scrape-examples = true
name = "broadcast_sender"
path = "examples/broadcast_sender.rs"
name = "udp_sender"
path = "examples/udp_sender.rs"

[[example]]
doc-scrape-examples = true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Client library written in Rust to send messages to a Syslog server. Support impl
* RFC-5424 Formatter: [The Syslog Protocol](https://datatracker.ietf.org/doc/html/rfc5424)
* `UdpSender`: [RFC 5426 - Transmission of Syslog Messages over UDP](https://datatracker.ietf.org/doc/html/rfc5426)
* `TcpSender`: [RFC 6587 - Transmission of Syslog Messages over TCP](https://datatracker.ietf.org/doc/html/rfc6587)
* `TlsSender`: [RFC 5425 - Transport Layer Security (TLS) Transport Mapping for Syslog](https://datatracker.ietf.org/doc/html/rfc5425)
* `NativeTlsSender`: [RFC 5425 - Transport Layer Security (TLS) Transport Mapping for Syslog](https://datatracker.ietf.org/doc/html/rfc5425)
* This implementation is based on [`native-tls`](https://crates.io/crates/native-tls) and requires features `native-tls` turned on.
* (unix only) Unix domain socket sender (datagram or stream)

Expand Down
2 changes: 1 addition & 1 deletion examples/tls_sender.rs → examples/native_tls_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use fasyslog::Severity;

fn main() {
let mut sender = fasyslog::sender::tls_well_known("127.0.0.1").unwrap();
let mut sender = fasyslog::sender::native_tls_well_known("127.0.0.1").unwrap();
let mut generator = names::Generator::default();
for _ in 0..100 {
let name = generator.next().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! * [RFC-5424 Formatter]: [The Syslog Protocol](https://datatracker.ietf.org/doc/html/rfc5424)
//! * [`UdpSender`]: [RFC 5426 - Transmission of Syslog Messages over UDP](https://datatracker.ietf.org/doc/html/rfc5426)
//! * [`TcpSender`]: [RFC 6587 - Transmission of Syslog Messages over TCP](https://datatracker.ietf.org/doc/html/rfc6587)
//! * [`TlsSender`]: [RFC 5425 - Transport Layer Security (TLS) Transport Mapping for Syslog](https://datatracker.ietf.org/doc/html/rfc5425)
//! * [`NativeTlsSender`]: [RFC 5425 - Transport Layer Security (TLS) Transport Mapping for Syslog](https://datatracker.ietf.org/doc/html/rfc5425)
//! * This implementation is based on [`native-tls`](https://crates.io/crates/native-tls) and
//! requires features `native-tls` turned on.
//! * (unix only) Unix domain socket sender (datagram or stream)
Expand All @@ -33,7 +33,7 @@
//! [RFC-5424 Formatter]: format::RFC5424Formatter
//! [`UdpSender`]: sender::UdpSender
//! [`TcpSender`]: sender::TcpSender
//! [`TlsSender`]: sender::TlsSender
//! [`NativeTlsSender`]: sender::NativeTlsSender
//!
//! # Example
//!
Expand Down
12 changes: 7 additions & 5 deletions src/sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum SyslogSender {
Tcp(TcpSender),
Udp(UdpSender),
#[cfg(feature = "native-tls")]
Tls(TlsSender),
NativeTlsSender(NativeTlsSender),
#[cfg(unix)]
UnixDatagram(UnixDatagramSender),
#[cfg(unix)]
Expand All @@ -62,7 +62,7 @@ impl SyslogSender {
SyslogSender::Tcp(sender) => sender.send_rfc3164(severity, message),
SyslogSender::Udp(sender) => sender.send_rfc3164(severity, message),
#[cfg(feature = "native-tls")]
SyslogSender::Tls(sender) => sender.send_rfc3164(severity, message),
SyslogSender::NativeTlsSender(sender) => sender.send_rfc3164(severity, message),
#[cfg(unix)]
SyslogSender::UnixDatagram(sender) => sender.send_rfc3164(severity, message),
#[cfg(unix)]
Expand All @@ -82,7 +82,9 @@ impl SyslogSender {
SyslogSender::Tcp(sender) => sender.send_rfc5424(severity, msgid, elements, message),
SyslogSender::Udp(sender) => sender.send_rfc5424(severity, msgid, elements, message),
#[cfg(feature = "native-tls")]
SyslogSender::Tls(sender) => sender.send_rfc5424(severity, msgid, elements, message),
SyslogSender::NativeTlsSender(sender) => {
sender.send_rfc5424(severity, msgid, elements, message)
}
#[cfg(unix)]
SyslogSender::UnixDatagram(sender) => {
sender.send_rfc5424(severity, msgid, elements, message)
Expand All @@ -100,7 +102,7 @@ impl SyslogSender {
SyslogSender::Tcp(sender) => sender.send_formatted(formatted),
SyslogSender::Udp(sender) => sender.send_formatted(formatted),
#[cfg(feature = "native-tls")]
SyslogSender::Tls(sender) => sender.send_formatted(formatted),
SyslogSender::NativeTlsSender(sender) => sender.send_formatted(formatted),
#[cfg(unix)]
SyslogSender::UnixDatagram(sender) => sender.send_formatted(formatted),
#[cfg(unix)]
Expand All @@ -122,7 +124,7 @@ impl SyslogSender {
SyslogSender::Tcp(sender) => sender.flush(),
SyslogSender::Udp(_) => Ok(()),
#[cfg(feature = "native-tls")]
SyslogSender::Tls(sender) => sender.flush(),
SyslogSender::NativeTlsSender(sender) => sender.flush(),
#[cfg(unix)]
SyslogSender::UnixDatagram(_) => Ok(()),
#[cfg(unix)]
Expand Down
28 changes: 16 additions & 12 deletions src/sender/native_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,40 @@ use crate::sender::internal::impl_syslog_stream_send_formatted;
/// See also [RFC-5425] §4.1 Port Assignment.
///
/// [RFC-5425]: https://datatracker.ietf.org/doc/html/rfc5425#section-4.1
pub fn tls_well_known<S: AsRef<str>>(domain: S) -> io::Result<TlsSender> {
pub fn native_tls_well_known<S: AsRef<str>>(domain: S) -> io::Result<NativeTlsSender> {
let domain = domain.as_ref();
tls(format!("{domain}:6514"), domain)
native_tls(format!("{domain}:6514"), domain)
}

/// Create a TLS sender that sends messages to the given address.
pub fn tls<A: ToSocketAddrs, S: AsRef<str>>(addr: A, domain: S) -> io::Result<TlsSender> {
tls_with(addr, domain, TlsConnector::builder())
pub fn native_tls<A: ToSocketAddrs, S: AsRef<str>>(
addr: A,
domain: S,
) -> io::Result<NativeTlsSender> {
native_tls_with(addr, domain, TlsConnector::builder())
}

/// Create a TLS sender that sends messages to the given address with certificate builder.
pub fn tls_with<A: ToSocketAddrs, S: AsRef<str>>(
pub fn native_tls_with<A: ToSocketAddrs, S: AsRef<str>>(
addr: A,
domain: S,
builder: TlsConnectorBuilder,
) -> io::Result<TlsSender> {
TlsSender::connect(addr, domain, builder)
) -> io::Result<NativeTlsSender> {
NativeTlsSender::connect(addr, domain, builder)
}

/// A syslog sender that sends messages to a TCP socket over TLS.
///
/// Users can obtain a `TlsSender` by calling [`tls_well_known`], [`tls`], or [`tls_with`].
/// Users can obtain a `TlsSender` by calling [`native_tls_well_known`], [`native_tls`], or
/// [`native_tls_with`].
#[derive(Debug)]
pub struct TlsSender {
pub struct NativeTlsSender {
writer: BufWriter<TlsStream<TcpStream>>,
context: SyslogContext,
postfix: Cow<'static, str>,
}

impl TlsSender {
impl NativeTlsSender {
/// Connect to a TCP socket over TLS at the given address.
pub fn connect<A: ToSocketAddrs, S: AsRef<str>>(
addr: A,
Expand Down Expand Up @@ -100,5 +104,5 @@ impl TlsSender {
}
}

impl_syslog_sender_common!(TlsSender);
impl_syslog_stream_send_formatted!(TlsSender);
impl_syslog_sender_common!(NativeTlsSender);
impl_syslog_stream_send_formatted!(NativeTlsSender);