fix leon & binstalk-downloader bug relating to features (#1153)

- ci: Check feat powerset of leon & binstalk-downloader in `ci.yml`
 - fix leon feature `cli`: Enable dep `miette` in feature `cli`
 - fix binstalk-downloader when default feature is disabled and no other
   tls related feature is enabled (breaking change due to replace of
   `tls::Version` with newtype `TLSVersion`).

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-06-19 12:22:09 +10:00 committed by GitHub
parent 5c4a542de5
commit 40efe02e34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 111 additions and 65 deletions

View file

@ -1,13 +1,19 @@
#[cfg(feature = "__tls")]
use reqwest::tls;
use super::Error;
#[derive(Clone, Debug)]
pub struct Certificate(pub(super) tls::Certificate);
pub struct Certificate(#[cfg(feature = "__tls")] pub(super) tls::Certificate);
#[cfg_attr(not(feature = "__tls"), allow(unused_variables))]
impl Certificate {
/// Create a Certificate from a binary DER encoded certificate
pub fn from_der(der: impl AsRef<[u8]>) -> Result<Self, Error> {
#[cfg(not(feature = "__tls"))]
return Ok(Self());
#[cfg(feature = "__tls")]
tls::Certificate::from_der(der.as_ref())
.map(Self)
.map_err(Error::from)
@ -15,6 +21,10 @@ impl Certificate {
/// Create a Certificate from a PEM encoded certificate
pub fn from_pem(pem: impl AsRef<[u8]>) -> Result<Self, Error> {
#[cfg(not(feature = "__tls"))]
return Ok(Self());
#[cfg(feature = "__tls")]
tls::Certificate::from_pem(pem.as_ref())
.map(Self)
.map_err(Error::from)

View file

@ -0,0 +1,37 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum Inner {
Tls1_2 = 0,
Tls1_3 = 1,
}
/// TLS version for [`crate::remote::Client`].
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct TLSVersion(Inner);
impl TLSVersion {
pub const TLS_1_2: TLSVersion = TLSVersion(Inner::Tls1_2);
pub const TLS_1_3: TLSVersion = TLSVersion(Inner::Tls1_3);
}
#[cfg(feature = "__tls")]
impl From<TLSVersion> for reqwest::tls::Version {
fn from(ver: TLSVersion) -> reqwest::tls::Version {
use reqwest::tls::Version;
use Inner::*;
match ver.0 {
Tls1_2 => Version::TLS_1_2,
Tls1_3 => Version::TLS_1_3,
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_tls_version_order() {
assert!(TLSVersion::TLS_1_2 < TLSVersion::TLS_1_3);
}
}