Skip to content

Commit

Permalink
Ugly responde with same protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
neacsu committed Nov 16, 2024
1 parent 6298b82 commit ee5b52d
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 81 deletions.
3 changes: 3 additions & 0 deletions common/authenticator-requests/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ pub enum Error {

#[error("conversion: {0}")]
Conversion(String),

#[error("failed to serialize response packet: {source}")]
FailedToSerializeResponsePacket { source: Box<bincode::ErrorKind> },
}
24 changes: 24 additions & 0 deletions common/authenticator-requests/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ use nym_wireguard_types::PeerPublicKey;

use crate::{v1, v2, v3, Error};

#[derive(Copy, Clone, Debug)]
pub enum AuthenticatorVersion {
V1,
V2,
V3,
UNKNOWN,
}

impl From<Protocol> for AuthenticatorVersion {
fn from(value: Protocol) -> Self {
if value.service_provider_type != ServiceProviderType::Authenticator {
AuthenticatorVersion::UNKNOWN
} else if value.version == v1::VERSION {
AuthenticatorVersion::V1
} else if value.version == v2::VERSION {
AuthenticatorVersion::V2
} else if value.version == v3::VERSION {
AuthenticatorVersion::V3
} else {
AuthenticatorVersion::UNKNOWN
}
}
}

pub trait InitMessage {
fn pub_key(&self) -> PeerPublicKey;
}
Expand Down
2 changes: 1 addition & 1 deletion common/service-provider-requests-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[repr(u8)]
pub enum ServiceProviderType {
NetworkRequester = 0,
Expand Down
3 changes: 3 additions & 0 deletions service-providers/authenticator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ pub enum AuthenticatorError {

#[error("storage should have the requested bandwidht entry")]
MissingClientBandwidthEntry,

#[error("unknown version number")]
UnknownVersion,
}

pub type Result<T> = std::result::Result<T, AuthenticatorError>;
Loading

0 comments on commit ee5b52d

Please sign in to comment.