Skip to content

Move protocol module to separate crate in workspace #6

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

Merged
merged 1 commit into from
Jul 25, 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
24 changes: 3 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
[package]
name = "tacacs-plus"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["std"]
std = ["byteorder/std", "num_enum/std", "md-5/std"]
docsrs = []

[dependencies]
bitflags = { version = "2.4.2" }
byteorder = { version = "1.5.0", default-features = false }
num_enum = { version = "0.7.2", default-features = false }
getset = { version = "0.1.2" }
md-5 = { version = "0.10.6", default-features = false }

[dev-dependencies]
tinyvec = { version = "1.6.1", features = ["rustc_1_57"] }
[workspace]
members = ["tacacs-plus-protocol"]
resolver = "2"
17 changes: 0 additions & 17 deletions src/lib.rs

This file was deleted.

20 changes: 20 additions & 0 deletions tacacs-plus-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "tacacs-plus-protocol"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["std"]
std = ["byteorder/std", "num_enum/std", "md-5/std"]

[dependencies]
bitflags = { version = "2.4.2" }
byteorder = { version = "1.5.0", default-features = false }
num_enum = { version = "0.7.2", default-features = false }
getset = { version = "0.1.2" }
md-5 = { version = "0.10.6", default-features = false }

[dev-dependencies]
tinyvec = { version = "1.6.1", features = ["rustc_1_57"] }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::ToOwned;
use std::string::String;

use super::{Reply, Status};
use crate::protocol::ToOwnedBody;
use crate::ToOwnedBody;

/// An owned version of a [`Reply`](super::Reply).
// TODO: stop ignoring dead_code lint when fields are actually used in client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::*;
use crate::protocol::packet::xor_body_with_pad;
use crate::protocol::{
use crate::packet::xor_body_with_pad;
use crate::FieldText;
use crate::{
Argument, AuthenticationContext, AuthenticationMethod, AuthenticationService,
AuthenticationType, HeaderInfo, MajorVersion, MinorVersion, Packet, PacketFlags,
PrivilegeLevel, UserInformation, Version,
};
use crate::FieldText;

use tinyvec::array_vec;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::ToOwned;
use std::string::String;
use std::vec::Vec;

use crate::protocol::ToOwnedBody;
use crate::ToOwnedBody;

use super::Reply;
use super::{ReplyFlags, Status};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::*;
use crate::protocol::{
use crate::FieldText;
use crate::{
AuthenticationContext, AuthenticationService, AuthenticationType, HeaderInfo, MajorVersion,
MinorVersion, Packet, PacketFlags, PrivilegeLevel, UserInformation, Version,
};
use crate::FieldText;

use tinyvec::array_vec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::vec::Vec;

use super::Reply;
use super::Status;
use crate::protocol::ArgumentOwned;
use crate::protocol::ToOwnedBody;
use crate::ArgumentOwned;
use crate::ToOwnedBody;

/// An authorization reply packet with owned fields.
// TODO: stop ignoring dead_code lint when fields are actually used
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::*;
use crate::protocol::packet::xor_body_with_pad;
use crate::protocol::{
use crate::packet::xor_body_with_pad;
use crate::FieldText;
use crate::{
Arguments, AuthenticationContext, AuthenticationMethod, AuthenticationService,
AuthenticationType, HeaderInfo, MajorVersion, MinorVersion, Packet, PacketFlags,
PrivilegeLevel, Serialize, UserInformation, Version,
};
use crate::FieldText;

use tinyvec::array_vec;

Expand Down Expand Up @@ -443,7 +443,7 @@ fn full_unobfuscated_reply_packet_to_owned() {
use std::string::String;
use std::vec;

use crate::protocol::ArgumentOwned;
use crate::ArgumentOwned;

let mut raw_packet = array_vec!([u8; 60] =>
// HEADER
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/fields.rs → tacacs-plus-protocol/src/fields.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::protocol::MinorVersion;
use crate::FieldText;
use crate::MinorVersion;

use super::SerializeError;

Expand Down Expand Up @@ -59,7 +59,7 @@ impl PrivilegeLevel {
///
/// # Examples
/// ```
/// use tacacs_plus::protocol::PrivilegeLevel;
/// use tacacs_plus_protocol::PrivilegeLevel;
///
/// let valid_level = PrivilegeLevel::new(3);
/// assert!(valid_level.is_some());
Expand Down
File renamed without changes.
16 changes: 15 additions & 1 deletion src/protocol.rs → tacacs-plus-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
//! TACACS+ protocol packet <-> binary format conversions.
//! # tacacs-plus-protocol
//!
//! Serialization & deserialization of (RFC8907) TACACS+ protocol packets.

#![no_std]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(clippy::cast_lossless)]
#![warn(clippy::cast_possible_truncation)]

#[cfg(feature = "std")]
extern crate std;

use core::{fmt, num::TryFromIntError};

Expand All @@ -19,6 +30,9 @@ pub use arguments::ArgumentOwned;
mod fields;
pub use fields::*;

mod text;
pub use text::FieldText;

/// An error that occurred when serializing a packet or any of its components into their binary format.
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use byteorder::{ByteOrder, NetworkEndian};
use getset::{CopyGetters, MutGetters};

use super::{PacketFlags, PacketType};
use crate::protocol::{DeserializeError, SerializeError, Version};
use crate::{DeserializeError, SerializeError, Version};

/// Information included in a TACACS+ packet header.
#[derive(PartialEq, Eq, Debug, Clone, CopyGetters, MutGetters)]
Expand All @@ -26,7 +26,7 @@ pub struct HeaderInfo {

impl HeaderInfo {
/// Size of a full TACACS+ packet header.
pub(in crate::protocol) const HEADER_SIZE_BYTES: usize = 12;
pub const HEADER_SIZE_BYTES: usize = 12;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be pub(in crate::protocol)

Suggested change
pub const HEADER_SIZE_BYTES: usize = 12;
pub(crate) const HEADER_SIZE_BYTES: usize = 12;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When working on the actual client, I ended up changing it to pub(crate) since I used it when reading a packet from a connection, which is why I made it fully pub here (since they will technically be different crates now). I'm fine leaving it as pub(crate) here but I'll likely change anyways once the initial client stuff is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can keep it as pub if you want, interested to see where this was needed in the client, seems more like a protocol matter


/// Bundles some information to be put in the header of a TACACS+ packet.
pub fn new(version: Version, sequence_number: u8, flags: PacketFlags, session_id: u32) -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

use crate::protocol::accounting::Reply;
use crate::protocol::{MajorVersion, MinorVersion, Version};
use crate::accounting::Reply;
use crate::{MajorVersion, MinorVersion, Version};

#[test]
fn obfuscated_packet_wrong_unencrypted_flag() {
Expand Down
4 changes: 2 additions & 2 deletions src/text.rs → tacacs-plus-protocol/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::fmt;
/// Conversions from `&str`:
///
/// ```
/// use tacacs_plus::FieldText;
/// use tacacs_plus_protocol::FieldText;
///
/// let valid_ascii = "a string";
/// assert!(FieldText::try_from(valid_ascii).is_ok());
Expand All @@ -25,7 +25,7 @@ use core::fmt;
/// Conversions from `&[u8]`:
///
/// ```
/// use tacacs_plus::FieldText;
/// use tacacs_plus_protocol::FieldText;
///
/// let valid_slice = b"this is (almost) a string";
/// assert!(FieldText::try_from(valid_slice.as_slice()).is_ok());
Expand Down