Handle more errors
This commit is contained in:
parent
4eb3204240
commit
2e94b4df34
16
src/lib.rs
16
src/lib.rs
|
@ -8,6 +8,7 @@ use lox_library::{
|
||||||
scalar_u32, IssuerPubKey, OPENINV_LENGTH,
|
scalar_u32, IssuerPubKey, OPENINV_LENGTH,
|
||||||
};
|
};
|
||||||
use lox_utils::{EncBridgeTable, Invite};
|
use lox_utils::{EncBridgeTable, Invite};
|
||||||
|
use serde::de::Error as SerdeError;
|
||||||
use serde_json::error::Error;
|
use serde_json::error::Error;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -115,7 +116,10 @@ pub async fn get_bucket(
|
||||||
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
||||||
let encbucket = match encbuckets.get(&id) {
|
let encbucket = match encbuckets.get(&id) {
|
||||||
Some(encbucket) => encbucket,
|
Some(encbucket) => encbucket,
|
||||||
None => panic!("Provided ID not found"),
|
None => {
|
||||||
|
// This is probably an abuse of the serde_json Error struct.
|
||||||
|
return Err(Error::missing_field("Provided ID not found"));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Ok(BridgeTable::decrypt_bucket(id, &key, &encbucket).unwrap())
|
Ok(BridgeTable::decrypt_bucket(id, &key, &encbucket).unwrap())
|
||||||
}
|
}
|
||||||
|
@ -210,7 +214,15 @@ pub async fn issue_invite(
|
||||||
|
|
||||||
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
let (id, key) = from_scalar(lox_cred.bucket).unwrap();
|
||||||
let bucket = BridgeTable::decrypt_bucket(id, &key, &encbuckets.get(&id).unwrap()).unwrap();
|
let bucket = BridgeTable::decrypt_bucket(id, &key, &encbuckets.get(&id).unwrap()).unwrap();
|
||||||
let reachcred = bucket.1.unwrap();
|
let reachcred = match bucket.1 {
|
||||||
|
Some(v) => v,
|
||||||
|
None => {
|
||||||
|
// This is probably an abuse of the serde_json Error struct.
|
||||||
|
return Err(Error::missing_field(
|
||||||
|
"Expected reachability credential but none was found",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let (req, state) = issue_invite::request(
|
let (req, state) = issue_invite::request(
|
||||||
lox_cred,
|
lox_cred,
|
||||||
|
|
Loading…
Reference in New Issue