Skip to content

Commit

Permalink
Create Party enum
Browse files Browse the repository at this point in the history
Introducing this enum as a replacement for ElligatorSwiftParty. Party is
more descriptive and should cause less confusion than
ElligatorSwiftParty
  • Loading branch information
shinghim committed Oct 16, 2024
1 parent 379e128 commit fef48bc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ellswift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pub enum ElligatorSwiftParty {
B,
}


impl ElligatorSwiftParty {
fn to_ffi_int(self) -> c_int {
match self {
Expand All @@ -307,6 +308,33 @@ impl ElligatorSwiftParty {
}
}

/// Represents the two parties in ECDH
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Party {
/// The party that starts the key exchange or communication process
Initiator,
/// The party that responds to the initiator's communications
Responder,
}

impl From<ElligatorSwiftParty> for Party {
fn from(value: ElligatorSwiftParty) -> Self {
match value {
ElligatorSwiftParty::A => Party::Initiator,
ElligatorSwiftParty::B => Party::Responder,
}
}
}

impl Party {
fn to_ffi_int(self) -> c_int {
match self {
Party::Initiator => 0,
Party::Responder => 1,
}
}
}

impl FromStr for ElligatorSwift {
fn from_str(hex: &str) -> Result<Self, Self::Err> {
let mut ser = [0u8; 64];
Expand Down

0 comments on commit fef48bc

Please sign in to comment.