Debian Codegraph @

src/authentication/sasl.rs

raw symbols SCIP
1 //! SASL-based authentication support.
2
3 use base64rust-analyzer cargo base64 0.22.1 crate/::Enginerust-analyzer cargo base64 0.22.1 engine/Engine#;
4 use base64rust-analyzer cargo base64 0.22.1 crate/::displayrust-analyzer cargo base64 0.22.1 display/::Base64Displayrust-analyzer cargo base64 0.22.1 display/Base64Display#;
5 use base64rust-analyzer cargo base64 0.22.1 crate/::enginerust-analyzer cargo base64 0.22.1 engine/::general_purposerust-analyzer cargo base64 0.22.1 engine/general_purpose/::STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD.;
6 use hmacrust-analyzer cargo hmac 0.13.0 crate/::{Hmacrust-analyzer cargo hmac 0.13.0 Hmac#, KeyInitrust-analyzer cargo crypto-common 0.2.2 KeyInit#, Macrust-analyzer cargo digest 0.11.3 mac/Mac#};
7 use randrust-analyzer cargo rand 0.10.1 crate/::{selfrust-analyzer cargo rand 0.10.1 crate/, RngExtrust-analyzer cargo rand 0.10.1 rng/RngExt#};
8 use sha2rust-analyzer cargo sha2 0.11.0 crate/::digestrust-analyzer cargo digest 0.11.3 crate/::FixedOutputrust-analyzer cargo digest 0.11.3 FixedOutput#;
9 use sha2rust-analyzer cargo sha2 0.11.0 crate/::{Digestrust-analyzer cargo digest 0.11.3 digest/Digest#, Sha256rust-analyzer cargo sha2 0.11.0 Sha256#};
10 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
12 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/;
13 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
14 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/;
15
16 const NONCE_LENGTHrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/NONCE_LENGTH.: usize = 24;
17
18 /// The maximum SCRAM iteration count the client will accept from the server.
19 ///
20 /// The iteration count is sent by the server and drives a PBKDF2 loop, so an
21 /// unbounded value lets a malicious or impersonating server force the client to
22 /// perform an arbitrary number of HMAC operations before authentication even
23 /// completes (a denial of service). 100_000 is ~24x the PostgreSQL default of
24 /// 4096 and matches the default cap the PostgreSQL JDBC driver (pgjdbc) adopted
25 /// for the same issue (CVE-2026-42198).
26 const MAX_ITERATION_COUNTrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/MAX_ITERATION_COUNT.: u32 = 100_000;
27
28 /// The identifier of the SCRAM-SHA-256 SASL authentication mechanism.
29 pub const SCRAM_SHA_256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/SCRAM_SHA_256.: &str = "SCRAM-SHA-256";
30 /// The identifier of the SCRAM-SHA-256-PLUS SASL authentication mechanism.
31 pub const SCRAM_SHA_256_PLUSrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/SCRAM_SHA_256_PLUS.: &str = "SCRAM-SHA-256-PLUS";
32
33 // since postgres passwords are not required to exclude saslprep-prohibited
34 // characters or even be valid UTF8, we run saslprep if possible and otherwise
35 // return the raw password.
36 fn normalizerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/normalize().(pass: &[u8]) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> {
37 let pass = match strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(pass) {
38 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pass) => pass,
39 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => return pass.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(),
40 };
41
42 match stringpreprust-analyzer cargo stringprep 0.1.5 crate/::saslpreprust-analyzer cargo stringprep 0.1.5 saslprep().(pass) {
43 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pass) => pass.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().().into_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_bytes().(),
44 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => pass.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(),
45 }
46 }
47
48 pub(craterust-analyzer cargo postgres-protocol 0.6.12 crate/) fn hirust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/hi().(str: &[u8], salt: &[u8], i: u32) -> [u8; 32] {
49 let mut hmac =
50 Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(str).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("HMAC is able to accept all key sizes");
51 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(salt);
52 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(&[0, 0, 0, 1]);
53 let mut prev = hmac.finalizerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.11.3 mac/impl#[`CtOutput<T>`]into_bytes().();
54
55 let mut hi = prev;
56
57 for _ in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i {
58 let mut hmac = Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(str).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("already checked above");
59 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(&prev);
60 prev = hmac.finalizerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.11.3 mac/impl#[`CtOutput<T>`]into_bytes().();
61
62 for (hi, prev) in hi.iter_mutrust-analyzer cargo hybrid-array 0.4.12 impl#[`Array<T, U>`]iter_mut().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(prev) {
63 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().hi rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign().^=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign().prev;
64 }
65 }
66
67 hi.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
68 }
69
70 enum ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner# {
71 Unrequestedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unrequested#,
72 Unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unsupported#,
73 TlsServerEndPointrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#TlsServerEndPoint#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>),
74 }
75
76 /// The channel binding configuration for a SCRAM authentication exchange.
77 pub struct ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#(ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#);
78
79 impl ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding# {
80 /// The server did not request channel binding.
81 pub fn unrequestedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]unrequested().() -> ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding# {
82 ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#(ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unrequestedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unrequested#)
83 }
84
85 /// The server requested channel binding but the client is unable to provide it.
86 pub fn unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]unsupported().() -> ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding# {
87 ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#(ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unsupported#)
88 }
89
90 /// The server requested channel binding and the client will use the `tls-server-end-point`
91 /// method.
92 pub fn tls_server_end_pointrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]tls_server_end_point().(signature: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding# {
93 ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#(ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::TlsServerEndPointrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#TlsServerEndPoint#(signature))
94 }
95
96 fn gs2_headerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]gs2_header().(&self) -> &'static str {
97 match self.0rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#0. {
98 ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unrequestedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unrequested# => "y,,",
99 ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unsupported# => "n,,",
100 ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::TlsServerEndPointrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#TlsServerEndPoint#(_) => "p=tls-server-end-point,,",
101 }
102 }
103
104 fn cbind_datarust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]cbind_data().(&self) -> &[u8] {
105 match self.0rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#0. {
106 ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unrequestedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unrequested# | ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::Unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#Unsupported# => &[],
107 ChannelBindingInnerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#::TlsServerEndPointrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBindingInner#TlsServerEndPoint#(ref buf) => buf,
108 }
109 }
110 }
111
112 enum Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State# {
113 Updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update# {
114 noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#nonce.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
115 passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#password.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>,
116 channel_bindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#channel_binding.: ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#,
117 },
118 Finishrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish# {
119 salted_passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#salted_password.: [u8; 32],
120 auth_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#auth_message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
121 },
122 Donerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Done#,
123 }
124
125 /// A type which handles the client side of the SCRAM-SHA-256/SCRAM-SHA-256-PLUS authentication
126 /// process.
127 ///
128 /// During the authentication process, if the backend sends an `AuthenticationSASL` message which
129 /// includes `SCRAM-SHA-256` as an authentication mechanism, this type can be used.
130 ///
131 /// After a `ScramSha256` is constructed, the buffer returned by the `message()` method should be
132 /// sent to the backend in a `SASLInitialResponse` message along with the mechanism name.
133 ///
134 /// The server will reply with an `AuthenticationSASLContinue` message. Its contents should be
135 /// passed to the `update()` method, after which the buffer returned by the `message()` method
136 /// should be sent to the backend in a `SASLResponse` message.
137 ///
138 /// The server will reply with an `AuthenticationSASLFinal` message. Its contents should be passed
139 /// to the `finish()` method, after which the authentication process is complete.
140 pub struct ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256# {
141 messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
142 staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state.: Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#,
143 }
144
145 impl ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256# {
146 /// Constructs a new instance which will use the provided password for authentication.
147 pub fn newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]new().(password: &[u8], channel_binding: ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#) -> ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256# {
148 // rand 0.5's ThreadRng is cryptographically secure
149 let mut rng = randrust-analyzer cargo rand 0.10.1 crate/::rngrust-analyzer cargo rand 0.10.1 rngs/thread/rng().();
150 let nonce = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#NONCE_LENGTHrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/NONCE_LENGTH.)
151 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| {
152 let mut v = rng.random_rangerust-analyzer cargo rand 0.10.1 rng/RngExt#random_range().(0x21u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0x7e);
153 if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0x2c {
154 v = 0x7e
155 }
156 v as char
157 })
158 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>();
159
160 ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#::new_innerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]new_inner().(password, channel_binding, nonce)
161 }
162
163 fn new_innerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]new_inner().(password: &[u8], channel_binding: ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#, nonce: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256# {
164 ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256# {
165 messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}n=,r={}", channel_binding.gs2_headerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]gs2_header().(), nonce),
166 staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state.: Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update# {
167 noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#nonce.,
168 passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#password.: normalizerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/normalize().(password),
169 channel_bindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#channel_binding.,
170 },
171 }
172 }
173
174 /// Returns the message which should be sent to the backend in an `SASLResponse` message.
175 pub fn messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]message().(&self) -> &[u8] {
176 if let Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Donerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Done# = self.staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state. {
177 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("invalid SCRAM state");
178 }
179 self.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message..as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()
180 }
181
182 /// Updates the state machine with the response from the backend.
183 ///
184 /// This should be called when an `AuthenticationSASLContinue` message is received.
185 pub fn updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]update().(&mut self, message: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
186 let (client_nonce, password, channel_binding) =
187 match memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state., Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Donerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Done#) {
188 Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update# {
189 noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#nonce.,
190 passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#password.,
191 channel_bindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Update#channel_binding.,
192 } => (nonce, password, channel_binding),
193 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().("invalid SCRAM state")),
194 };
195
196 let message =
197 strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(message).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
198
199 let parsed = Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#::newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(message).server_first_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_first_message().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
200
201 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed.noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#nonce..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(&client_nonce) {
202 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, "invalid nonce"));
203 }
204
205 if parsed.iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#iteration_count. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().MAX_ITERATION_COUNTrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/MAX_ITERATION_COUNT. {
206 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
207 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#,
208 "SCRAM iteration count exceeds the maximum allowed",
209 ));
210 }
211
212 let salt = match STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD..decoderust-analyzer cargo base64 0.22.1 engine/Engine#decode().(parsed.saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#salt.) {
213 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(salt) => salt,
214 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, e)),
215 };
216
217 let salted_password = hirust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/hi().(&password, &salt, parsed.iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#iteration_count.);
218
219 let mut hmac = Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(&salted_password)
220 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("HMAC is able to accept all key sizes");
221 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(b"Client Key");
222 let client_key = hmac.finalizerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.11.3 mac/impl#[`CtOutput<T>`]into_bytes().();
223
224 let mut hash = Sha256rust-analyzer cargo sha2 0.11.0 Sha256#::defaultrust-analyzer cargo sha2 0.11.0 impl#[Sha256][Default]default().();
225 hash.updaterust-analyzer cargo digest 0.11.3 digest/impl#[D][Digest]update().(client_key);
226 let stored_key = hash.finalize_fixedrust-analyzer cargo digest 0.11.3 FixedOutput#finalize_fixed().();
227
228 let mut cbind_input = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
229 cbind_input.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(channel_binding.gs2_headerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]gs2_header().().as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
230 cbind_input.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(channel_binding.cbind_datarust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]cbind_data().());
231 let cbind_input = STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD..encoderust-analyzer cargo base64 0.22.1 engine/Engine#encode().(&cbind_input);
232
233 self.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
234 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut self.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message., "c={},r={}", cbind_input, parsed.noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#nonce.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
235
236 let auth_message = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("n=,r={},{},{}", client_nonce, message, self.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message.);
237
238 let mut hmac = Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(&stored_key)
239 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("HMAC is able to accept all key sizes");
240 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(auth_message.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().());
241 let client_signature = hmac.finalizerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.11.3 mac/impl#[`CtOutput<T>`]into_bytes().();
242
243 let mut client_proof = client_key;
244 for (proof, signature) in client_proof.iter_mutrust-analyzer cargo hybrid-array 0.4.12 impl#[`Array<T, U>`]iter_mut().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(client_signature) {
245 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().proof rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign().^=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitXorAssign<Self>`]bitxor_assign().signature;
246 }
247
248 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
249 &mut self.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#message.,
250 ",p={}",
251 Base64Displayrust-analyzer cargo base64 0.22.1 display/Base64Display#::newrust-analyzer cargo base64 0.22.1 display/impl#[`Base64Display<'a, 'e, E>`]new().(&client_proof, &STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD.)
252 )
253 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
254
255 self.staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state. = Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Finishrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish# {
256 salted_passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#salted_password.,
257 auth_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#auth_message.,
258 };
259 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
260 }
261
262 /// Finalizes the authentication process.
263 ///
264 /// This should be called when the backend sends an `AuthenticationSASLFinal` message.
265 /// Authentication has only succeeded if this method returns `Ok(())`.
266 pub fn finishrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]finish().(&mut self, message: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
267 let (salted_password, auth_message) = match memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(&mut self.staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#state., Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Donerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Done#) {
268 Staterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#::Finishrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish# {
269 salted_passwordrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#salted_password.,
270 auth_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/State#Finish#auth_message.,
271 } => (salted_password, auth_message),
272 _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().("invalid SCRAM state")),
273 };
274
275 let message =
276 strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(message).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, e))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
277
278 let parsed = Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#::newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(message).server_final_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_final_message().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
279
280 let verifier = match parsed {
281 ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Error#(e) => {
282 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]other().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("SCRAM error: {e}")));
283 }
284 ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Verifier#(verifier) => verifier,
285 };
286
287 let verifier = match STANDARDrust-analyzer cargo base64 0.22.1 engine/general_purpose/STANDARD..decoderust-analyzer cargo base64 0.22.1 engine/Engine#decode().(verifier) {
288 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(verifier) => verifier,
289 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, e)),
290 };
291
292 let mut hmac = Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(&salted_password)
293 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("HMAC is able to accept all key sizes");
294 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(b"Server Key");
295 let server_key = hmac.finalizerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]finalize().().into_bytesrust-analyzer cargo digest 0.11.3 mac/impl#[`CtOutput<T>`]into_bytes().();
296
297 let mut hmac = Hmacrust-analyzer cargo hmac 0.13.0 Hmac#::<Sha256rust-analyzer cargo sha2 0.11.0 Sha256#>::new_from_slicerust-analyzer cargo hmac 0.13.0 impl#[`Hmac<D>`][KeyInit]new_from_slice().(&server_key)
298 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("HMAC is able to accept all key sizes");
299 hmac.updaterust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]update().(auth_message.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().());
300 hmac.verify_slicerust-analyzer cargo digest 0.11.3 mac/impl#[T][Mac]verify_slice().(&verifier)
301 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, "SCRAM verification error"))
302 }
303 }
304
305 struct Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#<'a> {
306 srust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#s.: &'a str,
307 itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it.: iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::CharIndicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/CharIndices#<'a>>,
308 }
309
310 impl<'a> Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#<'a> {
311 fn newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(s: &'a str) -> Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#<'a> {
312 Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser# {
313 srust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#s.,
314 itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it.: s.char_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]char_indices().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(),
315 }
316 }
317
318 fn eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().(&mut self, target: char) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
319 match self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
320 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, c)) if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().target => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
321 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((i, c)) => {
322 let m =
323 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unexpected character at byte {i}: expected `{target}` but got `{c}");
324 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, m))
325 }
326 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
327 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#,
328 "unexpected EOF",
329 )),
330 }
331 }
332
333 fn take_whilerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]take_while().<F>(&mut self, f: F) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str>
334 where
335 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(char) -> bool,
336 {
337 let start = match self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
338 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(i, _)) => i,
339 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(""),
340 };
341
342 loop {
343 match self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
344 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(_, c)) if f(c) => {
345 self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
346 }
347 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(i, _)) => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.srust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#s.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
348 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&self.srust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#s.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().),
349 }
350 }
351 }
352
353 fn printablerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]printable().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
354 self.take_whilerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]take_while().(|c| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, '\x21'..='\x2b' | '\x2d'..='\x7e'))
355 }
356
357 fn noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]nonce().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
358 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('r')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
359 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
360 self.printablerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]printable().()
361 }
362
363 fn base64rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]base64().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
364 self.take_whilerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]take_while().(|c| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '/' | '+' | '='))
365 }
366
367 fn saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]salt().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
368 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('s')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
369 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
370 self.base64rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]base64().()
371 }
372
373 fn posit_numberrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]posit_number().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u32> {
374 let n = self.take_whilerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]take_while().(|c| c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
375 n.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
376 .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, e))
377 }
378
379 fn iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]iteration_count().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u32> {
380 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('i')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
381 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
382 self.posit_numberrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]posit_number().()
383 }
384
385 fn eofrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eof().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
386 match self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
387 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(i, _)) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
388 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#,
389 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unexpected trailing data at byte {i}"),
390 )),
391 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
392 }
393 }
394
395 fn server_first_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_first_message().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ServerFirstMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#<'a>> {
396 let nonce = self.noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]nonce().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
397 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().(',')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
398 let salt = self.saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]salt().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
399 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().(',')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
400 let iteration_count = self.iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]iteration_count().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
401 self.eofrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eof().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
402
403 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ServerFirstMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage# {
404 noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#nonce.,
405 saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#salt.,
406 iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#iteration_count.,
407 })
408 }
409
410 fn valuerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]value().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
411 self.take_whilerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]take_while().(|c| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(c, '\0' | '=' | ','))
412 }
413
414 fn server_errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_error().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>> {
415 match self.itrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#it..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
416 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&(_, 'e')) => {}
417 _ => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
418 }
419
420 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('e')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
421 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
422 self.valuerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]value().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#)
423 }
424
425 fn verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]verifier().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<&'a str> {
426 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('v')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
427 self.eatrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eat().('=')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
428 self.base64rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]base64().()
429 }
430
431 fn server_final_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_final_message().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#<'a>> {
432 let message = match self.server_errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_error().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
433 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(error) => ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Error#(error),
434 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Verifier#(self.verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]verifier().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().),
435 };
436 self.eofrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]eof().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
437 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(message)
438 }
439 }
440
441 struct ServerFirstMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#<'a> {
442 noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#nonce.: &'a str,
443 saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#salt.: &'a str,
444 iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#iteration_count.: u32,
445 }
446
447 enum ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#<'a> {
448 Errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Error#(&'a str),
449 Verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Verifier#(&'a str),
450 }
451
452 #[cfg(test)]
453 mod testrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/test/ {
454 use superrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/::*;
455
456 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
457 fn parse_server_first_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/test/parse_server_first_message().() {
458 let message = "r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096";
459 let message = Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#::newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(message).server_first_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_first_message().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
460 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(message.noncerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#nonce., "fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j");
461 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(message.saltrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#salt., "QSXCR+Q6sek8bf92");
462 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(message.iteration_countrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFirstMessage#iteration_count., 4096);
463 }
464
465 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
466 fn parse_server_error_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/test/parse_server_error_message().() {
467 let message = "e=invalid-proof";
468 match Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#::newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(message).server_final_messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]server_final_message().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() {
469 ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Errorrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Error#(error) => assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(error, "invalid-proof"),
470 ServerFinalMessagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#::Verifierrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ServerFinalMessage#Verifier#(_) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("expected server error"),
471 }
472
473 // the error value ends at the first '\0', '=' or ','
474 for message in ["invalid-proof\0x", "invalid-proof=x", "invalid-proof,x"] {
475 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Parserrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/Parser#::newrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]new().(message).valuerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[`Parser<'a>`]value().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "invalid-proof");
476 }
477 }
478
479 // recorded auth exchange from psql
480 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
481 fn exchangerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/test/exchange().() {
482 let password = "foobar";
483 let nonce = "9IZ2O01zb9IgiIZ1WJ/zgpJB";
484
485 let client_first = "n,,n=,r=9IZ2O01zb9IgiIZ1WJ/zgpJB";
486 let server_first = "r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,s=fs3IXBy7U7+IvVjZ,i\
487 =4096";
488 let client_final = "c=biws,r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,p=AmNKosjJzS3\
489 1NTlQYNs5BTeQjdHdk7lOflDo5re2an8=";
490 let server_final = "v=U+ppxD5XUKtradnv8e2MkeupiA8FU87Sg8CXzXHDAzw=";
491
492 let mut scram = ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#::new_innerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]new_inner().(
493 password.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(),
494 ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#::unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]unsupported().(),
495 nonce.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
496 );
497 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(scram.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]message().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), client_first);
498
499 scram.updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]update().(server_first.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
500 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(scram.messagerust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]message().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), client_final);
501
502 scram.finishrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]finish().(server_final.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
503 }
504
505 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
506 fn excessive_iteration_count_is_rejectedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/test/excessive_iteration_count_is_rejected().() {
507 // a malicious server cannot force an unbounded PBKDF2 loop; the iteration
508 // count is rejected before `hi()` runs.
509 let nonce = "9IZ2O01zb9IgiIZ1WJ/zgpJB";
510 let server_first =
511 "r=9IZ2O01zb9IgiIZ1WJ/zgpJBjx/oIRLs02gGSHcw1KEty3eY,s=fs3IXBy7U7+IvVjZ,i=1000000";
512
513 let mut scram =
514 ScramSha256rust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ScramSha256#::new_innerrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]new_inner().(b"foobar", ChannelBindingrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/ChannelBinding#::unsupportedrust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ChannelBinding]unsupported().(), nonce.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
515 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(scram.updaterust-analyzer cargo postgres-protocol 0.6.12 authentication/sasl/impl#[ScramSha256]update().(server_first.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
516 }
517 }