]> git.proxmox.com Git - rustc.git/blob - vendor/gix/src/config/tree/sections/ssh.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / gix / src / config / tree / sections / ssh.rs
1 use crate::{
2 config,
3 config::tree::{keys, Key, Section, Ssh},
4 };
5
6 impl Ssh {
7 /// The `ssh.variant` key
8 pub const VARIANT: Variant = Variant::new_with_validate("variant", &config::Tree::SSH, validate::Variant)
9 .with_environment_override("GIT_SSH_VARIANT")
10 .with_deviation("We error if a variant is chosen that we don't know, as opposed to defaulting to 'ssh'");
11 }
12
13 /// The `ssh.variant` key.
14 pub type Variant = keys::Any<validate::Variant>;
15
16 #[cfg(feature = "blocking-network-client")]
17 mod variant {
18 use std::borrow::Cow;
19
20 use crate::{bstr::BStr, config, config::tree::ssh::Variant};
21
22 impl Variant {
23 pub fn try_into_variant(
24 &'static self,
25 value: Cow<'_, BStr>,
26 ) -> Result<Option<gix_protocol::transport::client::ssh::ProgramKind>, config::key::GenericErrorWithValue>
27 {
28 use gix_protocol::transport::client::ssh::ProgramKind;
29
30 use crate::bstr::ByteSlice;
31 Ok(Some(match value.as_ref().as_bytes() {
32 b"auto" => return Ok(None),
33 b"ssh" => ProgramKind::Ssh,
34 b"plink" => ProgramKind::Plink,
35 b"putty" => ProgramKind::Putty,
36 b"tortoiseplink" => ProgramKind::TortoisePlink,
37 b"simple" => ProgramKind::Simple,
38 _ => return Err(config::key::GenericErrorWithValue::from_value(self, value.into_owned())),
39 }))
40 }
41 }
42 }
43
44 impl Section for Ssh {
45 fn name(&self) -> &str {
46 "ssh"
47 }
48
49 fn keys(&self) -> &[&dyn Key] {
50 &[&Self::VARIANT]
51 }
52 }
53
54 mod validate {
55 use crate::{bstr::BStr, config::tree::keys};
56
57 pub struct Variant;
58 impl keys::Validate for Variant {
59 fn validate(&self, _value: &BStr) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
60 #[cfg(feature = "blocking-network-client")]
61 super::Ssh::VARIANT.try_into_variant(_value.into())?;
62 Ok(())
63 }
64 }
65 }