Skip to content

Commit cc704ba

Browse files
committed
Remove PairTargetUrl.
1 parent 660a87e commit cc704ba

File tree

3 files changed

+2
-93
lines changed

3 files changed

+2
-93
lines changed

crates/net/src/pairing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod websocket;
66

77
pub use enrollment::DeviceEnrollment;
88
pub use error::Error;
9-
pub use share_url::{PairTargetUrl, ServerPairUrl};
9+
pub use share_url::ServerPairUrl;
1010
pub use websocket::{AcceptPairing, OfferPairing};
1111

1212
/// Result type for the pairing module.

crates/net/src/pairing/share_url.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,6 @@ use sos_core::{csprng, AccountId};
55
use std::str::FromStr;
66
use url::Url;
77

8-
/// Pair target URL encapsulates a server and account ID.
9-
///
10-
/// It is used to transfer a server and account identifier
11-
/// from a mobile device to a desktop for the inverted pairing flow.
12-
///
13-
/// The URL format is `<server-url>?aid=<account-id>`.
14-
#[derive(Debug, PartialEq, Eq)]
15-
pub struct PairTargetUrl {
16-
/// Server used to transfer the account data.
17-
server: Url,
18-
/// Account identifier.
19-
account_id: AccountId,
20-
}
21-
22-
impl PairTargetUrl {
23-
/// Create a new pair target URL.
24-
pub fn new(server: Url, account_id: AccountId) -> Self {
25-
Self { server, account_id }
26-
}
27-
28-
/// Server URL.
29-
pub fn server(&self) -> &Url {
30-
&self.server
31-
}
32-
33-
/// Account identifier.
34-
pub fn account_id(&self) -> &AccountId {
35-
&self.account_id
36-
}
37-
}
38-
39-
impl From<PairTargetUrl> for Url {
40-
fn from(value: PairTargetUrl) -> Self {
41-
let mut url = value.server;
42-
url.query_pairs_mut()
43-
.append_pair(AID, &value.account_id.to_string());
44-
url
45-
}
46-
}
47-
48-
impl TryFrom<Url> for PairTargetUrl {
49-
type Error = Error;
50-
51-
fn try_from(mut url: Url) -> Result<Self> {
52-
let mut pairs = url.query_pairs();
53-
54-
let account_id = pairs.find_map(|q| {
55-
if q.0.as_ref() == AID {
56-
Some(q.1)
57-
} else {
58-
None
59-
}
60-
});
61-
let account_id = account_id.ok_or(Error::InvalidShareUrl)?;
62-
let account_id: AccountId = account_id.as_ref().parse()?;
63-
64-
url.set_query(None);
65-
url.set_path("");
66-
67-
Ok(PairTargetUrl {
68-
server: url,
69-
account_id,
70-
})
71-
}
72-
}
73-
748
/// Account identifier.
759
const AID: &str = "aid";
7610
/// Server URL.

tests/unit/src/tests/pairing_url.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
use anyhow::Result;
22
use sos_core::AccountId;
3-
use sos_net::pairing::{PairTargetUrl, ServerPairUrl};
3+
use sos_net::pairing::ServerPairUrl;
44
use url::Url;
55

66
const SERVER: &str = "http://192.168.1.8:5053";
77

8-
#[test]
9-
fn pair_target_url() -> Result<()> {
10-
let mock_server: Url = SERVER.parse()?;
11-
let mock_account_id = AccountId::random();
12-
let mock_url =
13-
Url::parse(&format!("{}/?aid={}", mock_server, mock_account_id))?;
14-
let pairing_target =
15-
PairTargetUrl::new(mock_server.clone(), mock_account_id.clone());
16-
17-
assert_eq!(&mock_server, pairing_target.server());
18-
assert_eq!(&mock_account_id, pairing_target.account_id());
19-
20-
let parsed_target: PairTargetUrl = mock_url.try_into()?;
21-
assert_eq!(pairing_target, parsed_target);
22-
23-
Ok(())
24-
}
25-
26-
#[test]
27-
fn pair_target_url_errors() -> Result<()> {
28-
// No account identifier in query string
29-
assert!(PairTargetUrl::try_from(Url::parse(SERVER).unwrap()).is_err());
30-
Ok(())
31-
}
32-
338
#[test]
349
fn pair_server_url() -> Result<()> {
3510
let mock_account_id = AccountId::random();

0 commit comments

Comments
 (0)