Skip to content

Commit

Permalink
Add warnings about multiple calls to same method in Builder
Browse files Browse the repository at this point in the history
Since multiple calls to the same method in Builder is not disallowed,
there is a risk of misuse if values are accidentally overwritten.

In later versions of snow, this will not be allowed full-stop, but in
the mean time we'll add a warning here to remain API-compatible.
  • Loading branch information
mcginty committed Jan 26, 2024
1 parent f280991 commit 308a24d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ impl<'builder> Builder<'builder> {
}

/// Specify a PSK (only used with `NoisePSK` base parameter)
///
/// # Safety
/// This will overwrite the value provided in any previous call to this method. Please take care
/// to ensure this is not a security risk. In future versions, multiple calls to the same
/// builder method will be explicitly prohibited.
pub fn psk(mut self, location: u8, key: &'builder [u8]) -> Self {
self.psks[location as usize] = Some(key);
self
}

/// Your static private key (can be generated with [`generate_keypair()`]).
///
/// # Safety
/// This will overwrite the value provided in any previous call to this method. Please take care
/// to ensure this is not a security risk. In future versions, multiple calls to the same
/// builder method will be explicitly prohibited.
///
/// [`generate_keypair()`]: #method.generate_keypair
pub fn local_private_key(mut self, key: &'builder [u8]) -> Self {
self.s = Some(key);
Expand All @@ -117,12 +127,22 @@ impl<'builder> Builder<'builder> {
}

/// Arbitrary data to be hashed in to the handshake hash value.
///
/// # Safety
/// This will overwrite the value provided in any previous call to this method. Please take care
/// to ensure this is not a security risk. In future versions, multiple calls to the same
/// builder method will be explicitly prohibited.
pub fn prologue(mut self, key: &'builder [u8]) -> Self {
self.plog = Some(key);
self
}

/// The responder's static public key.
///
/// # Safety
/// This will overwrite the value provided in any previous call to this method. Please take care
/// to ensure this is not a security risk. In future versions, multiple calls to the same
/// builder method will be explicitly prohibited.
pub fn remote_public_key(mut self, pub_key: &'builder [u8]) -> Self {
self.rs = Some(pub_key);
self
Expand Down

0 comments on commit 308a24d

Please sign in to comment.