Skip to content

Commit aa63dda

Browse files
committed
parse identity list
Signed-off-by: Arthur Gautier <[email protected]>
1 parent d820eb6 commit aa63dda

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/proto/message.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ pub struct Identity {
77
pub comment: String,
88
}
99

10+
impl Identity {
11+
fn decode_vec(reader: &mut impl Reader) -> Result<Vec<Self>> {
12+
let len = u32::decode(reader)?;
13+
let mut identities = vec![];
14+
15+
for _ in 0..len {
16+
identities.push(Self::decode(reader)?);
17+
}
18+
19+
Ok(identities)
20+
}
21+
}
22+
1023
impl Decode for Identity {
1124
type Error = Error;
1225

@@ -264,7 +277,7 @@ impl Decode for Message {
264277
5 => Ok(Self::Failure),
265278
6 => Ok(Self::Success),
266279
11 => Ok(Self::RequestIdentities),
267-
12 => todo!(),
280+
12 => Identity::decode_vec(reader).map(Self::IdentitiesAnswer),
268281
13 => SignRequest::decode(reader).map(Self::SignRequest),
269282
14 => Signature::decode(reader).map(Self::SignResponse),
270283
17 => AddIdentity::decode(reader).map(Self::AddIdentity),
@@ -549,4 +562,31 @@ mod tests {
549562
}
550563
);
551564
}
565+
566+
#[test]
567+
fn test_parse_identities() {
568+
let msg: &[u8] = &hex!(
569+
"
570+
0c000000010000006800000013656364
571+
73612d736861322d6e69737470323536
572+
000000086e6973747032353600000041
573+
04cb244fcdb89de95bc8fd766e6b139a
574+
bfc2649fb063b6c5e5a939e067e2a0d2
575+
150a660daca78f6c24a0425373d6ea83
576+
e36f8a1f8b828a60e77a97a9441bcc09
577+
870000000c62616c6f6f40616e67656c
578+
61"
579+
);
580+
let mut reader = msg;
581+
582+
let out = Message::decode(&mut reader).expect("parse message");
583+
584+
assert_eq!(
585+
out,
586+
Message::IdentitiesAnswer(vec![Identity {
587+
pubkey: KeyData::Ecdsa(demo_key().into()),
588+
comment: "baloo@angela".to_string()
589+
}]),
590+
);
591+
}
552592
}

0 commit comments

Comments
 (0)