@@ -20,6 +20,10 @@ pub enum Message {
20
20
AuthenticationOk ,
21
21
AuthenticationScmCredential ,
22
22
AuthenticationSspi ,
23
+ AuthenticationGssContinue ( AuthenticationGssContinueBody ) ,
24
+ AuthenticationSasl ( AuthenticationSaslBody ) ,
25
+ AuthenticationSaslContinue ( AuthenticationSaslContinueBody ) ,
26
+ AuthenticationSaslFinal ( AuthenticationSaslFinalBody ) ,
23
27
BackendKeyData ( BackendKeyDataBody ) ,
24
28
BindComplete ,
25
29
CloseComplete ,
@@ -81,17 +85,15 @@ impl Message {
81
85
let channel = try!( buf. read_cstr ( ) ) ;
82
86
let message = try!( buf. read_cstr ( ) ) ;
83
87
Message :: NotificationResponse ( NotificationResponseBody {
84
- process_id : process_id,
85
- channel : channel,
86
- message : message,
87
- } )
88
+ process_id : process_id,
89
+ channel : channel,
90
+ message : message,
91
+ } )
88
92
}
89
93
b'c' => Message :: CopyDone ,
90
94
b'C' => {
91
95
let tag = try!( buf. read_cstr ( ) ) ;
92
- Message :: CommandComplete ( CommandCompleteBody {
93
- tag : tag,
94
- } )
96
+ Message :: CommandComplete ( CommandCompleteBody { tag : tag } )
95
97
}
96
98
b'd' => {
97
99
let storage = buf. read_all ( ) ;
@@ -101,9 +103,9 @@ impl Message {
101
103
let len = try!( buf. read_u16 :: < BigEndian > ( ) ) ;
102
104
let storage = buf. read_all ( ) ;
103
105
Message :: DataRow ( DataRowBody {
104
- storage : storage,
105
- len : len,
106
- } )
106
+ storage : storage,
107
+ len : len,
108
+ } )
107
109
}
108
110
b'E' => {
109
111
let storage = buf. read_all ( ) ;
@@ -114,36 +116,34 @@ impl Message {
114
116
let len = try!( buf. read_u16 :: < BigEndian > ( ) ) ;
115
117
let storage = buf. read_all ( ) ;
116
118
Message :: CopyInResponse ( CopyInResponseBody {
117
- format : format,
118
- len : len,
119
- storage : storage,
120
- } )
119
+ format : format,
120
+ len : len,
121
+ storage : storage,
122
+ } )
121
123
}
122
124
b'H' => {
123
125
let format = try!( buf. read_u8 ( ) ) ;
124
126
let len = try!( buf. read_u16 :: < BigEndian > ( ) ) ;
125
127
let storage = buf. read_all ( ) ;
126
128
Message :: CopyOutResponse ( CopyOutResponseBody {
127
- format : format,
128
- len : len,
129
- storage : storage,
130
- } )
129
+ format : format,
130
+ len : len,
131
+ storage : storage,
132
+ } )
131
133
}
132
134
b'I' => Message :: EmptyQueryResponse ,
133
135
b'K' => {
134
136
let process_id = try!( buf. read_i32 :: < BigEndian > ( ) ) ;
135
137
let secret_key = try!( buf. read_i32 :: < BigEndian > ( ) ) ;
136
138
Message :: BackendKeyData ( BackendKeyDataBody {
137
- process_id : process_id,
138
- secret_key : secret_key,
139
- } )
139
+ process_id : process_id,
140
+ secret_key : secret_key,
141
+ } )
140
142
}
141
143
b'n' => Message :: NoData ,
142
144
b'N' => {
143
145
let storage = buf. read_all ( ) ;
144
- Message :: NoticeResponse ( NoticeResponseBody {
145
- storage : storage,
146
- } )
146
+ Message :: NoticeResponse ( NoticeResponseBody { storage : storage } )
147
147
}
148
148
b'R' => {
149
149
match try!( buf. read_i32 :: < BigEndian > ( ) ) {
@@ -154,12 +154,28 @@ impl Message {
154
154
let mut salt = [ 0 ; 4 ] ;
155
155
try!( buf. read_exact ( & mut salt) ) ;
156
156
Message :: AuthenticationMd5Password ( AuthenticationMd5PasswordBody {
157
- salt : salt,
158
- } )
157
+ salt : salt,
158
+ } )
159
159
}
160
160
6 => Message :: AuthenticationScmCredential ,
161
161
7 => Message :: AuthenticationGss ,
162
+ 8 => {
163
+ let storage = buf. read_all ( ) ;
164
+ Message :: AuthenticationGssContinue ( AuthenticationGssContinueBody ( storage) )
165
+ }
162
166
9 => Message :: AuthenticationSspi ,
167
+ 10 => {
168
+ let storage = buf. read_all ( ) ;
169
+ Message :: AuthenticationSasl ( AuthenticationSaslBody ( storage) )
170
+ }
171
+ 11 => {
172
+ let storage = buf. read_all ( ) ;
173
+ Message :: AuthenticationSaslContinue ( AuthenticationSaslContinueBody ( storage) )
174
+ }
175
+ 12 => {
176
+ let storage = buf. read_all ( ) ;
177
+ Message :: AuthenticationSaslFinal ( AuthenticationSaslFinalBody ( storage) )
178
+ }
163
179
tag => {
164
180
return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
165
181
format ! ( "unknown authentication tag `{}`" , tag) ) ) ;
@@ -171,31 +187,29 @@ impl Message {
171
187
let name = try!( buf. read_cstr ( ) ) ;
172
188
let value = try!( buf. read_cstr ( ) ) ;
173
189
Message :: ParameterStatus ( ParameterStatusBody {
174
- name : name,
175
- value : value,
176
- } )
190
+ name : name,
191
+ value : value,
192
+ } )
177
193
}
178
194
b't' => {
179
195
let len = try!( buf. read_u16 :: < BigEndian > ( ) ) ;
180
196
let storage = buf. read_all ( ) ;
181
197
Message :: ParameterDescription ( ParameterDescriptionBody {
182
- storage : storage,
183
- len : len,
184
- } )
198
+ storage : storage,
199
+ len : len,
200
+ } )
185
201
}
186
202
b'T' => {
187
203
let len = try!( buf. read_u16 :: < BigEndian > ( ) ) ;
188
204
let storage = buf. read_all ( ) ;
189
205
Message :: RowDescription ( RowDescriptionBody {
190
- storage : storage,
191
- len : len,
192
- } )
206
+ storage : storage,
207
+ len : len,
208
+ } )
193
209
}
194
210
b'Z' => {
195
211
let status = try!( buf. read_u8 ( ) ) ;
196
- Message :: ReadyForQuery ( ReadyForQueryBody {
197
- status : status,
198
- } )
212
+ Message :: ReadyForQuery ( ReadyForQueryBody { status : status } )
199
213
}
200
214
tag => {
201
215
return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
@@ -269,6 +283,64 @@ impl AuthenticationMd5PasswordBody {
269
283
}
270
284
}
271
285
286
+ pub struct AuthenticationGssContinueBody ( Bytes ) ;
287
+
288
+ impl AuthenticationGssContinueBody {
289
+ #[ inline]
290
+ pub fn data ( & self ) -> & [ u8 ] {
291
+ & self . 0
292
+ }
293
+ }
294
+
295
+ pub struct AuthenticationSaslBody ( Bytes ) ;
296
+
297
+ impl AuthenticationSaslBody {
298
+ #[ inline]
299
+ pub fn mechanisms < ' a > ( & ' a self ) -> SaslMechanisms < ' a > {
300
+ SaslMechanisms ( & self . 0 )
301
+ }
302
+ }
303
+
304
+ pub struct SaslMechanisms < ' a > ( & ' a [ u8 ] ) ;
305
+
306
+ impl < ' a > FallibleIterator for SaslMechanisms < ' a > {
307
+ type Item = & ' a str ;
308
+ type Error = io:: Error ;
309
+
310
+ #[ inline]
311
+ fn next ( & mut self ) -> io:: Result < Option < & ' a str > > {
312
+ let value_end = try!( find_null ( self . 0 , 0 ) ) ;
313
+ if value_end == 0 {
314
+ if self . 0 . len ( ) != 1 {
315
+ return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidData , "invalid message length" ) ) ;
316
+ }
317
+ Ok ( None )
318
+ } else {
319
+ let value = try!( get_str ( & self . 0 [ ..value_end] ) ) ;
320
+ self . 0 = & self . 0 [ value_end + 1 ..] ;
321
+ Ok ( Some ( value) )
322
+ }
323
+ }
324
+ }
325
+
326
+ pub struct AuthenticationSaslContinueBody ( Bytes ) ;
327
+
328
+ impl AuthenticationSaslContinueBody {
329
+ #[ inline]
330
+ pub fn data ( & self ) -> & [ u8 ] {
331
+ & self . 0
332
+ }
333
+ }
334
+
335
+ pub struct AuthenticationSaslFinalBody ( Bytes ) ;
336
+
337
+ impl AuthenticationSaslFinalBody {
338
+ #[ inline]
339
+ pub fn data ( & self ) -> & [ u8 ] {
340
+ & self . 0
341
+ }
342
+ }
343
+
272
344
pub struct BackendKeyDataBody {
273
345
process_id : i32 ,
274
346
secret_key : i32 ,
0 commit comments