Skip to content

Commit 308a24d

Browse files
committed
Add warnings about multiple calls to same method in Builder
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.
1 parent f280991 commit 308a24d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,23 @@ impl<'builder> Builder<'builder> {
9797
}
9898

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

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

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

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

0 commit comments

Comments
 (0)