Merge pull request #1130 from deltachat/fpr-without-addr

handle plain OPENPGP4FRP qr-codes correctly
This commit is contained in:
björn petersen
2020-01-01 21:49:37 +01:00
committed by GitHub

View File

@@ -69,7 +69,7 @@ fn decode_openpgp(context: &Context, qr: &str) -> Lot {
(fp, &rest[1..]) (fp, &rest[1..])
}) { }) {
Some(pair) => pair, Some(pair) => pair,
None => return format_err!("Invalid OPENPGP4FPR found").into(), None => (payload, ""),
}; };
// replace & with \n to match expected param format // replace & with \n to match expected param format
@@ -83,11 +83,11 @@ fn decode_openpgp(context: &Context, qr: &str) -> Lot {
let addr = if let Some(addr) = param.get(Param::Forwarded) { let addr = if let Some(addr) = param.get(Param::Forwarded) {
match normalize_address(addr) { match normalize_address(addr) {
Ok(addr) => addr, Ok(addr) => Some(addr),
Err(err) => return err.into(), Err(err) => return err.into(),
} }
} else { } else {
return format_err!("Missing address").into(); None
}; };
// what is up with that param name? // what is up with that param name?
@@ -157,7 +157,7 @@ fn decode_openpgp(context: &Context, qr: &str) -> Lot {
lot.state = LotState::QrFprWithoutAddr; lot.state = LotState::QrFprWithoutAddr;
lot.text1 = Some(dc_format_fingerprint(&fingerprint)); lot.text1 = Some(dc_format_fingerprint(&fingerprint));
} }
} else { } else if let Some(addr) = addr {
if grpid.is_some() && grpname.is_some() { if grpid.is_some() && grpname.is_some() {
lot.state = LotState::QrAskVerifyGroup; lot.state = LotState::QrAskVerifyGroup;
lot.text1 = grpname; lot.text1 = grpname;
@@ -172,6 +172,8 @@ fn decode_openpgp(context: &Context, qr: &str) -> Lot {
lot.fingerprint = Some(fingerprint); lot.fingerprint = Some(fingerprint);
lot.invitenumber = invitenumber; lot.invitenumber = invitenumber;
lot.auth = auth; lot.auth = auth;
} else {
return format_err!("Missing address").into();
} }
lot lot
@@ -471,4 +473,24 @@ mod tests {
assert_eq!(contact.get_addr(), "cli@deltachat.de"); assert_eq!(contact.get_addr(), "cli@deltachat.de");
assert_eq!(contact.get_name(), "Jörn P. P."); assert_eq!(contact.get_name(), "Jörn P. P.");
} }
#[test]
fn test_decode_openpgp_without_addr() {
let ctx = dummy_context();
let res = check_qr(
&ctx.ctx,
"OPENPGP4FPR:1234567890123456789012345678901234567890",
);
assert_eq!(res.get_state(), LotState::QrFprWithoutAddr);
assert_eq!(
res.get_text1().unwrap(),
"1234 5678 9012 3456 7890\n1234 5678 9012 3456 7890"
);
assert_eq!(res.get_id(), 0);
let res = check_qr(&ctx.ctx, "OPENPGP4FPR:12345678901234567890");
assert_eq!(res.get_state(), LotState::QrError);
assert_eq!(res.get_id(), 0);
}
} }