sftp-protocol 0.1.0

A pure Rust implementation of the SFTP protocol
Documentation
#[derive(thiserror::Error, Debug)]
pub enum Error {
	#[error("error decoding packet header")]
	PacketHeader,
	#[error("no header")]
	NoHeader,
	#[error("error decoding packet")]
	Packet(String),
	#[error("invalid path")]
	InvalidPath,
	#[error("I/O failure")]
	IO(#[from] std::io::Error),
}

impl From<nom::Err<nom::error::Error<&[u8]>>> for Error {
	fn from(inner: nom::Err<nom::error::Error<&[u8]>>) -> Self {
		Self::Packet(inner.to_string())
	}
}

#[cfg(test)]
impl PartialEq for Error {
	fn eq(&self, other: &Self) -> bool {
		match (self, other) {
			(Self::PacketHeader, Self::PacketHeader) => true,
			(Self::NoHeader, Self::NoHeader) => true,
			(Self::Packet(l), Self::Packet(r)) => l == r,
			(Self::InvalidPath, Self::InvalidPath) => true,
			(Self::IO(_), Self::IO(_)) => true,
			(_, _) => false
		}
	}
}