1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use std::net::SocketAddr;
use tor_llcrypto::pk;
use crate::{ChanTarget, CircTarget};
#[derive(Debug, Clone)]
pub struct OwnedChanTarget {
addrs: Vec<SocketAddr>,
ed_identity: pk::ed25519::Ed25519Identity,
rsa_identity: pk::rsa::RsaIdentity,
}
impl ChanTarget for OwnedChanTarget {
fn addrs(&self) -> &[SocketAddr] {
&self.addrs[..]
}
fn ed_identity(&self) -> &pk::ed25519::Ed25519Identity {
&self.ed_identity
}
fn rsa_identity(&self) -> &pk::rsa::RsaIdentity {
&self.rsa_identity
}
}
impl OwnedChanTarget {
pub fn new(
addrs: Vec<SocketAddr>,
ed_identity: pk::ed25519::Ed25519Identity,
rsa_identity: pk::rsa::RsaIdentity,
) -> Self {
Self {
addrs,
ed_identity,
rsa_identity,
}
}
pub fn from_chan_target<C>(target: &C) -> Self
where
C: ChanTarget + ?Sized,
{
OwnedChanTarget {
addrs: target.addrs().to_vec(),
ed_identity: *target.ed_identity(),
rsa_identity: *target.rsa_identity(),
}
}
}
#[derive(Debug, Clone)]
pub struct OwnedCircTarget {
chan_target: OwnedChanTarget,
ntor_onion_key: pk::curve25519::PublicKey,
protovers: tor_protover::Protocols,
}
impl OwnedCircTarget {
pub fn new(
chan_target: OwnedChanTarget,
ntor_onion_key: pk::curve25519::PublicKey,
protovers: tor_protover::Protocols,
) -> OwnedCircTarget {
OwnedCircTarget {
chan_target,
ntor_onion_key,
protovers,
}
}
pub fn from_circ_target<C>(target: &C) -> Self
where
C: CircTarget + ?Sized,
{
OwnedCircTarget {
chan_target: OwnedChanTarget::from_chan_target(target),
ntor_onion_key: *target.ntor_onion_key(),
protovers: target.protovers().clone(),
}
}
}
impl ChanTarget for OwnedCircTarget {
fn addrs(&self) -> &[SocketAddr] {
self.chan_target.addrs()
}
fn ed_identity(&self) -> &pk::ed25519::Ed25519Identity {
self.chan_target.ed_identity()
}
fn rsa_identity(&self) -> &pk::rsa::RsaIdentity {
self.chan_target.rsa_identity()
}
}
impl CircTarget for OwnedCircTarget {
fn ntor_onion_key(&self) -> &pk::curve25519::PublicKey {
&self.ntor_onion_key
}
fn protovers(&self) -> &tor_protover::Protocols {
&self.protovers
}
}
#[cfg(test)]
mod test {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]
fn targetinfo() {
let ti = OwnedChanTarget::new(
vec!["127.0.0.1:11".parse().unwrap()],
[42; 32].into(),
[45; 20].into(),
);
let ti2 = OwnedChanTarget::from_chan_target(&ti);
assert_eq!(ti.addrs(), ti2.addrs());
assert_eq!(ti.ed_identity(), ti2.ed_identity());
assert_eq!(ti.rsa_identity(), ti2.rsa_identity());
}
}