1
1
use ssh_encoding:: { CheckedSum , Decode , Encode , Error as EncodingError , Reader , Writer } ;
2
- use ssh_key:: { private:: KeypairData , public:: KeyData , Error , Result , Signature } ;
2
+ use ssh_key:: { private:: KeypairData , public:: KeyData , Error , Signature } ;
3
+
4
+ use super :: ProtoError ;
5
+
6
+ type Result < T > = core:: result:: Result < T , ProtoError > ;
3
7
4
8
#[ derive( Clone , PartialEq , Debug ) ]
5
9
pub struct Identity {
@@ -21,7 +25,7 @@ impl Identity {
21
25
}
22
26
23
27
impl Decode for Identity {
24
- type Error = Error ;
28
+ type Error = ProtoError ;
25
29
26
30
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
27
31
let pubkey = reader. read_prefixed ( KeyData :: decode) ?;
@@ -56,7 +60,7 @@ pub struct SignRequest {
56
60
}
57
61
58
62
impl Decode for SignRequest {
59
- type Error = Error ;
63
+ type Error = ProtoError ;
60
64
61
65
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
62
66
let pubkey = reader. read_prefixed ( KeyData :: decode) ?;
@@ -97,7 +101,7 @@ pub struct AddIdentity {
97
101
}
98
102
99
103
impl Decode for AddIdentity {
100
- type Error = Error ;
104
+ type Error = ProtoError ;
101
105
102
106
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
103
107
let privkey = KeypairData :: decode ( reader) ?;
@@ -126,7 +130,7 @@ pub struct AddIdentityConstrained {
126
130
}
127
131
128
132
impl Decode for AddIdentityConstrained {
129
- type Error = Error ;
133
+ type Error = ProtoError ;
130
134
131
135
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
132
136
let identity = AddIdentity :: decode ( reader) ?;
@@ -168,7 +172,7 @@ pub struct RemoveIdentity {
168
172
}
169
173
170
174
impl Decode for RemoveIdentity {
171
- type Error = Error ;
175
+ type Error = ProtoError ;
172
176
173
177
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
174
178
let pubkey = reader. read_prefixed ( KeyData :: decode) ?;
@@ -194,7 +198,7 @@ pub struct SmartcardKey {
194
198
}
195
199
196
200
impl Decode for SmartcardKey {
197
- type Error = Error ;
201
+ type Error = ProtoError ;
198
202
199
203
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
200
204
let id = String :: decode ( reader) ?;
@@ -225,7 +229,7 @@ pub enum KeyConstraint {
225
229
}
226
230
227
231
impl Decode for KeyConstraint {
228
- type Error = Error ;
232
+ type Error = ProtoError ;
229
233
230
234
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
231
235
let constraint_type = u8:: decode ( reader) ?;
@@ -239,7 +243,7 @@ impl Decode for KeyConstraint {
239
243
reader. read ( & mut details) ?;
240
244
KeyConstraint :: Extension ( name, details. into ( ) )
241
245
}
242
- _ => return Err ( Error :: AlgorithmUnknown ) , // FIXME: it should be our own type
246
+ _ => return Err ( Error :: AlgorithmUnknown ) ? , // FIXME: it should be our own type
243
247
} )
244
248
}
245
249
}
@@ -282,7 +286,7 @@ pub struct AddSmartcardKeyConstrained {
282
286
}
283
287
284
288
impl Decode for AddSmartcardKeyConstrained {
285
- type Error = Error ;
289
+ type Error = ProtoError ;
286
290
287
291
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
288
292
let key = SmartcardKey :: decode ( reader) ?;
@@ -321,7 +325,7 @@ pub struct Extension {
321
325
}
322
326
323
327
impl Decode for Extension {
324
- type Error = Error ;
328
+ type Error = ProtoError ;
325
329
326
330
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
327
331
let name = String :: decode ( reader) ?;
@@ -425,7 +429,7 @@ impl Message {
425
429
}
426
430
427
431
impl Decode for Message {
428
- type Error = Error ;
432
+ type Error = ProtoError ;
429
433
430
434
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
431
435
let message_type = u8:: decode ( reader) ?;
@@ -436,7 +440,10 @@ impl Decode for Message {
436
440
11 => Ok ( Self :: RequestIdentities ) ,
437
441
12 => Identity :: decode_vec ( reader) . map ( Self :: IdentitiesAnswer ) ,
438
442
13 => SignRequest :: decode ( reader) . map ( Self :: SignRequest ) ,
439
- 14 => reader. read_prefixed ( |reader| Signature :: decode ( reader) . map ( Self :: SignResponse ) ) ,
443
+ 14 => {
444
+ Ok ( reader
445
+ . read_prefixed ( |reader| Signature :: decode ( reader) . map ( Self :: SignResponse ) ) ?)
446
+ }
440
447
17 => AddIdentity :: decode ( reader) . map ( Self :: AddIdentity ) ,
441
448
18 => RemoveIdentity :: decode ( reader) . map ( Self :: RemoveIdentity ) ,
442
449
19 => Ok ( Self :: RemoveAllIdentities ) ,
@@ -448,7 +455,7 @@ impl Decode for Message {
448
455
26 => AddSmartcardKeyConstrained :: decode ( reader) . map ( Self :: AddSmartcardKeyConstrained ) ,
449
456
27 => Extension :: decode ( reader) . map ( Self :: Extension ) ,
450
457
28 => Ok ( Self :: ExtensionFailure ) ,
451
- _ => todo ! ( ) ,
458
+ command => Err ( ProtoError :: UnsupportedCommand { command } ) ,
452
459
}
453
460
}
454
461
}
0 commit comments