Debian Codegraph @

src/protocol/context/mod.rs

raw symbols SCIP
1 use bstrrust-analyzer cargo bstr 1.12.1 crate/::BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#;
2
3 /// Indicates key or values contain errors that can't be encoded.
4 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, thiserrorrust-analyzer cargo thiserror 2.0.18 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.18 Error:)]
5 #[allow(missing_docs)]
6 pub enum Errorrust-analyzer cargo gix-credentials 0.38.0 protocol/context/Error# {
7 #[errorrust-analyzer cargo thiserror-impl 2.0.18 error:("{key:?}={value:?} must not contain null bytes or newlines neither in key nor in value.")]
8 Encodingrust-analyzer cargo gix-credentials 0.38.0 protocol/context/Error#Encoding# { keyrust-analyzer cargo gix-credentials 0.38.0 protocol/context/Error#Encoding#key.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, valuerust-analyzer cargo gix-credentials 0.38.0 protocol/context/Error#Encoding#value.: BStringrust-analyzer cargo bstr 1.12.1 bstring/BString# },
9 }
10
11 mod accessrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/ {
12 use bstrrust-analyzer cargo bstr 1.12.1 crate/::BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#;
13
14 use craterust-analyzer cargo gix-credentials 0.38.0 crate/::protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/::Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#;
15
16 impl Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context# {
17 /// Clear all fields that are considered secret.
18 pub fn clear_secretsrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]clear_secrets().(&mut self) {
19 let Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context# {
20 protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#protocol.: _,
21 hostrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#host.: _,
22 pathrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#path.: _,
23 usernamerust-analyzer cargo gix-credentials 0.38.0 protocol/Context#username.: _,
24 passwordrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#password.,
25 oauth_refresh_tokenrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#oauth_refresh_token.,
26 password_expiry_utcrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#password_expiry_utc.: _,
27 urlrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#url.: _,
28 quitrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#quit.: _,
29 } = self;
30
31 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().password = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
32 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().oauth_refresh_token = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
33 }
34 /// Replace existing secrets with the word `<redacted>`.
35 pub fn redactedrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]redacted().(mut self) -> Selfrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context] {
36 let Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context# {
37 protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#protocol.: _,
38 hostrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#host.: _,
39 pathrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#path.: _,
40 usernamerust-analyzer cargo gix-credentials 0.38.0 protocol/Context#username.: _,
41 passwordrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#password.,
42 oauth_refresh_tokenrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#oauth_refresh_token.,
43 password_expiry_utcrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#password_expiry_utc.: _,
44 urlrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#url.: _,
45 quitrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#quit.: _,
46 } = &mut self;
47 for secret in [password, oauth_refresh_token].into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
48 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().secret = "<redacted>".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
49 }
50 self
51 }
52
53 /// Convert all relevant fields into a URL for consumption.
54 pub fn to_urlrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]to_url().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BStringrust-analyzer cargo bstr 1.12.1 bstring/BString#> {
55 use bstrrust-analyzer cargo bstr 1.12.1 crate/::{ByteSlicerust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#, ByteVecrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#};
56 let mut buf: BStringrust-analyzer cargo bstr 1.12.1 bstring/BString# = self.protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#protocol..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
57 buf.push_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#push_str().(b"://");
58 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(user) = &self.usernamerust-analyzer cargo gix-credentials 0.38.0 protocol/Context#username. {
59 buf.push_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#push_str().(user);
60 buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b'@');
61 }
62 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(host) = &self.hostrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#host. {
63 buf.push_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#push_str().(host);
64 }
65 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path) = &self.pathrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#path. {
66 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.starts_with_strrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#starts_with_str().("/") {
67 buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b'/');
68 }
69 buf.push_strrust-analyzer cargo bstr 1.12.1 ext_vec/ByteVec#push_str().(path);
70 }
71 buf.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
72 }
73 /// Compute a prompt to obtain the given value.
74 pub fn to_promptrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]to_prompt().(&self, field: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
75 match self.to_urlrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]to_url().() {
76 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(url) => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{field} for {url}: "),
77 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{field}: "),
78 }
79 }
80 }
81 }
82
83 mod mutaterust-analyzer cargo gix-credentials 0.38.0 protocol/context/mutate/ {
84 use bstrrust-analyzer cargo bstr 1.12.1 crate/::ByteSlicerust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#;
85
86 use craterust-analyzer cargo gix-credentials 0.38.0 crate/::{protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/, protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/::Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#};
87
88 /// In-place mutation
89 impl Contextrust-analyzer cargo gix-credentials 0.38.0 protocol/Context# {
90 /// Destructure the url at our `url` field into parts like protocol, host, username and path and store
91 /// them in our respective fields. If `use_http_path` is set, http paths are significant even though
92 /// normally this isn't the case.
93 #[allow(clippy::result_large_err)]
94 pub fn destructure_url_in_placerust-analyzer cargo gix-credentials 0.38.0 protocol/context/mutate/impl#[Context]destructure_url_in_place().(&mut self, use_http_path: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut Selfrust-analyzer cargo gix-credentials 0.38.0 protocol/context/mutate/impl#[Context], protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/::Errorrust-analyzer cargo gix-credentials 0.38.0 protocol/Error#> {
95 if self.urlrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#url..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
96 self.urlrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#url. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.to_urlrust-analyzer cargo gix-credentials 0.38.0 protocol/context/access/impl#[Context]to_url().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/::Errorrust-analyzer cargo gix-credentials 0.38.0 protocol/Error#::UrlMissingrust-analyzer cargo gix-credentials 0.38.0 protocol/Error#UrlMissing#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
97 }
98
99 let url = gix_urlrust-analyzer cargo gix-url 0.36.0 crate/::parserust-analyzer cargo gix-url 0.36.0 parse().(self.urlrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#url..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("URL is present after check above").as_refrust-analyzer cargo bstr 1.12.1 impls/bstring/impl#[BString][`AsRef<BStr>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
100 self.protocolrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#protocol. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(url.schemerust-analyzer cargo gix-url 0.36.0 Url#scheme..as_strrust-analyzer cargo gix-url 0.36.0 scheme/impl#[Scheme]as_str().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
101 self.usernamerust-analyzer cargo gix-credentials 0.38.0 protocol/Context#username. = url.userrust-analyzer cargo gix-url 0.36.0 impl#[Url]user().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#::to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().);
102 self.passwordrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#password. = url.passwordrust-analyzer cargo gix-url 0.36.0 impl#[Url]password().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#::to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().);
103 self.hostrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#host. = url.hostrust-analyzer cargo gix-url 0.36.0 impl#[Url]host().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#::to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|mut host| {
104 let port = url.portrust-analyzer cargo gix-url 0.36.0 Url#port..filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|port| {
105 url.schemerust-analyzer cargo gix-url 0.36.0 Url#scheme.
106 .default_portrust-analyzer cargo gix-url 0.36.0 scheme/impl#[Scheme]default_port().()
107 .is_none_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none_or().(|default_port| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().port rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().default_port)
108 });
109 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(port) = port {
110 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
111 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(host, ":{port}").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("infallible");
112 }
113 host
114 });
115 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(url.schemerust-analyzer cargo gix-url 0.36.0 Url#scheme., gix_urlrust-analyzer cargo gix-url 0.36.0 crate/::Schemerust-analyzer cargo gix-url 0.36.0 scheme/Scheme#::Httprust-analyzer cargo gix-url 0.36.0 scheme/Scheme#Http# | gix_urlrust-analyzer cargo gix-url 0.36.0 crate/::Schemerust-analyzer cargo gix-url 0.36.0 scheme/Scheme#::Httpsrust-analyzer cargo gix-url 0.36.0 scheme/Scheme#Https#) || use_http_path {
116 let path = url.pathrust-analyzer cargo gix-url 0.36.0 Url#path..trim_withrust-analyzer cargo bstr 1.12.1 ext_slice/ByteSlice#trim_with().(|b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'/');
117 self.pathrust-analyzer cargo gix-credentials 0.38.0 protocol/Context#path. = (!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()).thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
118 }
119 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self)
120 }
121 }
122 }
123
124 mod serderust-analyzer cargo gix-credentials 0.38.0 protocol/context/serde/;
125 pub use selfrust-analyzer cargo gix-credentials 0.38.0 protocol/context/::serderust-analyzer cargo gix-credentials 0.38.0 protocol/context/serde/::decoderust-analyzer cargo gix-credentials 0.38.0 protocol/context/serde/decode/;